Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Do not import ary madules other than math and check. Do not use Python constructs from later modules (e.g. laops). Da not use any other

image text in transcribed

Do not import ary madules other than math and check. Do not use Python constructs from later modules (e.g. laops). Da not use any other Pithon functions not discussed in class or expicity allowed elsewhere. See the allowable funczions post on Plazza. Yau are always allowed ta define your own helper functions, as long as they meet the assignment restrictions a o 4. Playing fnot scoring) a card game caled Take5 for 6 Nimmt): The "board" in the game Take5 consists of 4 rows of cards. Each row is in increasing order and contains Consider the following new data definitions: A card is a Nat between 1 and 104, inclusive ## A Row is a {listof Card) containing between 1 and 5 ## values, in strictly increasing order. between 1 and 5 cards. An example is shown to the left. Players take turn placing new cards on the board, one at a time. New cards can only be placed at the rightmost end of a row. In the process of placing cards, a player may need to remove all the cards in a row, and will be assigned points based on the values in that row. The goal of the game is to have the lowest score after all rounds have been played. (Points are actually based on the number of "bull horns" shown on the collected cards, but we will ignore that component of the game.) A Board is a (listof Row) of length 4 ## No card appears more than once in a Board To determine where a card is to be placed, you need to examine the So, for example, the Take 5 board in our image is represented as in my_board: my board[67,70, [9,18,19], [81, [13,30,50, 88,93] rightmost card in each row (70,19,8,93 in the board on the left). A card cannot be placed next to a bigger card, and must be placed next to the card its value is closest to. For example, 17 must be placed in the third row, next to 8; 22 must be placed in the second row, next to 19; 89 must be placed in the first row, next to 70, Write a Python function turn_take5, that consumes :, of type Board, and c, of type Cari, where c is different from each of the cards already in b, and mutates bto reflect the playing of c(as described previously). In additian, the function returns the list of cards taken off the board during the turn: There are three possibilitles when placing a new card: 1. The card can be placed, using the described guidelines, in a row with fewer than 5 cards. It becomes 2. If the row already has 5 cards, the new card cannot be added. Instead, the new card must actually the new rightmost card in that row if c is played on b without the player removing any cards [as in possibility 1) then returnied; if c should be played on a row which already contains five cards (as in possibility 2), then a row containing only c replaces that row, and the function returns the contents of the replaced row . is replace the entire row, and the player takes all the cards in that row. Consider, for example, placing 99. Based on the numbers, it must go in the fourth row. However, since that row already has 5 cards, the player will remove the cards there (13,30,50,88,93) and then 99 will become the only card in the fourth row If the new card is smaller than all the rightmost cards, then the player must remove a row. For simplicity, we will assume that the player must choose the row which has the minimum value in its rightmost position, and then the new card will become the only card in that row. (in the real game, the ployer can choose ony row, but usually chooses the one with the fewest "bull horns" but we will use o simpler rule.) For example, suppose we are trying to place 6. It is smaller than all the rightmost cards, so the player must take the third row (containing 8), since 8 is the smallest rightmost value, and then 6 becomes the only card in that row . if c is smaller than the rightmost card in each row of b (as in possibility 3), then a row containing only creplaces the row with the smallest rightmost card, and the function returns the contents of the replaced row. 3. For example, consider the following sequence of calls (in which the value of my boari is updated by each successive call, as indicated. turntakes board, 17) -> [],and mutates myboard to . my - - - r:67, 701, 19, 18, 19), ta, 17], [13, 30, 50, Ba, [(67, 70], [9, 1e, 19, 22], [8, 17], [13, 30, 50, to LL, 701, 19, 18, 19, 22], 18, 1- 9911 6, 701, 19, 119, 221, 5], 1991 9311 turn takes my board, 22)> and mutates my board to 8, 93]] turntakes my board, 9S) -> 13, 30, 5, 8, 931.and mutates my board turn take5 my hoard, 5>-> [, 17 and mutates myboard to Do not import ary madules other than math and check. Do not use Python constructs from later modules (e.g. laops). Da not use any other Pithon functions not discussed in class or expicity allowed elsewhere. See the allowable funczions post on Plazza. Yau are always allowed ta define your own helper functions, as long as they meet the assignment restrictions a o 4. Playing fnot scoring) a card game caled Take5 for 6 Nimmt): The "board" in the game Take5 consists of 4 rows of cards. Each row is in increasing order and contains Consider the following new data definitions: A card is a Nat between 1 and 104, inclusive ## A Row is a {listof Card) containing between 1 and 5 ## values, in strictly increasing order. between 1 and 5 cards. An example is shown to the left. Players take turn placing new cards on the board, one at a time. New cards can only be placed at the rightmost end of a row. In the process of placing cards, a player may need to remove all the cards in a row, and will be assigned points based on the values in that row. The goal of the game is to have the lowest score after all rounds have been played. (Points are actually based on the number of "bull horns" shown on the collected cards, but we will ignore that component of the game.) A Board is a (listof Row) of length 4 ## No card appears more than once in a Board To determine where a card is to be placed, you need to examine the So, for example, the Take 5 board in our image is represented as in my_board: my board[67,70, [9,18,19], [81, [13,30,50, 88,93] rightmost card in each row (70,19,8,93 in the board on the left). A card cannot be placed next to a bigger card, and must be placed next to the card its value is closest to. For example, 17 must be placed in the third row, next to 8; 22 must be placed in the second row, next to 19; 89 must be placed in the first row, next to 70, Write a Python function turn_take5, that consumes :, of type Board, and c, of type Cari, where c is different from each of the cards already in b, and mutates bto reflect the playing of c(as described previously). In additian, the function returns the list of cards taken off the board during the turn: There are three possibilitles when placing a new card: 1. The card can be placed, using the described guidelines, in a row with fewer than 5 cards. It becomes 2. If the row already has 5 cards, the new card cannot be added. Instead, the new card must actually the new rightmost card in that row if c is played on b without the player removing any cards [as in possibility 1) then returnied; if c should be played on a row which already contains five cards (as in possibility 2), then a row containing only c replaces that row, and the function returns the contents of the replaced row . is replace the entire row, and the player takes all the cards in that row. Consider, for example, placing 99. Based on the numbers, it must go in the fourth row. However, since that row already has 5 cards, the player will remove the cards there (13,30,50,88,93) and then 99 will become the only card in the fourth row If the new card is smaller than all the rightmost cards, then the player must remove a row. For simplicity, we will assume that the player must choose the row which has the minimum value in its rightmost position, and then the new card will become the only card in that row. (in the real game, the ployer can choose ony row, but usually chooses the one with the fewest "bull horns" but we will use o simpler rule.) For example, suppose we are trying to place 6. It is smaller than all the rightmost cards, so the player must take the third row (containing 8), since 8 is the smallest rightmost value, and then 6 becomes the only card in that row . if c is smaller than the rightmost card in each row of b (as in possibility 3), then a row containing only creplaces the row with the smallest rightmost card, and the function returns the contents of the replaced row. 3. For example, consider the following sequence of calls (in which the value of my boari is updated by each successive call, as indicated. turntakes board, 17) -> [],and mutates myboard to . my - - - r:67, 701, 19, 18, 19), ta, 17], [13, 30, 50, Ba, [(67, 70], [9, 1e, 19, 22], [8, 17], [13, 30, 50, to LL, 701, 19, 18, 19, 22], 18, 1- 9911 6, 701, 19, 119, 221, 5], 1991 9311 turn takes my board, 22)> and mutates my board to 8, 93]] turntakes my board, 9S) -> 13, 30, 5, 8, 931.and mutates my board turn take5 my hoard, 5>-> [, 17 and mutates myboard to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students explore these related Databases questions