All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Probability
Tic Tac Toe II (Posted on 2013-12-24) Difficulty: 3 of 5
In a game of tic-tac-toe, X went first followed by O. The situation after two moves was as follows:
   
   |   |
---+---+---
 O | X |
---+---+---
   |   |
Given that both X and O act at random, what is the probability that X wins the game?

No Solution Yet Submitted by K Sengupta    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
verification by simulation Comment 2 of 2 |
(In reply to computer aided solution by Charlie)

The following simulation verifies the probabilities found previously:

DECLARE SUB move (mno#)
DECLARE SUB moveww (mno#)
DECLARE FUNCTION fact# (x#)
DEFDBL A-Z

CLEAR , , 25000

DIM SHARED grid(3, 3), wins(2)
grid(2, 2) = 1: grid(2, 1) = 2

CLS

FOR trial = 1 TO 100000
 move 3
NEXT

FOR i = 0 TO 2
  PRINT wins(i);
  PRINT wins(i) / (wins(1) + wins(2) + wins(0))
NEXT


SUB move (mno)
  player = (mno - 1) MOD 2 + 1
  psn = INT(9 * RND(1) + 1)
  row = (psn - 1) \ 3 + 1
  col = (psn - 1) MOD 3 + 1
  WHILE grid(row, col) > 0
    psn = INT(9 * RND(1) + 1)
    row = (psn - 1) \ 3 + 1
    col = (psn - 1) MOD 3 + 1
  WEND
  grid(row, col) = player

  vhit = 1
  FOR r = 1 TO 3
    IF grid(r, col) <> player THEN vhit = 0: EXIT FOR
  NEXT
  hhit = 1
  FOR c = 1 TO 3
    IF grid(row, c) <> player THEN hhit = 0: EXIT FOR
  NEXT
  d1hit = 1
  FOR r = 1 TO 3
    IF grid(r, r) <> player THEN d1hit = 0: EXIT FOR
  NEXT
  d2hit = 1
  FOR r = 1 TO 3
    IF grid(4 - r, r) <> player THEN d2hit = 0: EXIT FOR
  NEXT
  IF vhit OR hhit OR d1hit OR d2hit THEN
    wins(player) = wins(player) + 1
  ELSE
    IF mno < 9 THEN
      move mno + 1
    ELSE
      wins(0) = wins(0) + 1
    END IF
  END IF

  grid(row, col) = 0
END SUB

The results:

 11447  .11447   draw 
 72884  .72884   win for X
 15669  .15669   win for Y

  Posted by Charlie on 2013-12-24 21:45:24
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information