Creating the basic Ludo Board model


The Board model

As a first step, we will just model the state of the tokens on the board, while deferring the logic of the game.

The board just keeps track of the state of the tokens on the squares, but does not know the rules of the game.

Caveat: Originally we had separate LudoBoard and LudoGame classes, but at some point it became simpler to unify these two, to have the game logic close to the representation.

We start with a simple test example of an empty board and state what should be true about it.


	| board |
	board := GtLudoGame new.
	self assert: board players size equals: 4.
	self assert: board squares size equals: 40.
	self assert: board tokens size equals: 8.
	board tokens do: [ :token | self assert: token isInStartState ].
	board squares do: [ :square | self assert: square isEmpty ].

	board players do: [ :player | 
		| route |
		route := board routeFor: player.
		self assert: route size equals: 42.
		self assert: route first kind equals: #initial.
		self assert: route last kind equals: #goal.
		self assert: route nextToLast kind equals: #goal ].

	^ board

In this first simple example we just focus on the basics (each of these translates to an assertion in the example method above):

• a Ludo board has 4 Players, 40 Squares and 8 Tokens

• the Board knows the Players and the Squares, and the Players know their Tokens.

• Tokens know their state, i.e., whether they are in play or not

• Tokens are all initially in the start state

• Squares know whether they are empty or not. They either hold a real player token or a dummy, blank token. A token knows if it is the blank token or not.

• all Squares are empty

• each Player follows its own Route of 42 squares, starting with an initial square and end with two goal squares

We implement the missing parts until the test example runs.

Caveat: if we inspect the result of this example, we will already see a graphical representation, but this is only implemented later. Look at raw view to see roughly where we are now.