Algorithm design methods: decision tables, JSP and state-transition diagrams – A Level Computer Science (old syllabus, to 2021) (9608)

16 questions · page 2 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9608/41/M/J/16 · Question 6May/June 2016Paper 4117 marks
Loading question…
Question text

6
In a board game, one player has white pieces and the other player has black pieces. Players take
alternate turns to move one of their pieces. White always makes the first move.
The game ends if:
•
a player is unable to make a move when it is their turn. In this case, there is no winner. This is
called ‘stalemate’.
•
a player wins the game as a result of their last move and is called a ‘winner’.
(a) A state-transition diagram is drawn to clarify how the game is played.
Complete the following state-transition diagram.
WHITE
WINS
No move
possible
:+,7(·6
TURN
Stalemate
BLACK moves
BLACK
%/$&.·6
WINS
TURN
Winning
move
[4]
(b) The layout of the board at the start of the game is shown below:
x
y
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
The programmer decides to use a 2D array to represent the board. The index numbering to
be used is as shown.
Each square on the board is either occupied by one piece only, or is empty.
The data stored in the array indicate whether or not that square is occupied, and if so, with a
black piece or a white piece.
(i)
Write program code to initialise the contents of the array to represent the board at the
start of the game. Use characters as follows for each square:
'B' represents a black piece
'W' represents a white piece
'E' represents an empty square
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language …
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

Advertisement