What algorithm for a tic-tac-toe game can I use to determine the “best move” for the AI?

The strategy from Wikipedia for playing a perfect game (win or tie every time) seems like straightforward pseudo-code: Quote from Wikipedia (Tic Tac Toe#Strategy) A player can play a perfect game of Tic-tac-toe (to win or, at least, draw) if they choose the first available move from the following list, each turn, as used in … Read more

my else if statement isnt working in my tic tac toe program [duplicate]

if (currentstate == you_win){ System.out.println(“‘X’ Won!!”); else if (currentstate == comp_win) System.out.println(“‘O’ won!!”); else if (currentstate == draw) System.out.println(“It’s a Draw :(“); } Take a look at this line (and I removed some extraneous code to make this easier to see): if (currentstate == you_win){ else if (currentstate == comp_win) //… } Looking at it … Read more