0% found this document useful (0 votes)
80 views4 pages

1 PENTAGO Game

The document describes a PENTAGO game and provides objectives for a Python programming project to implement the game. The project involves 3 steps - 1) creating a skeleton and user interface, 2) implementing the game rules, and 3) adding computer players of different difficulties.

Uploaded by

eclair636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views4 pages

1 PENTAGO Game

The document describes a PENTAGO game and provides objectives for a Python programming project to implement the game. The project involves 3 steps - 1) creating a skeleton and user interface, 2) implementing the game rules, and 3) adding computer players of different difficulties.

Uploaded by

eclair636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1 PENTAGO game

PENTAGO is a two-player game invented by Tomas Flod ́en that won several awards when first
commercialised (Wikipedia link: https://en.wikipedia.org/wiki/Pentago).

The game is played on a 6 × 6 board divided into four 3 × 3 sub-boards (or quadrants), see Figure 2. Taking
turns, the two players place a marble of their color onto an unoccupied space on the board, and then rotate one
of the sub-boards by 90 degrees either clockwise or anti-clockwise. A player wins by getting five consecutive of
their marbles in a vertical, horizontal or diagonal row (either before or after the sub-board rotation in their
move). If all 36 spaces on the board are occupied without a row of five consecutive being formed then the game
is a draw. If a situation arises where both players have five consecutive of their marbles in a vertical, horizontal
or diagonal row at the same time (whatever the number of 5-in-a-row lines they separately have), then the game
is also a draw.

There is also a 3 or 4 player version called PENTAGO XL, where the board is instead a 9 × 9 board made of
nine 3 × 3 sub-boards.

Interestingly, the 6 × 6 version of PENTAGO has been completely been solved with the help of a huge
supercomputer. Using the 4 TeraBytes (!) of data produced by this huge computation, a player can be
guaranteed to win provided that he starts the game. Yet, without using such enormous precomputed data, the
game is quite difficult because of its important branching (i.e. how many moves can be done at each turn, in the
worst case 36 × 8 = 288).

Figure 1: Example of a 6×6 PENTAGO board (image taken from Wikipedia). White wins with 5 consecutive
marbles in a diagonal.

2 Ob jectives
The objective of the project is to write in Python a working PENTAGO program. The program must allow the
user to configure the type of the two players (human or computer), and the difficulty level in case of a computer
player (two levels).
2

You have to implement this PENTAGO game following the three steps given below. Moreover, note that
everytime you add a feature to your program, you should test it thoroughly before continuing. Testing your
program only at the very end is the best way to render the bug hunting close to impossible !

3 Three steps to complete the project


3.1 1st step: implementing the skeleton of the project and the user interface

The first step in a programming project is perhaps the most important one: before writing any Python code, you
should think about the functions you will need to implement, their input/output, their goal, the overall structure
of the entire program. Once this done, you should write a skeleton of the project that only handles the interface
with the user (i.e. how the user will choose which position/rotation to play), the display of the board, and the
initialization of the variables.

3.1.1 Data Structure for the game.

In order to represent the board in Python, you can use a simple data structure: a 6×6 matrix of integers, where 0
represents no marble (i.e. empty), 1 stands for a marble belonging to player 1, and 2 for a marble belonging to
player 2 (row 0 being the top row). In order to represent that matrix, use a Numpy two-dimensional array: first
import the Numpy module using:

import numpy as np

You can create an empty board (all elements filled to 0) of r rows and c columns using:

game_board = np.zeros((r, c))


Finally, the element of the matrix located at row r and column c can be accessed using game board[r,c]. We

will use as convention that the row 0 is the top row.


3.1.2 Skeleton of the project.

You will have to implement the following functions for your project. Note that board will denote a 6 × 6 matrix
of integers representing the board, turn will denote an integer representing who’s turn it is to play (thus equal to
either 1 or 2),

• check victory(board, turn, rot). This function’s role is to check if a victory situation has been reached. It will
take a matrix board and an integer turn as inputs, as well as the rotation integer rot that has just been played (we
consider this rotation action has already been applied to board) and will return:

– 0 if no winning/draw situation is present for this game – 1 if player 1 wins


– 2 if player 2 wins
– 3ifitisadraw

• apply move(board, turn, row, col, rot). This function’s role is to apply a certain move to a game. It will take a
matrix board, an integer turn as inputs, as well as three integers row, col and rot that will represent the move
made by the player. It returns an updated board according to that move.

• check move(board, row, col). This function’s role is to check if a certain move is valid for a certain board. It
will take a matrix board as well as two integers row and col (that will represent the position played) as inputs. It
returns a boolean value False if the move is impossible, and it return True if the move is possible.

• computer move(board, turn, level). This function’s role is to ask for the computer to make a move for a certain
board. It will take a matrix board and an integer turn as inputs, as well as an integer level that will represent the
level of the computer opponent. It will return three integers: a row, a column and a rotation value, representing
the move played by the computer.

• display board(board). This function’s role is to display the board in the console. It takes a matrix board as input
and does not return anything.

• menu(). This function’s role is to handle the menu interface with the user via the console. It is basically the
director function that will interact with the user and distribute the work to all functions. It should be the main
function that is called in your Python script. It takes no input and doesn’t output anything.

3.2 2nd step: implementing the rules of the PENTAGO game

Once the skeleton ready, you can start writing the internals of the functions that will implement the game.

Display. The display should be handled in a separate function display board, that can be called every time a new
move was made by a player. A simple way to implement that function is to simply print the board matrix
(optionally, you can create a more advanced display function, using a graphical display, or using the SenseHat
module of a Raspberry Pi).

Making a move. Note that a move from a player can be described by a row index (integer between 0 and 5), a
column index (integer between 0 and 5) and a rotation index (integer between 1 and 8, see Figure 2). Your menu
should error-check that the user did not try to enter a row/column beyond board limits, or non-existing rotation
index. Once the move chosen, your program must check if the move is valid and apply it only if it is indeed a
valid move. Then, if the move is valid, it must check if a victory situation is reached. This entire sequence
repeats until the game is over, or the user would like to quit the game.
Figure 2: Correspondence between the rotation ID (between 1 and 8) and the actual board rotations.

Checking victory. In order to check if a victory situation is reached, you must check if 5 consecutive marbles (or
more) of the same color are present in one of the rows, columns or diagonals of the board. Be careful, victory
situation must be checked before the rotation was applied, and then after the rotation was applied. It might
happen that both players get at least 5 consecutive marbles of their color in different rows, columns or
diagonals. In that case, the game is a draw. Finally, if the board is full and no win situation occurred, the game is
also a draw.

Once this entire second step is fully implemented, you should be able to play human versus human with your
program. Do not start the third step before this second step is fully functional (test several games, try unusual
situations to make sure there is no bug in your program).

3.3 3rd step: implementing the computer player

The last step of this project is to implement a computer player with two levels of quality.

Level 1: random computer player. To start, program a trivial strategy: each time he will have to play, the
computer player will randomly choose a move among all the possible random moves (row, column and rotation
choices). You can test that this player is easy to beat.

Level 2: medium computer player. Program a computer player that will necessarily play a move that leads to a
direct win for him if such a move exists. If no such move exist, it will avoid to play a move that leads to a direct
win for his adversary in the next round (if such a move exist for the adversary). If again no such move exist, the
computer player will simply pick a random valid move.

You might also like