Tor Egil Hoftun Kvæstad

— Joy in creation

Bondesjakk

Screenshot
Bondesjakk Screenshot

Bondesjakk directly translated into english means “Farmer-chess”. The game is played by two players, and the goal is to get five-in-a-row. The playing board can be of an arbitrary size, although in my version it is square.

System requirements

Download

FileBondesjakk-1_01.zip (22KiB)
Release1.01,
MD5-Sum39750612c7a7e12914afbdd27c13de66
SHA1-Sumd30e9db1b07a2c9d386bf2bab2149dddbe541fac
SHA256-Sum11be7279be55541f57ae0cc6d63b9996f17336a0d963f1ee9ba0644eee7d2256
GPG SignatureBondesjakk-1_01.zip.sig

Languages

Features

Design

The current design is shown in the following UML diagrams.

In my opinion, I’ve succeeded quite well in keeping UI code apart from the rest of the code. The model does not have any concept about the UI at all, and the controller (org.toregilhk.bondesjakk.Bondesjakk) does not need to know anything either, since it just uses an interface that must be implemented by the UI.

To find out if there is a winner, I’ve chosen to use a recursive method. The method used to find the amount of successive player symbols looks like this:

SuccessiveSymbols:
	if the x coordinate is out of bounds
	or the y coordinate is out of bounds
	or this cell contains nothing
	or this cell does not contain the current player
		return this cell's number - 1
	else if this cell's number == 5
		if this cell contains the current player
			return this cell's number
		else
			return this cell's number -1
	return this method called for the next cell and number + 1

In the above pseudocode, the x and y coordinates refer to the indices of an item in a two-dimensional array, here called a cell. The number is the amount of consecutive symbols belonging to the current player that have been found. The method is called every time a player puts his or her symbol on the board.

The directions that are to be searched are found in org.toregilhk.bondesjakk.model.Direction, which is an enum containing the compass directions and relative x and y coordinates to be used for finding the next cell in a given direction. Direction is again used by org.toregilhk.bondesjakk.Line, which contains two Direction-objects.

When a player puts his/her symbol on the board, the Line enums are searched through until a winning line can be found. To check if a Line is winning, it uses the following method:

IsLineWinning:
	integer d1 == call SuccessiveSymbols for the first direction
	integer d2 == call SuccessiveSymbols for the second direction
	return (d1 + d2) > 5

Since both calls for SuccessiveSymbols in IsLineWinning start from the cell of origin, what d1 + d2 returns is actually 1 more than it should have been (the cell of origin is counted twice). A winning line is therefore winning if d1 + d2 equals six or more.

Tools Used

ArgoUML, GNU Emacs, Java J2SE 1.6.0_13, JUnit, Subversion