Thursday, May 15, 2008
You have $100. You want to bet on a best-of-seven game series between two teams (Team A and Team B). Your objective is to double the money if your team (Team A) wins and lose all the money if the other team (Team B) wins. All bets in this game are “double or nothing” bets – i.e. if you bet $x on a game you get $2x if your team wins or you lose $x if your team loses. What will be your strategy and how much would you bet at each game.
Additionally, if Team A had a 2 is to 1 chance of winning, how should the strategy be changed to achieve the same goal.
Solution Summary
We will come up with possible paths in the game and define states at each node. State in this game is defined by two parameters - – X (how many games does Team A need to win) and Y (how many games does Team B need to win) – for example in the beginning of the series each team needs 4 games to win – and if Team A wins the first game, then the state is defined as (3,4) – meaning that Team A needs 3 games to win and Team B needs 4 games to win. We know that we need to bet all $100 for state (1,1) – i.e. when each team has won 3 games and this is the final deciding game. We need to make sure that when we get to this node (1,1) we must have $100 – now if we step back one node – if Team A has won 3 games and Team B has won 2 games – we need to make sure that we will still have $100 if Team B wins this game so we need to keep $100 back and bet some amount such that if Team A wins the game we will have $200 – it’s easy to see that we must bet $50 at this state – so the two numbers for the state (3,2) are $100 (to keep) and $50 (to bet).
Output from the Java Program is below:
C:\strategy>java GameStrategy 4 4 200
Parameters:
Number of games Team A needs to win the series=4
Number of games Team B needs to win the series=4
Amount of money we need to make if Team A wins the series=200.0
-----------State(4,4)---------------------------
AneedsToWin=4
BneedsToWin=4
MoneyToKeep=68.75
MoneyToBet=31.25
-----------State(4,3)---------------------------
AneedsToWin=4
BneedsToWin=3
MoneyToKeep=37.5
MoneyToBet=31.25
-----------State(4,2)---------------------------
AneedsToWin=4
BneedsToWin=2
MoneyToKeep=12.5
MoneyToBet=25.0
-----------State(4,1)---------------------------
AneedsToWin=4
BneedsToWin=1
MoneyToKeep=0.0
MoneyToBet=12.5
-----------State(3,4)---------------------------
AneedsToWin=3
BneedsToWin=4
MoneyToKeep=100.0
MoneyToBet=31.25
-----------State(3,3)---------------------------
AneedsToWin=3
BneedsToWin=3
MoneyToKeep=62.5
MoneyToBet=37.5
-----------State(3,2)---------------------------
AneedsToWin=3
BneedsToWin=2
MoneyToKeep=25.0
MoneyToBet=37.5
-----------State(3,1)---------------------------
AneedsToWin=3
BneedsToWin=1
MoneyToKeep=0.0
MoneyToBet=25.0
-----------State(2,4)---------------------------
AneedsToWin=2
BneedsToWin=4
MoneyToKeep=137.5
MoneyToBet=25.0
-----------State(2,3)---------------------------
AneedsToWin=2
BneedsToWin=3
MoneyToKeep=100.0
MoneyToBet=37.5
-----------State(2,2)---------------------------
AneedsToWin=2
BneedsToWin=2
MoneyToKeep=50.0
MoneyToBet=50.0
-----------State(2,1)---------------------------
AneedsToWin=2
BneedsToWin=1
MoneyToKeep=0.0
MoneyToBet=50.0
-----------State(1,4)---------------------------
AneedsToWin=1
BneedsToWin=4
MoneyToKeep=175.0
MoneyToBet=12.5
-----------State(1,3)---------------------------
AneedsToWin=1
BneedsToWin=3
MoneyToKeep=150.0
MoneyToBet=25.0
-----------State(1,2)---------------------------
AneedsToWin=1
BneedsToWin=2
MoneyToKeep=100.0
MoneyToBet=50.0
-----------State(1,1)---------------------------
AneedsToWin=1
BneedsToWin=1
MoneyToKeep=0.0
MoneyToBet=100.0
Attached java program uses this strategy to come up with amounts to keep and bet at each state in the game:
/*
* File: GameStrategy.java
*
* Created: November 19, 2007
*
*/
/*
* Class to determine strategy for a best-of series
*
* Given a goal to double our money or lose everhything in a best-of series,
* This program provides a strategy for each state in the game. states are
* defined by the number of times each team needs to win. For example in the
* beginning of a best-of-seven series A needs to win 4 games and B needs to
* win 4 games - so this state is defined as (4,4) - if our objective is to
* double our money from $100 to $200 or lose everhhing then we can provide
* 3 arguments to this program - 4 4 200 - to calculate and print a strategy
* for the entire series - then depending on how the game proceeds we can decide
* how much to keep and how much to bet at each state.
*
* @author Anil Gurnani
*/
public class GameStrategy {
public static void main(String args[]) {
GameStrategy strategy = new GameStrategy();
if( args.length < 3 ) {
strategy.printUsage();
System.exit(1);
}
int awins = 0;
int bwins = 0;
double jackpot = 0;
try {
awins = Integer.parseInt(args[0]);
bwins = Integer.parseInt(args[1]);
jackpot = Double.parseDouble(args[2]);
} catch ( Exception ex ) {
ex.printStackTrace();
strategy.printUsage();
System.exit(1);
}
strategy.play(awins, bwins, jackpot);
}
/**
* Method to print Usage.
*/
public void printUsage() {
System.out.println("GameStrategy
}
/**
* Method to iterate over all states in the series.
*/
public void play(int AneedsToWin, int BneedsToWin, double needToMake) {
//
System.out.println("Parameters:");
System.out.println("Number of games Team A needs to win the series="+AneedsToWin);
System.out.println("Number of games Team B needs to win the series="+BneedsToWin);
System.out.println("Amount of money we need to make if Team A wins the series="+needToMake);
for( int i = AneedsToWin; i>0; i-- ) {
for( int j = BneedsToWin; j>0; j-- ) {
if( i == 0 && j == 0 )
return;
else {
double needtokeep = needtokeepat(i, j, needToMake);
double needtobet = needtobetat(i,j,needToMake);
System.out.println("-----------State("+i+","+j+")---------------------------");
System.out.println("AneedsToWin="+i);
System.out.println("BneedsToWin="+j);
System.out.println("MoneyToKeep="+needtokeep);
System.out.println("MoneyToBet="+needtobet);
}
}
}
}
/**
* Method to determine how much money to keep aside at each state.
* @param awins number of games A needs to win to win the series
* @param bwins number of games B needs to win to win the series
* @param needtomake totao money to be made if Team A wins the series
* @return money to be kept aside at given state.
*/
public double needtokeepat(int awins, int bwins, double needtomake) {
double retval = 0;
if( awins == 1 && bwins == 1 ) {
// if this is the last game
// we need to bet half of what we need to make
// and we must lose everything if B wins so we must not keep anything
// in hand.
retval = 0;
} else if( awins == 1 && bwins == 2 ) {
// a has one to win
// b has 2 to win
// so let's say we keep $k and bet $b
// then k + 2b must equal what we need to make at the end of the series - i.e. needtomake
// and k must equal what we need when we get to 1,1 in case we lose this one
// (when awins is 1 and bwins is 1)
// so we need to solve for k + 2b = needtomake
// and k = needat (1,1)
// and we know that totalneeded at (1 1) is needtomake/2
double totalneededat11 = needtomake/2;
// now we need to solve for k and b when
// k + 2b = needtomake (so b = (needtomake -k)/2 )
// k = totalneededat11
/* k */ double k = totalneededat11;
/* b */ double b = (needtomake -k)/2;
retval = k;
} else if ( awins == 1 && bwins == 3 ) {
// a has 1 to win
// b has 3 to win
// k + 2b = needtomake
// k = needed at 12
// 2b = needtomake - k
// b = (needtomake - k)/2
/* k */ double k = needtokeepat(1,2,needtomake) + needtobetat(1,2,needtomake);
/* b */ double b = (needtomake -k)/2;
retval = k;
} else if ( awins == 1 && bwins == 4 ) {
// a has 1 to win
// b has 4 to win
// k + 2b = needtomake
// k = needed at 13
// 2b = needtomake - k
// b = (needtomake - k)/2
/* k */ double k = needtokeepat(1,3,needtomake) + needtobetat(1,3,needtomake);
/* b */ double b = (needtomake -k)/2;
retval = k;
} else if( awins == 2 && bwins == 1 ) {
// a has two to win
// b has 1 to win
// since b has only 1 game to win
// we must bet everything because in case b wins this one we must be left with 0
// so k = 0;
// now bet amount must be enough to give us
// enough to bet on the last game if we win this one i.e. needtomake/2
// because if we win this game then we need to
// bet everything to make enough to get needtomake amount
// so b must be equal to (needtomake/2)/2
/* k */ double k = 0;
/* b */ double b = needtomake/4;
retval = k;
} else if( awins == 2 && bwins == 2 ) {
// a has 2 to win
// b has 2 to win
// this is a tough one
// if A wins - we should have the amount needed at (1,2)
// if B wins - we hsould have the amount needed at (2,1)
// let's say we keep k and bet b then
// k = neededat21 because if we lose we must have at least enough for the state at 2,1
// k + 2b = neededat12 - cause if we win we must have enough for the state at 1,2
double neededat21 = needtokeepat(2,1,needtomake) + needtobetat(2,1,needtomake);
double neededat12 = needtokeepat(1,2,needtomake) + needtobetat(1,2,needtomake);
// saubstitute k in the second equation;
// neededat21 + 2b = neededat12
// => 2b = needat12 - needat21
// => b = (needat12 - needat21)/2
/* k */ double k = neededat21;
/* b */ double b = (neededat12 - neededat21)/2;
retval = k;
} else if( awins == 2 && bwins == 3 ) {
// a has 2 to win
// b has 3 to win
// if A wins - we should have the amount needed at (1,3)
// if B wins - we hsould have the amount needed at (2,2)
// let's say we keep k and bet b then
// k = neededat22 because if we lose we must have at least enough for the state at 2,2
// k + 2b = neededat13 - cause if we win we must have enough for the state at 1,3
double neededat22 = needtokeepat(2,2,needtomake) + needtobetat(2,2,needtomake);
double neededat13 = needtokeepat(1,3,needtomake) + needtobetat(1,3,needtomake);
// 2b = neededat13 - k
// b = (neededat13 - k)/2
/* k */ double k = neededat22;
/* b */ double b = (neededat13 - k)/2;
retval = k;
} else if( awins == 2 && bwins == 4 ) {
// a has 2 to win
// b has 4 to win
// if A wins - we should have the amount needed at (1,4)
// if B wins - we hsould have the amount needed at (2,3)
// let's say we keep k and bet b then
// k = neededat23 because if we lose we must have at least enough for the state at 2,3
// k + 2b = neededat14 - cause if we win we must have enough for the state at 1,4
double neededat23 = needtokeepat(2,3,needtomake) + needtobetat(2,3,needtomake);
double neededat14 = needtokeepat(1,4,needtomake) + needtobetat(1,4,needtomake);
// 2b = neededat14 - k
// b = (neededat14 - k)/2
/* k */ double k = neededat23;
/* b */ double b = (neededat14 - k)/2;
retval = k;
} else if( awins == 3 && bwins == 1 ) {
// a has 3 to win
// b has 1 to win
// we must bet everything we have
// cause if b wins - we want to lose everything
// plus we need to bet enough so that if we win we get to state 2,1
// so k = 0
// and k + 2b = needed at 21
double neededat21 = needtokeepat(2,1,needtomake) + needtobetat(2,1,needtomake);
/* k */ double k = 0;
/* b */ double b = neededat21/2;
retval = k;
} else if( awins == 3 && bwins == 2 ) {
// a has 3 to win
// b has 2 to win
// k + 2b = needed at 2,2
// k = needed at 3,1
// 2b = neededat22 - k
// b = (neededat22 - k)/2
double neededat22 = needtokeepat(2,2,needtomake) + needtobetat(2,2,needtomake);
/* k */ double k = needtokeepat(3,1,needtomake) + needtobetat(3,1,needtomake);
/* b */ double b = (neededat22 - k)/2;
retval = k;
} else if( awins == 3 && bwins == 3 ) {
// a has 3 to win
// b has 3 to win
// k + 2b = needed at 2,3
// k = needed at 3,2
// 2b = neededat23 - k
// b = (neededat23-k)/2
double neededat23 = needtokeepat(2,3,needtomake) + needtobetat(2,3,needtomake);
/* k */ double k = needtokeepat(3,2,needtomake) + needtobetat(3,2,needtomake);
/* b */ double b = (neededat23 - k)/2;
retval = k;
} else if( awins == 3 && bwins == 4 ) {
// a has 3 to win
// b has 4 to win
// k + 2b = needed at 2,4
// k = needed at 3,3
// 2b = neededat24 - k
// b = (neededat24-k)/2
double neededat24 = needtokeepat(2,4,needtomake) + needtobetat(2,4,needtomake);
/* k */ double k = needtokeepat(3,3,needtomake) + needtobetat(3,3,needtomake);
/* b */ double b = (neededat24 - k)/2;
retval = k;
} else if( awins == 4 && bwins == 1 ) {
// a has 4 to win
// b has 1 to win
// 2b = needed at 3,1
// k = 0 - because if b wins we must not have anything in our hands
// 2b = neededat31 - k
// b = (neededat31 - k)/2
double neededat31 = needtokeepat(3,1,needtomake) + needtobetat(3,1,needtomake);
/* k */ double k = 0;
/* b */ double b = (neededat31-k)/2;
retval = k;
} else if( awins == 4 && bwins == 2 ) {
// a has 4 to win
// b has 2 to win
// k + 2b = needed at 3,2
// k = needed at 4,1
// 2b = neededat32 - k
// b = (neededat32 - k)/2
double neededat32 = needtokeepat(3,2,needtomake) + needtobetat(3,2,needtomake);
/* k */ double k = needtokeepat(4,1,needtomake) + needtobetat(4,1,needtomake);
/* b */ double b = (neededat32 - k)/2;
retval = k;
} else if( awins == 4 && bwins == 3 ) {
// a has 4 to win
// b has 3 to win
// k + 2b = needed at 3,3
// k = needed at 4,2
// 2b = neededat33 - k
// b = (neededat33 - k)/2
double neededat33 = needtokeepat(3,3,needtomake) + needtobetat(3,3,needtomake);
/* k */ double k = needtokeepat(4,2,needtomake) + needtobetat(4,2,needtomake);
/* b */ double b = (neededat33 - k)/2;
retval = k;
} else if( awins == 4 && bwins == 4 ) {
// a has 4 to win
// b has 4 to win
// k + 2b = needed at 3,4
// k = needed at 4,3
// 2b = neededat34 - k
// b = (neededat34 - k)/2
double neededat34 = needtokeepat(3,4,needtomake) + needtobetat(3,4,needtomake);
/* k */ double k = needtokeepat(4,3,needtomake) + needtobetat(4,3,needtomake);
/* b */ double b = (neededat34 - k)/2;
retval = k;
}
return retval;
}
/**
* Method to determine how much money to keep aside at each state.
* @param awins number of games A needs to win to win the series
* @param bwins number of games B needs to win to win the series
* @param needtomake totao money to be made if Team A wins the series
* @return money to be bet at given state.
*/
public double needtobetat(int awins, int bwins, double needtomake) {
double retval = 0;
if( awins == 1 && bwins == 1 ) {
// if this is the last game
// we need to bet half of what we need to make
// and we must lose everything if B wins so we must not keep anything
// in hand.
retval = needtomake/2;
} else if( awins == 1 && bwins == 2 ) {
// a has one to win
// b has 2 to win
// so let's say we keep $k and bet $b
// then k + 2b must equal what we need to make at the end of the series - i.e. needtomake
// and k must equal what we need when we get to 1,1 in case we lose this one
// (when awins is 1 and bwins is 1)
// so we need to solve for k + 2b = needtomake
// and k = needat (1,1)
// and we know that totalneeded at (1 1) is needtomake/2
double totalneededat11 = needtomake/2;
// now we need to solve for k and b when
// k + 2b = needtomake (so b = (needtomake -k)/2 )
// k = totalneededat11
/* k */ double k = totalneededat11;
/* b */ double b = (needtomake -k)/2;
retval = b;
} else if ( awins == 1 && bwins == 3 ) {
// a has 1 to win
// b has 3 to win
// k + 2b = needtomake
// k = needed at 12
// 2b = needtomake - k
// b = (needtomake - k)/2
/* k */ double k = needtokeepat(1,2,needtomake) + needtobetat(1,2,needtomake);
/* b */ double b = (needtomake -k)/2;
retval = b;
} else if ( awins == 1 && bwins == 4 ) {
// a has 1 to win
// b has 4 to win
// k + 2b = needtomake
// k = needed at 13
// 2b = needtomake - k
// b = (needtomake - k)/2
/* k */ double k = needtokeepat(1,3,needtomake) + needtobetat(1,3,needtomake);
/* b */ double b = (needtomake -k)/2;
retval = b;
} else if( awins == 2 && bwins == 1 ) {
// a has two to win
// b has 1 to win
// since b has only 1 game to win
// we must bet everything because in case b wins this one we must be left with 0
// so k = 0;
// now bet amount must be enough to give us
// enough to bet on the last game if we win this one i.e. needtomake/2
// because if we win this game then we need to
// bet everything to make enough to get needtomake amount
// so b must be equal to (needtomake/2)/2
/* k */ double k = 0;
/* b */ double b = needtomake/4;
retval = b;
} else if( awins == 2 && bwins == 2 ) {
// a has 2 to win
// b has 2 to win
// this is a tough one
// if A wins - we should have the amount needed at (1,2)
// if B wins - we hsould have the amount needed at (2,1)
// let's say we keep k and bet b then
// k = neededat21 because if we lose we must have at least enough for the state at 2,1
// k + 2b = neededat12 - cause if we win we must have enough for the state at 1,2
double neededat21 = needtokeepat(2,1,needtomake) + needtobetat(2,1,needtomake);
double neededat12 = needtokeepat(1,2,needtomake) + needtobetat(1,2,needtomake);
// saubstitute k in the second equation;
// neededat21 + 2b = neededat12
// => 2b = needat12 - needat21
// => b = (needat12 - needat21)/2
/* k */ double k = neededat21;
/* b */ double b = (neededat12 - neededat21)/2;
retval = b;
} else if( awins == 2 && bwins == 3 ) {
// a has 2 to win
// b has 3 to win
// if A wins - we should have the amount needed at (1,3)
// if B wins - we hsould have the amount needed at (2,2)
// let's say we keep k and bet b then
// k = neededat22 because if we lose we must have at least enough for the state at 2,2
// k + 2b = neededat13 - cause if we win we must have enough for the state at 1,3
double neededat22 = needtokeepat(2,2,needtomake) + needtobetat(2,2,needtomake);
double neededat13 = needtokeepat(1,3,needtomake) + needtobetat(1,3,needtomake);
// 2b = neededat13 - k
// b = (neededat13 - k)/2
/* k */ double k = neededat22;
/* b */ double b = (neededat13 - k)/2;
retval = b;
} else if( awins == 2 && bwins == 4 ) {
// a has 2 to win
// b has 4 to win
// if A wins - we should have the amount needed at (1,4)
// if B wins - we hsould have the amount needed at (2,3)
// let's say we keep k and bet b then
// k = neededat23 because if we lose we must have at least enough for the state at 2,3
// k + 2b = neededat14 - cause if we win we must have enough for the state at 1,4
double neededat23 = needtokeepat(2,3,needtomake) + needtobetat(2,3,needtomake);
double neededat14 = needtokeepat(1,4,needtomake) + needtobetat(1,4,needtomake);
// 2b = neededat14 - k
// b = (neededat14 - k)/2
/* k */ double k = neededat23;
/* b */ double b = (neededat14 - k)/2;
retval = b;
} else if( awins == 3 && bwins == 1 ) {
// a has 3 to win
// b has 1 to win
// we must bet everything we have
// cause if b wins - we want to lose everything
// plus we need to bet enough so that if we win we get to state 2,1
// so k = 0
// and k + 2b = needed at 21
double neededat21 = needtokeepat(2,1,needtomake) + needtobetat(2,1,needtomake);
/* k */ double k = 0;
/* b */ double b = neededat21/2;
retval = b;
} else if( awins == 3 && bwins == 2 ) {
// a has 3 to win
// b has 2 to win
// k + 2b = needed at 2,2
// k = needed at 3,1
// 2b = neededat22 - k
// b = (neededat22 - k)/2
double neededat22 = needtokeepat(2,2,needtomake) + needtobetat(2,2,needtomake);
/* k */ double k = needtokeepat(3,1,needtomake) + needtobetat(3,1,needtomake);
/* b */ double b = (neededat22 - k)/2;
retval = b;
} else if( awins == 3 && bwins == 3 ) {
// a has 3 to win
// b has 3 to win
// k + 2b = needed at 2,3
// k = needed at 3,2
// 2b = neededat23 - k
// b = (neededat23-k)/2
double neededat23 = needtokeepat(2,3,needtomake) + needtobetat(2,3,needtomake);
/* k */ double k = needtokeepat(3,2,needtomake) + needtobetat(3,2,needtomake);
/* b */ double b = (neededat23 - k)/2;
retval = b;
} else if( awins == 3 && bwins == 4 ) {
// a has 3 to win
// b has 4 to win
// k + 2b = needed at 2,4
// k = needed at 3,3
// 2b = neededat24 - k
// b = (neededat24-k)/2
double neededat24 = needtokeepat(2,4,needtomake) + needtobetat(2,4,needtomake);
/* k */ double k = needtokeepat(3,3,needtomake) + needtobetat(3,3,needtomake);
/* b */ double b = (neededat24 - k)/2;
retval = b;
} else if( awins == 4 && bwins == 1 ) {
// a has 4 to win
// b has 1 to win
// 2b = needed at 3,1
// k = 0 - because if b wins we must not have anything in our hands
// 2b = neededat31 - k
// b = (neededat31 - k)/2
double neededat31 = needtokeepat(3,1,needtomake) + needtobetat(3,1,needtomake);
/* k */ double k = 0;
/* b */ double b = (neededat31-k)/2;
retval = b;
} else if( awins == 4 && bwins == 2 ) {
// a has 4 to win
// b has 2 to win
// k + 2b = needed at 3,2
// k = needed at 4,1
// 2b = neededat32 - k
// b = (neededat32 - k)/2
double neededat32 = needtokeepat(3,2,needtomake) + needtobetat(3,2,needtomake);
/* k */ double k = needtokeepat(4,1,needtomake) + needtobetat(4,1,needtomake);
/* b */ double b = (neededat32 - k)/2;
retval = b;
} else if( awins == 4 && bwins == 3 ) {
// a has 4 to win
// b has 3 to win
// k + 2b = needed at 3,3
// k = needed at 4,2
// 2b = neededat33 - k
// b = (neededat33 - k)/2
double neededat33 = needtokeepat(3,3,needtomake) + needtobetat(3,3,needtomake);
/* k */ double k = needtokeepat(4,2,needtomake) + needtobetat(4,2,needtomake);
/* b */ double b = (neededat33 - k)/2;
retval = b;
} else if( awins == 4 && bwins == 4 ) {
// a has 4 to win
// b has 4 to win
// k + 2b = needed at 3,4
// k = needed at 4,3
// 2b = neededat34 - k
// b = (neededat34 - k)/2
double neededat34 = needtokeepat(3,4,needtomake) + needtobetat(3,4,needtomake);
/* k */ double k = needtokeepat(4,3,needtomake) + needtobetat(4,3,needtomake);
/* b */ double b = (neededat34 - k)/2;
retval = b;
}
return retval;
}
}
How r u and family ?
Its so easy to find you...just typed ur name and u r on the top.
Ill keep update with ur blog and do keep posting interesting stuff.
Regards to you, didi and love to kids.
find me on orkut for family pics.
sachin
<< Home