Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python language Question 3 Code a Python program to play a board game with the computer. You are given a board represented as a 2-
Python language
Question 3 Code a Python program to play a board game with the computer. You are given a board represented as a 2- dimensional NXN square table, where each element of the given table is initialized with an integer data value between 100 and 800, inclusive. The aim of the game is to beat the computer, i.e., the player's accumulated points for the game should be higher than the computed points for the computer. Include the following game board definition in your program, but note that your code should work even if the board declaration below is changed to something with different values and/or a different size (but still a square board big enough to play the game): : board - [[100, 250, 200, 150, 110, 320, 800), (500, 600, 700, 450, 230, 230, 400), [200, 225, 230, 150, 330, 145, 105), [120, 520, 500, 200, 250, 175, 205), [ 405, 160, 800, 350, 150, 300, 210), [125, 205, 200, 200, 110, 100, 400), [300, 145, 120, 230, 250, 205, 600]] Your program should use the following three functions (main, printBoard and findHighest, described below) to play the game: the main function of the program should do the following: o print the given board row-wise (table as shown below in sample input/output) using the printBoard function o obtain the name of the player o obtain the number of rounds of the game to be played o generate the total points for the computer by generating a random number between 400 and 800 (inclusive) and multiplying it by the number of rounds to be played. o for each round of play generate two random numbers, between 1 and n-2 (inclusive), one for the row index and one for the column index using the findhighest function, find the highest value from one of the 8 neighbouring cells adjacent to the randomly generated row and column index accumulate that highest value as the total points for the player . display results (see sample input/output below) at the end of all the rounds of the game, print if the player won or lost the game or the game was a draw (see the sample input/output below) the printBoard function should, given the board, print the board/table row-wise (one row at a time) as follows: 100250200150110320800 15006001700450230 230 400 1200225230|150|330145105 12015205002001250175205 405160800350 150 300 210 125205200200110100400 300145120/230|250205600 the findHighest function should, given the board and the row and column index values, find and return the highest data value in the neighbouring elements in the table (not including the value at that location itself) Note: Section 6.7.3, page 287 in the text might be helpful in navigating the neighbouring elements in the table. Sample input/output 1: 1100250 200 1150110320800 1500 600 70014502302304001 1200225230115033014511051 112052050020012501752051 1405160800350 150 300210 112520520020011011004001 1300|145112023025020516001 Enter player name: Henny How many rounds do you wish to play? 4 To beat the computer you must get higher than 1756 points. Your selected cell is at row 4 and column 3 Your score for this round of the game is 800 Your total points up to and including round 1 are 800 Your selected cell is at row 5 and column 2 Your score for this round of the game is 800 Your total points up to and including round 2 are 1600 Your selected cell is at row 2 and column 1 Your score for this round of the game is 700 Your total points up to and including round 3 are 2300 Your selected cell is at row 2 and column 4 Your score for this round of the game is 450 Your total points up to and including round 4 are 2750 Henny, you have accumulated total of 2750 points. Congratulations, you won the game by 994 points. Sample input/output 2: 1100250 200 150110320800 1500 600 700 450 230 230 4001 1200225 230 150 13301451051 1120520500200125017512051 14051160 1800 1350 15013002101 11252051200 120011011004001 1300145 120 1230 250 20516001 Enter player name: Henny How many rounds do you wish to play? 3 To beat the computer you must get higher than 2352 points. Your selected cell is at row 5 and column 5 Your score for this round of the game is 600 Your total points up to and including round 1 are 600 Your selected cell is at row 5 and column 2 Your score for this round of the game is 800 Your total points up to and including round 2 are 1400 Your selected cell is at row 1 and column 5 Your score for this round of the game is 800 Your total points up to and including round 3 are 2200 Henny, you have accumulated total of 2200 points. Unfortunately, you lost the game by 152 points. Good luck for the next game. Question 3 Code a Python program to play a board game with the computer. You are given a board represented as a 2- dimensional NXN square table, where each element of the given table is initialized with an integer data value between 100 and 800, inclusive. The aim of the game is to beat the computer, i.e., the player's accumulated points for the game should be higher than the computed points for the computer. Include the following game board definition in your program, but note that your code should work even if the board declaration below is changed to something with different values and/or a different size (but still a square board big enough to play the game): : board - [[100, 250, 200, 150, 110, 320, 800), (500, 600, 700, 450, 230, 230, 400), [200, 225, 230, 150, 330, 145, 105), [120, 520, 500, 200, 250, 175, 205), [ 405, 160, 800, 350, 150, 300, 210), [125, 205, 200, 200, 110, 100, 400), [300, 145, 120, 230, 250, 205, 600]] Your program should use the following three functions (main, printBoard and findHighest, described below) to play the game: the main function of the program should do the following: o print the given board row-wise (table as shown below in sample input/output) using the printBoard function o obtain the name of the player o obtain the number of rounds of the game to be played o generate the total points for the computer by generating a random number between 400 and 800 (inclusive) and multiplying it by the number of rounds to be played. o for each round of play generate two random numbers, between 1 and n-2 (inclusive), one for the row index and one for the column index using the findhighest function, find the highest value from one of the 8 neighbouring cells adjacent to the randomly generated row and column index accumulate that highest value as the total points for the player . display results (see sample input/output below) at the end of all the rounds of the game, print if the player won or lost the game or the game was a draw (see the sample input/output below) the printBoard function should, given the board, print the board/table row-wise (one row at a time) as follows: 100250200150110320800 15006001700450230 230 400 1200225230|150|330145105 12015205002001250175205 405160800350 150 300 210 125205200200110100400 300145120/230|250205600 the findHighest function should, given the board and the row and column index values, find and return the highest data value in the neighbouring elements in the table (not including the value at that location itself) Note: Section 6.7.3, page 287 in the text might be helpful in navigating the neighbouring elements in the table. Sample input/output 1: 1100250 200 1150110320800 1500 600 70014502302304001 1200225230115033014511051 112052050020012501752051 1405160800350 150 300210 112520520020011011004001 1300|145112023025020516001 Enter player name: Henny How many rounds do you wish to play? 4 To beat the computer you must get higher than 1756 points. Your selected cell is at row 4 and column 3 Your score for this round of the game is 800 Your total points up to and including round 1 are 800 Your selected cell is at row 5 and column 2 Your score for this round of the game is 800 Your total points up to and including round 2 are 1600 Your selected cell is at row 2 and column 1 Your score for this round of the game is 700 Your total points up to and including round 3 are 2300 Your selected cell is at row 2 and column 4 Your score for this round of the game is 450 Your total points up to and including round 4 are 2750 Henny, you have accumulated total of 2750 points. Congratulations, you won the game by 994 points. Sample input/output 2: 1100250 200 150110320800 1500 600 700 450 230 230 4001 1200225 230 150 13301451051 1120520500200125017512051 14051160 1800 1350 15013002101 11252051200 120011011004001 1300145 120 1230 250 20516001 Enter player name: Henny How many rounds do you wish to play? 3 To beat the computer you must get higher than 2352 points. Your selected cell is at row 5 and column 5 Your score for this round of the game is 600 Your total points up to and including round 1 are 600 Your selected cell is at row 5 and column 2 Your score for this round of the game is 800 Your total points up to and including round 2 are 1400 Your selected cell is at row 1 and column 5 Your score for this round of the game is 800 Your total points up to and including round 3 are 2200 Henny, you have accumulated total of 2200 points. Unfortunately, you lost the game by 152 points. Good luck for the next gameStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started