The name of your C program file must be called ttt2.c, files with any other name will not be marked.
This week's lab is based on last week's lab question. If you have not read it, please do so now.
Last week, we allowed two players to play tic-tac-toe. This week, we want to see the outcome of players place their pieces randomly on unoccupied squares. Assume that Player X always moves first. What are the probabilities of player X winning, player O winning, and a draw result?
You may wish to review the material on Command Line Arguments in Lecture 10, as well as the program conversion1.c.
Assuming that the executable is ttt2beta, sample runs of the program are shown below. The sample runs are self-explanatory. Follow the sample output precisely. User input is denoted in bold.
$ gcc -Wall ttt2beta.c -o ttt2beta $ ./ttt2beta Usage: ./ttt2beta seed $ ./ttt2beta 6105 Seed: 6105 Move by player X at (0, 0). X . . . . . . . . Move by player O at (0, 1). X O . . . . . . . Move by player X at (1, 1). X O . . X . . . . Move by player O at (2, 2). X O . . X . . . O Move by player X at (2, 0). X O . . X . X . O Move by player O at (0, 2). X O O . X . X . O Move by player X at (1, 2). X O O . X X X . O Move by player O at (1, 0). X O O O X X X . O Move by player X at (2, 1). X O O O X X X X O Draw result. How boring. $ ./ttt2beta 6106 Seed: 6106 Move by player X at (2, 2). . . . . . . . . X Move by player O at (1, 1). . . . . O . . . X Move by player X at (0, 1). . X . . O . . . X Move by player O at (0, 0). O X . . O . . . X Move by player X at (2, 0). O X . . O . X . X Move by player O at (0, 2). O X O . O . X . X Move by player X at (1, 0). O X O X O . X . X Move by player O at (1, 2). O X O X O O X . X Move by player X at (2, 1). O X O X O O X X X Player X wins! $ ./ttt2beta 6107 Seed: 6107 Move by player X at (0, 0). X . . . . . . . . Move by player O at (2, 0). X . . . . . O . . Move by player X at (1, 0). X . . X . . O . . Move by player O at (0, 2). X . O X . . O . . Move by player X at (0, 1). X X O X . . O . . Move by player O at (1, 1). X X O X O . O . . Player O wins! $
$ gcc -Wall ttt2.c -o ttt2 $ ./ttt2 Usage: ./ttt2 seed number_of_simulations $ ./ttt2 6105 Usage: ./ttt2 seed number_of_simulations $ ./ttt2 6105 1000 Seed: 6105 Number of simulations: 1000, wins by player X: 586 wins by player O: 292, draws: 122 Percentage of wins by player X: 58.600% Percentage of wins by player O: 29.200% Percentage of draws: 12.200% $ ./ttt2 6106 10000 Seed: 6106 Number of simulations: 10000, wins by player X: 5881 wins by player O: 2875, draws: 1244 Percentage of wins by player X: 58.810% Percentage of wins by player O: 28.750% Percentage of draws: 12.440% $ ./ttt2 6107 100000 Seed: 6107 Number of simulations: 100000, wins by player X: 58466 wins by player O: 28817, draws: 12717 Percentage of wins by player X: 58.466% Percentage of wins by player O: 28.817% Percentage of draws: 12.717% $
A total of 13 different hosts have accessed this document in the last 445 days; your host, nsrp-source.comp.nus.edu.sg, has accessed it 7 times.
If you're interested, complete statistics for this document are also available, including breakdowns by top-level domain, host name, and date.