18.10.2014 Views

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

Object-oriented Software in Ada 95

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

9 Case study: Design of a game<br />

This chapter looks at the implementation of the game reversi. The problem is analysed us<strong>in</strong>g the fusion<br />

methodology and from this analysis and design is developed a program to play the game of reversi<br />

between two human players.<br />

9.1 Reversi<br />

In the game of reversi two players take it <strong>in</strong> turn to add counters to a board of 8-by-8 cells. Each player has a stack<br />

of counters, black one side and white the other. One player’s counters are placed white side up, whilst the other<br />

player’s are black side up. The object of the game is to capture all your opponent's counters. You do this by<br />

add<strong>in</strong>g one of your counters to the board so that your opponent's counter(s) are flanked by two of your counters.<br />

When you do this, the counters you have captured are flipped over to become your counters. If you can't capture<br />

any of your opponent's counters dur<strong>in</strong>g your turn, you must pass and let your opponent go.<br />

The game is won when you have captured all your opponent's counters. If neither player can add a counter to<br />

the board, then the player with the most counters w<strong>in</strong>s. If the number of counters for each player is equal, then the<br />

game is a draw.<br />

The <strong>in</strong>itial start<strong>in</strong>g position is set so that the 4 centre squares <strong>in</strong> the 8-by-8 board of cells is as illustrated <strong>in</strong><br />

Figure 9.1.<br />

Figure 9.1 The 4 center squares of a reversi board..<br />

On a reduced board of 4-by-4 cells a game might be as illustrated <strong>in</strong> Figure 9.2.<br />

Black’s move<br />

White’s move<br />

Black’s move White’s move Black’s move<br />

© M A Smith - May not be reproduced without permission

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!