Friday, 30 January 2015

On what basis to split classes

What should a generic turn based game consist of? How should classes be designed?

Whenever I program, I always try to think of some physical process. For example, when I was first tackling the sorting problem, I thought of insertion sort. When I sort my cards, that's how I sort. I trace back to how my brain does it and then I make the code do exactly that. Of course there may be limitations to this, but I find that this is a good starting point.

Similar methodology was used when I tackled this problem. When I imagine a game, what entities are involved? First and most obvious are the players. And then there is the some neutral entity that manages the game... I would call it the game master. The game master talks to the players and notifies them of the game state, announces other people's moves, etc. In poker this would be like the dealer. The game master is directly aware of the game state, since it keeps track and modifies it. The game master can learn about the game using the game state. I think of the game state as the chips/panel used to keep track of all the information and a rule book of how to manage the game. The game master refers to the book for what instructions are needed to be given to manage the game and also interacts with the record, modifying it and referring to it as needed. other_info is shown as an example to express that the game board can be extended (current number might be in the other_info). Note that some minor details are omitted and levels are only conceptual.

One "problem" I found with the assignment is that it is open but also closed. For example, in the game state I did not want to generate all possible moves. The rule_book only needs to be able to say whether the move can be made. There is no need to generate all moves. I wanted the computer to be able to find possible moves and so wanted to implement AI that is specific to the game. Part of the player's role is to find the moves given the game. Due to the structure of the requirements, it was more convenient for game state to be able to generate the moves. I  guess this is just a minor issue.

In a future post, maybe I will talk about more detailed implementation details. If you have any questions about how I did things, feel free to comment. I'm also interested in learning about how other people thought to do this.

No comments:

Post a Comment