1

I am currently busy with a project for a university module where we have to create a computer based implementation of the original Cluedo board game that can be played with 4 to 6 players over a network. My main responsibility is the network, but due to my love for data structures I volunteered to create a class that implements the actual game board as a graph in order to provide pathfinding for our AI player as well as validation for moves and paths of players playing the game. In the original project description all players started on their own tile, but this was changed recently.

Dus to the original specification and due to the rule that a player may not move through the center room, I simply made that the center room only has a path to it, not from it (thus no children in the graph node). When the project changed I forgot about this and we started getting errors that the server says a move is invalid everytime the game starts, because naturally the pathfinding says that the distance of any path from the center room is infinite and thus (distance > playerDiceRoll).

We quickly needed a work around, without changing everything or the structure of the graph, due to the face that a player shouldn't move through the center. My solution to this was that in the validate move function, I simply check whether the player is in the center room and then return whether a move from any of the for exit blocks from the center to the desired destination with the current dice roll value is valid (because moving to any block from the center a human player would take the shortest path, using the exit closest to their desired destination.

My result code was basically:

if (in center && target != destination)
return validMove(exit1, destination, rollValue) || validMove(exit2, destination, rollValue) || .......;

My friends immediately didn't think it will work, but I sat there with a smile and compiled my code with full confidence. Their faces were priceless!

Comments
Add Comment