Urgent help needed with bar puzzle

Nice sketch Rob

I have just stuck some names on the results for disbelievers :slight_smile: :-

//    FILE: simuBarGame.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1
// PURPOSE: simulate ashtray game
//     URL: http://forum.arduino.cc/index.php?topic=182297.0
//
// Released to the public domain
//

unsigned long win1 = 0;
unsigned long win2 = 0;
unsigned long games = 0;
float ratio = 0.0;

void setup()
{
  Serial.begin(115200);
  Serial.println("Start ashtray game");
}

void loop()
{
  games++;
  int pos = random(3);  // position of coin
  int initialChoice = random(3);  // initial choice

  // NOT CHANGING PLAYER
  // straightforward
  if (pos == initialChoice) win1++;

  // CHANGING PLAYER
  // select one that is empty to turn
  int turn = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == pos) continue;
    if (i == initialChoice) continue;
    turn = i;
  }
  // change choice
  int newchoice = 0;
  for (int i = 0; i < 3; i++)
  {
    if (i == turn) continue;
    if (i == initialChoice) continue;
    newchoice = i;
  } 
  if (pos == newchoice) win2++;

  ratio = (1.0 * win1)/win2;

  // DISPLAY
    Serial.print("games played =");
  Serial.print(games);
  Serial.print("\t");
  Serial.print("won by keeping =");
  Serial.print(win1);
  Serial.print("\t");
   Serial.print("won by changing =");
  Serial.print(win2);
  Serial.print("\t");
   Serial.print("ratio =");
  Serial.println(ratio, 4);
}