polewcad.blogg.se

Code to check if my tic tac toe tie
Code to check if my tic tac toe tie











code to check if my tic tac toe tie

you might find that the entire game can be played, evaluated and scored VERY efficiently - using simply bitwise logic.īTW I'm not a regular here on StackOverflow, so I hope this post wasn't too chaotic to follow. With some clever choice of integers to represent moves, positions or boards. See if the states fit within an integer, and think about what an 'easy' bitmask to process would look like.

code to check if my tic tac toe tie

If you're looking for efficient ways to process a board, don't start with a board object. if the result is nonzero, then the position is already in use. Just check the 'AND' of this Value with (XB OR OB). If user chooses UpperLeft, this position has an integer value. So, you can check if a move is valid quite easily. Obviously, ORing "X's board" with "O's board" = ALL POSITIONS from move checking, to board updating and right through to win/loss detection and an appropriate success message, all fit in a handful of ASM instructions. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. This code is for an n by n board with n in a row to win (3x3 board requires 3 in a row, etc) public class TripleT Also since there are a fixed number of moves in a draw tic-tac-toe game once the last move is made if it wasn't a winning move it's by default a draw game. Keep in mind I'm a first year CS student, yet all of my tests seemed to work rather well.You know a winning move can only happen after X or O has made their most recent move, so you can only search row/column with optional diag that are contained in that move to limit your search space when trying to determine a winning board. This is how I went about checking for a tie for the project that I just had to do.













Code to check if my tic tac toe tie