Programming Project
The objective of this project is to design the Snakes and Ladders game. The project needs to simulate the game with the ability to roll dice between two players, and then apply the game logic to decide who the winner is.
The game board has 100 cells starting from 1 to 100. There are two players and each player rolls the dice and moves cell position accordingly. There are snakes and ladders in different cells with each cell having either a ladder, a snake or nothing but not both in the same cell. If a player moves to a cell that contains a ladder, the player jumps up by 15 cells. If the player moves to a cell including a snake mouth, the player drops off by 10 cells. The rolling of dice continues until one of the players reaches a cell above 99, that player will be declared as the winner of the game.
The steps to design the game are:
Step 1: get_players_list()
Create a function get_players_list() that reads and stores both player names in a list. The function prints and returns name_list.
Step 2: generate_ladders_position()
There are 15 ladders in the game. Declare function generate_ladders_position()to generate the positions of these ladders randomly, and store them in a list. Ladder positions should be in the range of cells 5 to 85 (both inclusive). You must avoid assigning the same cell to more than one ladder. The function prints the ladder positions and returns ladders_list.
Step 3: generate_snakes_position()
There are 10 snakes in the game. Declare function generate_snakes_position()to generate the positions of these snakes mouths randomly, and store them in a list. Snake mouth positions should be in the range of cells 20 to 95 (both inclusive).
You must avoid assigning the same cell to more than one snake. Moreover, the function should receive an input argument (ladders_list) to avoid assigning a cell to both a ladder or a snake, meaning that no cell can host both a ladder or a snake mouth. Nevertheless, for simplicity reasons, the game allows snakes cells that jump down to a ladder cell, or ladder cells that put the player in a snake mouth. For example, a player may jump on a ladder and then get bitten by a snake.
The function prints and returns the snakes_list.
Step 4: roll_dice()
Define a function to roll the dice i.e., generating a random number between 1 and 6 (both inclusive). The function should receive two arguments, current_position (an integer) of the player rolling the dice, and player_name, the name of the player rolling the dice. The function returns the new position of the player. The function also prints the value of the dice, and the new position of the player. The new position is calculated as current_position + the dice value.
For example, roll_dice(current_position=54, player_name="John") prints:
Step 5: check_for_ladder()
Write a function to accept three input arguments, 1) current_position of a player, 2)ladder_list, and 3) plyer_name. The function checks if the position contains a ladder. If so, increase the current position of the player by 15 cells and return the new position.
The function also prints a message explaining what happened, and the player’s new position. For example:
Step 6: check_for_snake()
Create a function to receive three input arguments, 1) current_position of the player, 2) snake_list, and 3) player_name, and check if the position contains a snake mouth. If so, decrease the current position of the player by 10 cells and return the new position.
The function also prints a message explaining what happened, and the player’s new position, for example:
Step 7: Main Program
The main program is responsible for running the game using the functions defined above, and identify the winner. An example of the tasks on the Main program can be:
DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma
Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t
Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th
1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of
1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of