In this Project, you will first create a text-based board game in Python that will use...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
In this Project, you will first create a text-based board game in Python that will use 2-dimentional lists, recursions, loops and other programming logics. Insert Python code into this notebook. You are expected to add and test several functions in this file that will help the main function to start and continue the game. Rules of the game: This game will be played using a 2D-list (board) that must always have the same number of rows and columns. The board will be displayed to the user in the following format. 812 3 0 • G can move to any empty column on row 0 only. . P does not move at all. • 1 2 3 4 5 6 1 1 1 + = = = = G P 2. then go to row,column in the following (valid) move. . G, B. R cannot move to a location if that location is already occupied by another soldier. B = - P - = - B can move diagonally in four different directions, i.e., left-up, right-up, left-down and right-down. R can move in a straight line in four different directions, i.e., left, right, up. and down. . B and R cannot pass a P on their way to a new location row,column, unless B/R captures P on their first (valid) move and P R Р B 45 6 = = - P = a 1 2 3 4 Р = = + 1 I P - R = 5 6 1 I I I I + 0 Please note the following: . This example game board has 7 rows and 7 columns (7x7). The row and column numbers (0,1,...6 in this example), and the additional symbols (+) are not part of the 2D-list. These symbols must be displayed whenever the board is displayed to the user. G: the general will be placed in some random column on row 0. . • P: pawns will be placed in all columns on row 1. • B: two (2) bishops will be placed in random columns on the last row (row 6 in this example). . R: two (2) rooks will be placed in random columns on the last row as well (row 6 in this example). • B and R are called soldiers. The user of your program should be able to move these soldiers (see Valid moves below) to some other locations on this board and try to capture G to win the game. Valid moves: 1 2 3 4 5 6 Your program must also create another 2D list (trap_map - see below) that should not be visible to the user but the total number of hidden traps should be displayed in the beginning of the game. Your program should randomly place some traps (T) on rows 2 to the second last rows on the board with some predefined probability (see rules in later part of the specifications). This board has 8 hidden traps. How the game continues: The game starts by displaying the game board and the total number of hidden traps. Then the game will continue in a loop until 1. G is captured by the soldiers or 2. all four soldiers die. The maximum board size can be 10x10 and the minimum board size can be 5x5. At every iteration of the game, 1. Your program should ask the user which soldier they want to move and where. 2. The user must enter these two information (locations) as row,column - where row and column are valid integer numbers (refer to the max/min board size to check the validity), separated by a comma. In case the user enters bad inputs (anything other than two valid integers separated by a comma), they should be asked again unless valid inputs are entered. 3. Next, your program must check if a soldier is present in the current location entered by the user, if not a message will be displayed to the user and nothing changes. 4. If a soldier is available in the current location, your program must validate the move of that soldier (see Valid Moves) from their current location to the new location. If the move is not valid, the soldier will not move, a message will be displayed to the user and nothing changes. 5. If the move is valid, your program should check if there is any hidden trap on the track from the current location to the new location. If a trap is there, that soldier dies, and the user loses 1 point. Subsequently, G will move to a random free location on row 0. The board should be displayed again showing that trap. A message and the current points will be shown to the users. 6. If there is no trap on the track, the soldier moves to the new location and one of these three cases may occur. a. If the new location contains P, the soldier captures (replaces) P and the user gets 2 points. G will move to a random free location on row 0. The updated board should be displayed again. A message and the current points will be shown to the users. b. If the new location contains G, the soldier captures G and the user gets 10 points. The updated board should now display all previously hidden traps. A message and the current points will be shown to the users. If the new location is empty, the soldier just moves there, and the updated board should be displayed. A message and the current points will also be shown to the users. See the sample runs on BB. Required Functions: You must write the following functions (not necessarily in this order) as they are the required components for this assignment. You are encouraged to create any additional helper functions, if you prefer, to better organize your code. • create_board() - does not take any parameter and creates a 2D-list to represent the board with a predefined SIZE, where SIZE is a global constant, with 5 ≤ SIZE ≤ 10. The board should contain G, P. B. R according to the given rules above. The empty locations should have - symbols. . set_traps() - does not take any parameter and creates a 2D-list to represent the trap_map with a predefined SIZE, where SIZE is a global constant, with 5 ≤ SIZE ≤ 10. The trap_map should contain traps (T) placed randomly according to the given specifications above. Set the probability value to 20%, that is your program should place a trap in the current location with a 20 in 100 chance (or a 2 in 10 chance). This function should also display how many hidden traps the game board has. • display_board() - takes a 2D-list as an argument and prints the board to the terminal is the specified format. • validate_moves()- takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and a 2D-list representing the board. This function returns True if the proposed move is valid (see rules), otherwise returns False. . check_traps()- this must be a recursive function that takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and a 2D-list representing the trap_map. This function checks for traps on the proposed track of the soldier from their current location to the new location, and returns the location of the trap, if exists. Otherwise, it returns False. . move_general() - takes a 2D-list as an argument representing the board. This function moves the location of G (see the rules) and returns the updated 2D-list. . move_soldier() - takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and two 2D-lists representing the board and trap_map, respectively. This function follows the rules of the game and move the soldier to the new location if everything goes according to the rules. It should also update the board, displays necessary messages to the terminal and returns the score that the user earned during this move. • main() - creates two 2D-lists representing the board and the trap_map, respectively. Then it must start the game that should repeat the steps of the game (see How the game continues), until the user wins or loses. If the user loses (when all soldiers die), it should display a 'Game Over' message. If the user wins (when G is captured), a "You Win' message should be displayed with the final score. Sample run 1 (6x6 board): Game starts now >> 012345 +======+ 0|----G-10 1|PPPPPP|1 2--- |2 3 31- 41- 5|B-R-RB 5 +======+ 012345 This board has 3 hidden traps! To move your soldier enter it's current position <row, col>: 5,2 Enter the new position <row, col> : 1,2 012345 +======+ 01-G-10 1|PPRPPP|1 21--- 3|--- 41------14 5 B---RB 5 +======+ 012345 ----- |2 |3 Your score: 1 To move your soldier enter it's current position <row, col>: 1,2 Enter the new position <row, col> : 1,3 In this Project, you will first create a text-based board game in Python that will use 2-dimentional lists, recursions, loops and other programming logics. Insert Python code into this notebook. You are expected to add and test several functions in this file that will help the main function to start and continue the game. Rules of the game: This game will be played using a 2D-list (board) that must always have the same number of rows and columns. The board will be displayed to the user in the following format. 812 3 0 • G can move to any empty column on row 0 only. . P does not move at all. • 1 2 3 4 5 6 1 1 1 + = = = = G P 2. then go to row,column in the following (valid) move. . G, B. R cannot move to a location if that location is already occupied by another soldier. B = - P - = - B can move diagonally in four different directions, i.e., left-up, right-up, left-down and right-down. R can move in a straight line in four different directions, i.e., left, right, up. and down. . B and R cannot pass a P on their way to a new location row,column, unless B/R captures P on their first (valid) move and P R Р B 45 6 = = - P = a 1 2 3 4 Р = = + 1 I P - R = 5 6 1 I I I I + 0 Please note the following: . This example game board has 7 rows and 7 columns (7x7). The row and column numbers (0,1,...6 in this example), and the additional symbols (+) are not part of the 2D-list. These symbols must be displayed whenever the board is displayed to the user. G: the general will be placed in some random column on row 0. . • P: pawns will be placed in all columns on row 1. • B: two (2) bishops will be placed in random columns on the last row (row 6 in this example). . R: two (2) rooks will be placed in random columns on the last row as well (row 6 in this example). • B and R are called soldiers. The user of your program should be able to move these soldiers (see Valid moves below) to some other locations on this board and try to capture G to win the game. Valid moves: 1 2 3 4 5 6 Your program must also create another 2D list (trap_map - see below) that should not be visible to the user but the total number of hidden traps should be displayed in the beginning of the game. Your program should randomly place some traps (T) on rows 2 to the second last rows on the board with some predefined probability (see rules in later part of the specifications). This board has 8 hidden traps. How the game continues: The game starts by displaying the game board and the total number of hidden traps. Then the game will continue in a loop until 1. G is captured by the soldiers or 2. all four soldiers die. The maximum board size can be 10x10 and the minimum board size can be 5x5. At every iteration of the game, 1. Your program should ask the user which soldier they want to move and where. 2. The user must enter these two information (locations) as row,column - where row and column are valid integer numbers (refer to the max/min board size to check the validity), separated by a comma. In case the user enters bad inputs (anything other than two valid integers separated by a comma), they should be asked again unless valid inputs are entered. 3. Next, your program must check if a soldier is present in the current location entered by the user, if not a message will be displayed to the user and nothing changes. 4. If a soldier is available in the current location, your program must validate the move of that soldier (see Valid Moves) from their current location to the new location. If the move is not valid, the soldier will not move, a message will be displayed to the user and nothing changes. 5. If the move is valid, your program should check if there is any hidden trap on the track from the current location to the new location. If a trap is there, that soldier dies, and the user loses 1 point. Subsequently, G will move to a random free location on row 0. The board should be displayed again showing that trap. A message and the current points will be shown to the users. 6. If there is no trap on the track, the soldier moves to the new location and one of these three cases may occur. a. If the new location contains P, the soldier captures (replaces) P and the user gets 2 points. G will move to a random free location on row 0. The updated board should be displayed again. A message and the current points will be shown to the users. b. If the new location contains G, the soldier captures G and the user gets 10 points. The updated board should now display all previously hidden traps. A message and the current points will be shown to the users. If the new location is empty, the soldier just moves there, and the updated board should be displayed. A message and the current points will also be shown to the users. See the sample runs on BB. Required Functions: You must write the following functions (not necessarily in this order) as they are the required components for this assignment. You are encouraged to create any additional helper functions, if you prefer, to better organize your code. • create_board() - does not take any parameter and creates a 2D-list to represent the board with a predefined SIZE, where SIZE is a global constant, with 5 ≤ SIZE ≤ 10. The board should contain G, P. B. R according to the given rules above. The empty locations should have - symbols. . set_traps() - does not take any parameter and creates a 2D-list to represent the trap_map with a predefined SIZE, where SIZE is a global constant, with 5 ≤ SIZE ≤ 10. The trap_map should contain traps (T) placed randomly according to the given specifications above. Set the probability value to 20%, that is your program should place a trap in the current location with a 20 in 100 chance (or a 2 in 10 chance). This function should also display how many hidden traps the game board has. • display_board() - takes a 2D-list as an argument and prints the board to the terminal is the specified format. • validate_moves()- takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and a 2D-list representing the board. This function returns True if the proposed move is valid (see rules), otherwise returns False. . check_traps()- this must be a recursive function that takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and a 2D-list representing the trap_map. This function checks for traps on the proposed track of the soldier from their current location to the new location, and returns the location of the trap, if exists. Otherwise, it returns False. . move_general() - takes a 2D-list as an argument representing the board. This function moves the location of G (see the rules) and returns the updated 2D-list. . move_soldier() - takes the following arguments, four integers representing the rows and columns of the current location and the new location, respectively, and two 2D-lists representing the board and trap_map, respectively. This function follows the rules of the game and move the soldier to the new location if everything goes according to the rules. It should also update the board, displays necessary messages to the terminal and returns the score that the user earned during this move. • main() - creates two 2D-lists representing the board and the trap_map, respectively. Then it must start the game that should repeat the steps of the game (see How the game continues), until the user wins or loses. If the user loses (when all soldiers die), it should display a 'Game Over' message. If the user wins (when G is captured), a "You Win' message should be displayed with the final score. Sample run 1 (6x6 board): Game starts now >> 012345 +======+ 0|----G-10 1|PPPPPP|1 2--- |2 3 31- 41- 5|B-R-RB 5 +======+ 012345 This board has 3 hidden traps! To move your soldier enter it's current position <row, col>: 5,2 Enter the new position <row, col> : 1,2 012345 +======+ 01-G-10 1|PPRPPP|1 21--- 3|--- 41------14 5 B---RB 5 +======+ 012345 ----- |2 |3 Your score: 1 To move your soldier enter it's current position <row, col>: 1,2 Enter the new position <row, col> : 1,3
Expert Answer:
Answer rating: 100% (QA)
To create the Python program for the described textbased board game well start by de... View the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
MCO Leather manufactures leather purses. Each purse requires 2 pounds of direct materials at a cost of $5 per pound and 0.7 direct labor hour at a rate of $13 per hour. Variable overhead is budgeted...
-
Is there any resource that you could consider as a distinctive competence for Yunnan Lucky Air?
-
A Yahtzee game made in C please! Objectives: Student should be able to: Define an array Manipulate and print an array Use parallel arrays Pass an array to a function Use pass by reference Calculate...
-
Solve each system using the substitution method. If a system is inconsistent or has dependent equations, say so. -5x + 2y = -2 x + 6y = 26
-
(a) Write Newman projections for the gauche and anti conformations of 1, 2-dichloroethane (ClCH2CH2Cl). (b) The measured dipole moment of ClCH2CH2Cl is 1.12 D. Which one of the following statements...
-
The drawing illustrates an overhead view of a door and its axis of rotation. The axis is perpendicular to the page. There are four forces acting on the door, and they have the same magnitude. Rank...
-
Assume that the flowrate, \(Q\), of a gas from a smokestack is a function of the density of the ambient air, \(ho_{a}\), the density of the gas, \(ho_{g}\), within the stack, the acceleration of...
-
Squirrel Tree Services reports the following amounts on December 31. In addition, the company reported the following cash flows. Required: 1. Prepare a balance sheet. 2. Prepare a statement of...
-
4. (30 points) In a small community with a population of 4,000, an incident released E. coli into the water supply, resulting in the infection of 50% of the community's residents. a) Calculate the...
-
Obtain v(t) and i(t) for t > 0 in the circuit in Fig. 16.54 . 5 H ll i(t) 24 V (+ 10u(t) v(t) 200 mF
-
Royal Bank (RBC) is currently trading for $84.10. You believe that RBC will release its annual report at on January 19 th , 2024. It is your belief that the company will beat the market's...
-
Use a truth table to prove the first Negation law: pV p=t Use a truth table to prove the second Negation law: p^~ p=c
-
5. Consider a three-period binomial model for a stock S whose current price is So = 100. Suppose that over each of the next three years, the stock price can either move up by a factor u = 1.2 or down...
-
The magnetization circuit parameters are neglected in representation of equivalent cireuit for three phase induction motor under blocked rotor test, discuss this sentence by aid of diagrams? 4* What...
-
( Ces SecuriCorp operates a fleet of armored cars that make scheduled pickups and deliveries in the Los Angeles area. The company is implementing an activity-based costing system that has four...
-
Complete the following table of basic calculations. For Percent Contribution Margin, use (P-MC)/P. Round to table standard. Price 18 17 16 15 14 13 j Quantity Demanded 600 a 800 900 1000 1100 1200...
-
What are Turkish family traditions?
-
Which of the following raises the credibility of areport? Which of the following raises the credibility of a report? Multiple Choice avoiding predictions avoiding the use of cause-effect statements...
-
1. Fraud detection involves (______). a. Finding frauds b. Finding fraud indicators c. Finding the perpetrator d. None of the above 2. The pattern of numbers associated with Benford Analysis involves...
-
Collateral Deposit (Part 2)2 (This is a continuation of Problem 27 in Chapter 2.) Required Part 1 prepares an analytic flowchart and cross-references it to the list of procedures that accompanies...
-
The Nelm Company has discovered through experience that somehow Erm, its major competitor, seems to discover its every secret. For example, when Nelm launches a new advertising campaign, Erm always...
-
For the composite properties and environmental conditions described in Examples 3.6, 4.7, and 5.3, determine the hygrothermally degraded values of the longitudinal and transverse tensile strengths....
-
The filament-wound E-glass/epoxy pressure vessel described in Example 4.4 is to be used in a hot-wet environment with temperature \(T=100^{\circ} \mathrm{F}\) \(\left(38^{\circ} \mathrm{C} ight)\)...
-
A carbon/epoxy lamina is clamped between rigid plates in a mold (Figure 5.17), while curing at a temperature of \(125^{\circ} \mathrm{C}\). After curing, the lamina/mold assembly (still clamped...
Study smarter with the SolutionInn App