60 likes | 179 Views
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. TO DO - Probability and statistics for game analysis. In a game of noughts and crosses.
E N D
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 SampleAnswer TSP: MathematicalFoundations
TO DO - Probability and statistics for game analysis • In a game of noughts and crosses. • If 2 playersplaycompletelyrandomly (correctlyfollowing the rules of the game, but showing no other intelligence regardingwhere/how to playateachturn) then : • Whatis the probabilitythat the playerwhostartswins the game? • Whatisprobabilitythat the playerwhogoes second wins the game? • Whatisprobabilitythat the gameends in a draw? • Calculate the probabilities (+/- 0.1), and test youranswerthrough a computer simulation TSP: MathematicalFoundations
Myresults by Java simulation of randomgame 1 million times Number of random games = 1000000 Number of wins for X (starting)= 585649 Number of wins for O (second) = 287073 Myresults 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 Winsafter rounds = 5 : 34560 6 : 31968 7 : 95904 8 : 72576 9 : 81792 NOTE: I did not simplify for symmetry Prob(X wins) = 0.5849 Prob(O wins) = 0.2881 Prob(draw) = 0,127 TSP: MathematicalFoundations
Test_Complete_Play.java (main algorithm) do{ permutation =gameIterator.next(); XOBoardgame = newXOBoard(); gameCount++; gameOver = false; game = newXOBoard(); intplayCount =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); TSP: MathematicalFoundations
Test_Statistics_RandomPlay.java (main algorithm) intwinXCount =0; intwinOCount =0; intNUMBER_GAMES = 1000000; booleangameOver = false; XOBoardgame = newXOBoard(); XORandomPlayrules = newXORandomPlay(); for (intgamecount =0; gamecount< NUMBER_GAMES; gamecount++){ gameOver = false; game = newXOBoard(); 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++; } TSP: MathematicalFoundations
ProbabilisticAnalysis Has Been PublishedElsewhere: Scientific American, MathematicalRecreations, 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 TSP: MathematicalFoundations