Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Description Player 1: Decides on integer x > 0

Similar presentations


Presentation on theme: "Game Description Player 1: Decides on integer x > 0"— Presentation transcript:

1 Game Description Player 1: Decides on integer x > 0
Player 2 : Has to find a number yn so that yn  x Rules: Player 2: y1< y2< …< yn y1< y2< …< yn-1 < x and yn  x On a guess yj, player 1 either says: smaller than x, please provide a next guess larger or equal x, and reveals x stopping the game

2 Optimization Criteria
Let the guesses be y1, y2, ….yn, so that yn  x yj < x for all j  n – 1 The optimization criteria is the performance ratio:

3 Programming Examples 1. Write a C program that randomly generates the number to guess and ask user to provide the guesses. The program will calculate and print the performance ratio for one game 2. Write a C program that randomly generates the number to guess and ask user to provide the guesses. The program will calculate and print the performance ratio for 10 games and also calculates the average of performance ratios for 10 games. 3. Modification of example 2: let user decide on amount of games that user would like to play and output the average performance ratio over all games.

4 EXAMPLE 76 Performance Ratio 118 / 37 = 3.189189 1 3 10 28
Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess 1 Smaller than x, next guess 3 Smaller than x, next guess 10 Smaller than x, next guess 28 STOP! x = 37 76 Performance Ratio 118 / 37 =

5 EXAMPLE 23 Performance Ratio (1+2+3+4+23) / 5 = 6.6 1 2 3 4
Player 1 Player 2 x is chosen, please provide a guess Smaller than x, next guess 1 Smaller than x, next guess 2 Smaller than x, next guess 3 Smaller than x, next guess 4 STOP! x = 5 23 Performance Ratio ( ) / 5 = 6.6

6 The Powers of 2 Strategy for the Second Player
It turns out that the simple strategy that selects powers of 2: y0 = 1, y1 = 2, y2 = 4, … yi = 2i … is an optimal deterministic strategy for this game The worst case for the strategy is when the number selected by the first player is x = 2j + 1 In this case the game is played until the second player suggests 2j+1

7 EXAMPLE x = 13 x = 65 guesses: 1, 2, 4, 8, 16 sum: 1+2+4+8+16 = 31
performance ratio is x = 65 guesses: 1, 2, 4, 8, 16, 32, 64, 128 sum: = 255 performance ratio is 3.923

8 A Randomized Strategy The following simple randomized strategy gives an improved expected value Let  R [0, 1) – randomly and uniformly chosen from interval [0, 1) Define yj = exp( j +  ) Let i be so that exp( i  ) < x  exp( i +  ) The expected performance ratio is:

9 EXAMPLE Performance Ratio 129 / 48 = 2.6875  = 0.419 STOP! x = 48
Player 1 Player 2 x is chosen, please provide a guess  = 0.419 Smaller than x, next guess exp() = 1 Smaller than x, next guess exp(+1) = 4 Smaller than x, next guess exp(+2) = 11 Smaller than x, next guess exp(+3) =30 STOP! x = 48 exp(+4) = 83 Performance Ratio 129 / 48 =

10 EXAMPLE Performance Ratio 201 / 63 = 3.190476  = 0.866 STOP! x = 63
Player 1 Player 2 x is chosen, please provide a guess  = 0.866 Smaller than x, next guess exp() = 2 Smaller than x, next guess exp(+1) = 6 Smaller than x, next guess exp(+2) = 17 Smaller than x, next guess exp(+3) =47 STOP! x = 63 exp(+4) = 129 Performance Ratio 201 / 63 =

11 Smaller than x, next guess Smaller than x, next guess
EXAMPLE Player 1 Player 2 x is chosen, please provide a guess  = 0.195 Smaller than x, next guess exp() = 1 Smaller than x, next guess exp(+1) = 3 STOP! x = 6 exp(+2) = 8 Performance Ratio 12 / 6 =

12 Discussion Questions Discussion of the Optimization Criteria selection: Why not to choose yi/x, where yi  x? Answer: simple strategy 1, 2, 3, …is optimal Discussion of possible strategies: Why not to start with some “large” number? Why do we not benefit from increasing the next guess only a little compared to the previous guess? What is the disadvantage of making the next guess, say, 100 times larger than previous guess?


Download ppt "Game Description Player 1: Decides on integer x > 0"

Similar presentations


Ads by Google