Question: Code a Python program to play a board game with the computer. You are given aboard represented as a 2-dimensional NX Nsquare table, where each
Code a Python program to play a board game with the computer. You are given aboard represented as a 2-dimensional NX Nsquare table, where each element of the given table is initialized with an integer data valuebetween 100 and 800, inclusive. The aim of the game is to beat the computer, i.e.,the players 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, printBoardand findHighest, described below)to play the game:the mainfunction of the program should do the following:oprint the given board row-wise (table as shown below in sample input/output) using the printBoardfunctionoobtain the name of the playeroobtain the number of rounds of the game to be playedogenerate 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.ofor each round of play generate two random numbers,between 1 and n-2(inclusive),one for the row index andonefor the column index usingthefindhighestfunction,find the highest value from one of the 8neighbouring cells adjacent tothe randomly generated row and columnindex accumulate thathighest value asthetotal points for the playerdisplay results (see sample input/output below)oat 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 printBoardfunction should, given the board,print the board/table row-wise(one row at a time) as follows:|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|the findHighestfunction 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:|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|Enter player name: HennyHow many rounds do you wish to play? 4To beat the computer you must get higher than 1756 points.Your selected cell is at row 4 and column 3Your score for this round of the game is 800Your total points up to and including round 1 are 800Your selected cell is at row 5 and column 2Your score for this round of the game is 800Your total points up to and including round 2 are 1600Your selected cell is at row 2 and column 1Your score for this round of the game is 700Your total points up to and including round 3 are 2300 Your selected cell is at row 2 and column 4Your score for this round of the game is 450Your total points up to and including round 4 are 2750Henny, you have accumulated total of 2750 points.Congratulations, you won the game by 994 points.Sample input/output 2:|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|Enter player name: HennyHow many rounds do you wish to play? 3To beat the computer you must get higher than 2352 points.Your selected cell is at row 5 and column 5Your score for this round of the game is 600Your total points up to and including round 1 are 600Your selected cell is at row 5 and column 2Your score for this round of the game is 800Your total points up to and including round 2 are 1400Your selected cell is at row 1 and column 5Your score for this round of the game is 800Your total points up to and including round 3 are 2200Henny, you have accumulated total of 2200 points.Unfortunately, you lost the game by 152 points.Good luck for the next game.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
