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.
System design is the designing the software/application as a whole [high level] that may include analysis, modelling, architecture, Components, Infrastructure etc. whereas the objected-oriented design is the set of defined rules/concepts to implement the functionalities within a software.
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!
I'd define 3 interfaces:
Here's a quick sketch of what would each class have:
Game:
IPlayer:
You could run the code like the following:
IPlayer meAsAPlayer = new UserPlayer(); //you'd have to implement this
//as an "empty" class that would let the user
//specify the actions
IPlayer AIPlayer = new AIPlayer(); //one AI class you'd have implemented
Game game = new Game(meAsAPlayer, AIPlayer);
game.start(); //this would run one game to the end
game.start(); //this would be the second game already
It would be the Game class that'd decide which plays would be correct and which wouldn't.If a player tried to make an incorrect play, it'd block it and it'd call again that player's OnTurn() event.
That or instead of defining the IPlayer interface you could define an APlayer abstract class that'd only let you make correct movements.
I would say that having using me and opponent for player moves isn't quite right. It should be either Xs and Os or first and second player. Beyond that, you've got a start. Where is input going to be handled? Referee or in the board square or somewhere else? Also, how about stat tracking that exists beyond 1 game?
Just some ideas.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With