Hi every one! Im a total java noob, and ive got to do a Tic tac toe game for my java class and Im getting a lot of difficulties ,and since Ive been a lurker of this forum for a while now, I decided to post here haha . Ive already searched for a tons of code of how to do a tic tac toe java game but i cant understand them very well and the most part of code that ive seen is much more complicated for what i want, I just want a simple tic tac toe game that executes in the console haha..
basically the game must have 2 game modes : SinglePlayer and TwoPlayers. The singlePlayer mode must have three levels of difficulty : Easy, Medium and Hard.
I decided to start with the two player mode but im having issues with how to execute the game with the players 'X' and 'O' and put it on the BoardGame.
I was thinking of doing a method that recieves the position of where I want to put the symbol and then alternate that symbol with a counter.. but i dont know how lol.. im thinking of doing a boardGame class that contains the board and the plays methods, a player class that contains the players and the Game modes and a TicTacToe class that just executes the game..
Heres my BoardGame class:
Thanks in advance.
P.s - Sorry about my english, its a bit rusty.
Obviously this won't play well but it will allow you to get a program to play. To get it to play slightly better you'll have to prefer the centre and corners before playing the sides. To get it to play much better then you'll need to look up MinMax searches and selecting the best move.
PS why do you use pos (1-9) to input a move but then store it in a 3*3 array? wouldn't it be simpler to just have a position array of length 9 and then store the board in that?
At original poster:
Its generally a bad idea to implement magic numbers.
what you can do is
may be you can make some classes.
1)Main class could control the game-flow, it the overall management of the game. It might contain
where the details about AI will go,
if you want to make three levels, make sure you treat the maximum depth in accordance to your level.
Say easy,maxPly=2 medium maxPly=5,hard maxPly=9.
If your implementation is correct then your code would be unbeatable at the hardest level(Converse, if your AI is beatable on level 9 then for sure there is some bug ;) )
This is just the tip of advice I can offer.
Anyways if you would like me to explain you more regarding the same, just drop me a PM and then I would even start to blog on how to write tic-tac-toe.
It would surely improve my english writing skills.