Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Check Win Algorithm
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
erob95




PostPosted: Fri Jan 27, 2012 5:52 pm   Post subject: Check Win Algorithm

I am looking for an efficient way to check for a win in the game of sequence. I need to check for a row of five pieces in a ten by ten board. Rather than find the 100s of possibilities for rows I was hoping there was a way to search around the last played piece rather than search the entire board.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri Jan 27, 2012 6:30 pm   Post subject: RE:Check Win Algorithm

How would you do this on paper?
erob95




PostPosted: Fri Jan 27, 2012 6:35 pm   Post subject: Re: Check Win Algorithm

Do you mean in the game? Or pseudo code kind of thing?
Insectoid




PostPosted: Fri Jan 27, 2012 6:52 pm   Post subject: RE:Check Win Algorithm

Draw a grid on some paper, pick a spot, and find a logical way to decide if that spot is part of a winning row.
Velocity




PostPosted: Sat Jan 28, 2012 12:16 pm   Post subject: RE:Check Win Algorithm

are you making tetris if so, then i can help you out.
erob95




PostPosted: Sat Jan 28, 2012 12:29 pm   Post subject: Re: Check Win Algorithm

I am making the game of sequence.
crossley7




PostPosted: Sat Jan 28, 2012 11:55 pm   Post subject: RE:Check Win Algorithm

well, you have horizontal, vertical and the 2 diagonals. include the 1 you just placed and 4 more in each direction for the 4 possibilities. Then check these series of 9 for 5 in a row. Exactly what you wanted to do. I gave you about the most naive way of implementing. The other option would be to keep track of winning squares but that may be too inefficient to implement (not thinking about logic progression, just ways of finding if the piece is a winning play)

EDIT: Also, try wording your question better next time. It seems you are looking for an
code:

if (WIN)
 do this
else
 continue


type of thing where WIN is a built in command or maybe 1 step. You will need a function/procedure that will check for the win (or in the main code, but that gets to be hard to read)
Srlancelot39




PostPosted: Sun Jan 29, 2012 7:28 pm   Post subject: RE:Check Win Algorithm

I don't think erob95 was asking how to code what to do when you win, I think he was asking the most efficient way of determining if the player has won or not.
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Tue Feb 07, 2012 5:37 pm   Post subject: RE:Check Win Algorithm

if block 1 and 2 and 3 and ... are in between these parameters then block = false

meaning it is dead, look up the types and boolean tutorials to see efficient ways of manuveuring this
Raknarg




PostPosted: Tue Feb 07, 2012 6:48 pm   Post subject: RE:Check Win Algorithm

@Velocity are you suggesting he try to look at every possible combination of victories? If yes, then thats ok for tic tac toe, but at this scale, it would be incredibly ineffecient.

If no, then you should reword that.
tyuo9980




PostPosted: Wed Feb 08, 2012 7:02 pm   Post subject: Re: Check Win Algorithm

well after a player makes a move, you can check for a connect 5 sequence by starting from the piece that the player played and checking the 4 possible directions for a 5 in a row sequence. Have a counter for every time a piece is found in that direction and if it equals 5 then go to your 'win' procedure.

eg) if the current situation is like this -> XX_XX and you filled in the missing piece: XX'X'XX
check the 4 possible directions (horizontal, vertical, and the 2 diagonals) for pieces.

counter = 1
Starting from the piece you played, check left and add 1 to the counter, then keep and adding 1 to the ocunter until you reach an opposing piece. Then check the right side and do the same thing.
If a win has not been found, reset counter to 1 and check the other directions.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: