Introduction to "Mathematical Foundations for Software Engineering"

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
2012 J Paul Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.1
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 Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.2
My results by Java simulation of random game 1 million times
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 all possible games:
NOTE: I did
Number of games = 362880
not simplify for
Number of wins for X (starting)= 212256
symmetry
Number of wins for O (second) = 104544
Wins after rounds =
5 : 34560
6 : 31968
Prob(X wins) = 0.5849
7 : 95904
Prob(O wins) = 0.2881
8 : 72576
Prob(draw) = 0,127
9 : 81792
2012 J Paul Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.3
Test_Complete_Play.java (main algorithm)
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);
2012 J Paul Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.4
Test_Statistics_RandomPlay.java (main algorithm)
int winXCount =0;
int winOCount =0;
int NUMBER_GAMES =
boolean gameOver =
XOBoard game = new
XORandomPlay rules
1000000;
false;
XOBoard();
= 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++;
}
2012 J Paul Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.5
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
2012 J Paul Gibson
TSP: Mathematical Foundations
MAT7003/L6-XO-Answer.6