Question: Pawn game Python Two players compete on a one-dimensional board of squares. Initially each box contains a random (possibly null) number of pions. In turn,

Pawn game Python
Two players compete on a one-dimensional board of squares. Initially each box contains a random (possibly null) number of pions. In turn, the players choose a box containing at least one pawn, and move one of the pawns therein to a box to the left, i.e. a strictly lower index box. This box can be empty or already contain one or more pions.
The winner is the last player to move a pawn. In other words, as soon as a player can no longer move a pawn he has lost. This of course corresponds to a situation where all the pieces of the board are on the first box.
Implement the following subroutines in a "nimble.py" file:
A "newBoard (n, p)" function that returns a one-dimensional list representing the initial state of a game board with n boxes. On each square will be positioned a random number of pawns included (in the broad sense) between 0 and p.
A "display (board, n)" procedure that displays on the console of the board. We will represent each box by the number of pions it contains, and we will indicate below its number. Example:
A "possibleSquare (board, n, i)" function that returns True if i is the number of a box containing a movable piece, and False otherwise.
A "selectSquare (board, n)" function that takes the number of a box containing a movable piece. We will assume that there is such a box, we will not test this fact here. As long as this number is not valid against the rules of the game and the size of the board, we will ask again to enter it. Finally, the function will return this number.
A "possibleDestination (board, n, i, j)" function where it is assumed here that i is the number of a box containing a movable pawn. This function returns True if j is the number of a box to which the number of i can move, and False otherwise.
A "selectDestination (board, n, i)" function where it is assumed here that i is the number of a box containing a movable pawn. This function makes you enter the number of a box to which the coordinate counter i can move. We will assume that there is such a box, we will not test this fact here. As long as this number is not valid against the rules of the game and the size of the board, we will ask again to enter it. Finally, the function will return this number.
A "move (board, n, i, j)" procedure where it is assumed here that i is the number of a box containing a movable piece, and that j is the number of its destination. This procedure performs this move.
A "lose (board, n)" function that returns False if there is at least one movable pawn on the board and True otherwise.
A "nimble (n, p)" procedure that will use the previous subroutines (and others if necessary) to allow two players to play a complete game on a set of n spaces, each one of them containing not more than pions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!