Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Help with python code Objective of program: LCR (short for left-right center) is a game largely focused around the movement of coins (poker chips, candy,

Help with python code

Objective of program:

LCR (short for left-right center) is a game largely focused around the movement of coins (poker chips, candy, money, whatever) around the players. In each turn the active player rolls dice to determine how to move their coins either keeping them, putting them in the center or passing the left or right. The goal of the game is to be the only player with coins, at which point that player wins the coins they have and all coins in the center. The game is played with special 6-sided dice, three sides are labeled with a dot, representing that a coin can be kept, then one side each is labeled L (left), R (right) and C (center). It is from these dice that the game gets its name. At the beginning of the game, the players sit in a circle, each with three coins. One player is chosen to go first, afterwords play will go in a circle until the game completes. A players turn has three parts. First the player figures out how many dice they must roll. The player rolls as many dice as they have coins capped at a maximum of three dice. So, if a player has three or fewer coins, they roll as many dice as they have coins, but if they have four or more coins, they would only roll three dice. Then the player rolls their dice. For each dice that rolls an L, the player must hand a coin to the player on their left. For each dice that rolls an R, the player must hand a coin to the player on their right. For each dice that rolls a C, the player must put a coin in the center, coins in the center cannot be retrieved until the end of the game. If a dice rolls a dot, the player doesnt have to give up a coin. If a player has no coins they are still in the game, but they roll no dice on their turn and nothing happens. (For our purposes, we will still count that as a turn, even though nothing happens) These players stay in the game because the player to their left or right may still be forced to give them coins. The game ends when only one player has coins. This can happen on anyones turn (so player 1 can be declared a winner at the beginning of player 3s turn if no other player has coins).

Computational problem:

Using these functions below, design a game of LCR. You can use more functions but these below are required.

1) lcr over (coins) this function takes an array of numbers (representing coin counts) and indicates if the game is over (that is, it returns true if only one element is non-zero, and false if more than one element is non-zero)

2) lcr winner(coins) this function takes an array of numbers (representing coin counts). You can assume that this function is only called when there is a winner, that is, this function will only be called if lcr over (coins) returns true. This function should return 4 the index of the player who won the game. That is, this function should return the index of the non-zero element of the coins list.

3) left (coins, player) this function takes two parameters, the coins list, and the index of the current player. It should perform a left on that players coin count, reducing it by one, and increasing the player to the lefts coin count by one. Remember, as players sit in a circle, left of the first player is the last player. This function should return nothing, it should instead directly change the list.

4) right (coins, player) like left, but performing a right shift, so removing one coin from player and giving it to the player to the right. This function should return nothing.

5) center(coins, player) like left and right, but with the coin going to the center As we dont track coins in the center, this just needs to reduce the coin count for player by one.

6) lcr game(num players) this function should simulate, to completion, a game of lcr. It should start with each player having 3 coins, and player 0 going first, and it should continue until only one player has coins per the rules of the game discussed above. This function should return a tuple with two values, the first value in the tuple is the index of the player who won. The second value should be the number of turns it took to win.

7) most common winner(num players) This function should simulate 2000 games with the given number of players. It should count how many times each player wins, and then figure out which player won the most over the 2000 games. This function should return a tuple with two values. The first value is the player who won the most of the simulated 2000 games. The second value is the percent of those games the player won (so win count/2000). This function is the end goal of our program, it will tell us if the game is fair, and if not, how often a given player wins. This function should run relatively quickly (maximum one or two seconds)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions