6
2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/L6-XO-Answer.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson, A207 [email protected] ://www-public.it-sudparis.eu/~gibson/Teaching/MAT70 XO Sample Answer

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

Embed Size (px)

Citation preview

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/L6-XO-Answer.1

MAT 7003 : Mathematical Foundations

(for Software Engineering)

J Paul Gibson, A207

[email protected]

http://www-public.it-sudparis.eu/~gibson/Teaching/MAT7003/

XO Sample Answer

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/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

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/L6-XO-Answer.3

Number of random games = 1000000Number of wins for X (starting)= 585649Number 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 = 362880Number of wins for X (starting)= 212256Number of wins for O (second) = 104544Wins after rounds = 5 : 345606 : 319687 : 959048 : 725769 : 81792

Prob(X wins) = 0.5849Prob(O wins) = 0.2881Prob(draw) = 0,127

NOTE: I did not simplify for symmetry

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/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)

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/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)

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

2012 J Paul Gibson TSP: Mathematical Foundations MAT7003/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.htmHenry Bottomley