So far I have pretty much working game, but I really can’t add all features as I want so far, because I can’t solve that problem.
Let’s say I have class Board, and each board have squares and pieces on those squares.
I have many players connected to game, for each two players (and observers etc) I need to have single board. My question is where to start with that ?
I think first of all I need multiple instances of class Board, and then I need a way of binding those boards to and individual games (games are identified by GUIDs).
My question is where to start with this?
So far I have it working but it heavily uses database and it not really optimal and with my current approach I can’t really do all things I wanted (move verification, dumping board state for future reference etc).
Because of the complexity involved in storing the state of the game, board games can make excellent use of a non-relational database like MongoDB.
If this isn’t an option (I assume you’re using a full Microsoft stack) I’d still avoid a relational approach to the data storage. Without knowing the specifics of your game, I can only speculate. Because of that, I’ll use scrabble as an example.
Dumping The Board
You could store the entire board state literally in a
boardStatetable, like this (5×5 non regulation scrabble board :))All processing could then be handled by the application logic. Imagine the database overhead if you were to try to relationally store this information!
Move Verification
Although scrabble doesn’t have “moves” to speak of, this is something that should avoid the database anyway. All processes like word-checking, board limits, game logic, etc should be handled entirely in the application layer.
Application Implementation
If I were you, I’d continue on the path you were going with having many instances of the
Gameclass, each containing aBoardobject. Store everything in memory and do all computations you need to in the application layer until something needs to persist (Board state if you want to save the game for later, game scores). At this time, dump it to the database.Without knowing more about your game logic I can’t speculate on how I’d handle it, so there’s a 20,000 ft. top down view.
Update:
Based upon the new information, I’d just load a GameCollection class with GUID identifiers into memory. You’d be able to access the individual games through something like
colGames[GUID]and boards withcolGames[GUID].Board. Store all relevant information in the database after the game ends/is saved and remove it from memory.