# 2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207.

## Presentation on theme: "2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207."— Presentation transcript:

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207 paul.gibson@it-sudparis.eu http://www-public.it-sudparis.eu/~gibson/Teaching/MAT7003/ XO Sample Answer

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.2 TO DO - Probability and statistics for game analysis In a game of noughts and crosses. If 2 players play completely randomly (correctly following the rules of the game, but showing no other intelligence regarding where/how to play at each turn) then : What is the probability that the player who starts wins the game? What is probability that the player who goes second wins the game? What is probability that the game ends in a draw? Calculate the probabilities (+/- 0.1), and test your answer through a computer simulation

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.3 Number of random games = 1000000 Number of wins for X (starting)= 585649 Number of wins for O (second) = 287073 My results by Java simulation of random game 1 million times My results by Java simulation of all possible games: Number of games = 362880 Number of wins for X (starting)= 212256 Number of wins for O (second) = 104544 Wins after rounds = 5 : 34560 6 : 31968 7 : 95904 8 : 72576 9 : 81792 Prob(X wins) = 0.5849 Prob(O wins) = 0.2881 Prob(draw) = 0,127 NOTE: I did not simplify for symmetry

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.4 do{ permutation =gameIterator.next(); XOBoard game = new XOBoard(); gameCount++; gameOver = false; game = new XOBoard(); int playCount =0; do { game.playX(permutation[playCount]+1); playCount++; if (game.checkFull() || game.checkWinX()) gameOver = true; if (!gameOver){ game.playO(permutation[playCount]+1); playCount++; if (game.checkFull() || game.checkWinO()) gameOver = true; } } while (!gameOver); if (game.checkWinX() ) {winXCount++; winCount[playCount]++;} if (game.checkWinO() ) {winOCount++; winCount[playCount]++;} gameOver = false; } while (gameIterator.hasNext() && !gameOver); Test_Complete_Play.java (main algorithm)

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.5 int winXCount =0; int winOCount =0; int NUMBER_GAMES = 1000000; boolean gameOver = false; XOBoard game = new XOBoard(); XORandomPlay rules = new XORandomPlay(); for (int gamecount =0; gamecount< NUMBER_GAMES; gamecount++){ gameOver = false; game = new XOBoard(); do { rules.apply(game, 'X'); if (game.checkFull() || game.checkWinX()) gameOver = true; if (!gameOver){ rules.apply(game, 'O'); if (game.checkFull() || game.checkWinO()) gameOver = true; } } while (!gameOver); if (game.checkWinX() ) winXCount++; if (game.checkWinO() ) winOCount++; } Test_Statistics_RandomPlay.java (main algorithm)

2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.6 Probabilistic Analysis Has Been Published Elsewhere: Scientific American, Mathematical Recreations, Tic-Tac-Toe (January 2002) Steve Schaefer http://www.mathrec.org/old/2002jan/solutions.html How many Tic-Tac-Toe (noughts and crosses) games are possible? http://www.se16.info/hgb/tictactoe.htm Henry Bottomley

Download ppt "2012 J Paul GibsonTSP: Mathematical FoundationsMAT7003/L6-XO-Answer.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207."

Similar presentations