niombud.blogg.se

Computer replacing my x's tic tac toe unity
Computer replacing my x's tic tac toe unity








computer replacing my x

If(board = board & board = board & board != '-')Įlse if(board = board & board = board & board != '-') checks if there is an empty place on the board asks the user for the number of players constructor that fill the board array with dashes. creates scanner object used to get user input declares multiple integers used throughout the game simulation create a 3*3 array of characters that acts as the board in the game. declares the symbol character that will hold either "x" or "o" ay() //this simulates the whole game from asking the number of players all the way to printing the win message.

computer replacing my x

TicTacToe game = new TicTacToe() //creates an object Here is the code.ĭriver File: public class DriverTicTacToe Also, I am relatively new to Java so if I am doing something wrong, please let me know how to do it so that I can fix it and improve my own skills. If none of them are true, then it should randomly select a square and make it's move. If not, it should check if the user can win and prevent them from winning. I am looking for a simple way to go through the 2d array and sees if it has a way to win. Currently, the computer randomly generates a row and a column and if the corresponding square in the array has a "-" (signifying that it is empty), it will fill it with an "o".

computer replacing my x

I have gotten both of them to work but am trying to make the AI have some logic as to where it places its "o". I am trying to make a Tic-tac-toe game where the user gets to select whether they would like to play a single player game or a two player game.










Computer replacing my x's tic tac toe unity