I am going to develop a Tic-Tac-Toe game using Java(or maybe other OO Languages). Now I have a picture in my mind about the general design.
Interface:
Player, then I will be able to implement a couple of Player classes based on how I want the opponent to be, for example, random player, intelligent player, etc.
Classes:
Board class, with a two-dimensional array of integers, 0 indicates open, 1 indicates me, -1 indicates opponent. The evaluation function will be in here as well, to return the next best move based on the current board arrangement and whose turn it is.
Referee class, which will create instance of the Board and two player instances, then get the game started.
This is a rough idea of my OO design. Could anybody give me any critiques please? I find this is really beneficial. Thank you very much.
When I think of object structure, I think of my methods as doing one of two things:
1) asking an ‘object’ a question
2) commanding the ‘object’ to do something
That being said, it doesn’t make sense to me to ask the ‘board’ what the next best move is. The board should simply hold values and tell you about its state.
I would probably have an object that is dedicated to determining the best next move for a given ‘intelligence’. Let’s call it the ‘move_brain’. Then you can say, “hey move_brain, given this board and this level of intelligence, what’s the next best move?”
The board class as you have outlined it now has many responsibilities: holding state, allowing users to move, AND thinking about how to move next. That’s too much responsibility.
And after all that, I would say this: given that this program is not THAT massive, pretty much any solution will be okay.
Best of luck!