Question: (C++ Debugging assistance) The following code supposed to count out all possible( valid and unique ) games of tic-tac-toe, which should be 5478 boards( including

(C++ Debugging assistance)

The following code supposed to count out all possible(valid and unique) games of tic-tac-toe, which should be 5478 boards(including empty boards, and excluding duplicate boards) and the amount of Xwins should be double of the Owins since it goes first. However, my program isn't printing the outputs properly(see at the end). What lines should I change in order to fix this problem??? (the code here is pretty much done, and all of the functions/line#s should be in order)

The function that prints the X's, O's, and space...

(C++ Debugging assistance) The following code supposed to count out all possible(valid

The function that checks winning condition for X's and O's...

and unique) games of tic-tac-toe, which should be 5478 boards(including empty boards,

and excluding duplicate boards) and the amount of Xwins should be doubleof the Owins since it goes first. However, my program isn't printing

the outputs properly(see at the end). What lines should I change in

The function that checks if a board is a tie...

order to fix this problem??? (the code here is pretty much done,

The function that checks for board validity...

and all of the functions/line#s should be in order) The function that

The function that prints all boards...

prints the X's, O's, and space... The function that checks winning condition

The int.main()...

for X's and O's... The function that checks if a board is

Output: "Owins: 0, Xwins: 0, Ties: 0"(which isn't reading my program properly)

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include #include #include using namespace std; //global variables bool wx, wo; //Generates X's and O's accordingly string ConvertPermutationToString(int permutation){string board = int counter = 0; while (permutation>0){ switch (permutation %3 ) { case 0: //do nothing break; case 1: board [counter] = '0'; break; case 2: board [counter] = 'X'; break; } counter++; permutation = permutation/3; } return board; 20 21 22 23 24 25 26 27 28 29 30 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 //checks winning conditions for X's and O's bool win(string xo, char & winner){ bool win = false; if(x0[0]==x0[3] && Xo [3] == x0[6]){ if(xo[0]=='X'){ win = true; winner = 'X'; wx = true; } if(xo [0]=='0'){ win = true; winner = '0'; wo = true; } } if(x0[1]==x0[4] && Xo [4] == x0[7]){ if(xo[1] == 'X'){ win = true; winner = 'X'; wx = true; } if(xo[1] =='0'){ win = true; winner = '0'; Wo = true; } } if(xo [2] ==x0[5] && Xo [5] == xo[8]){ if(xo [2] == 'X'){ win = true; 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 winner = 'X'; wx = true; } if(xo [2]=='0'){ win = true; winner = '0'; Wo = true; } } if(xo [0] ==x0[1] && xo[1] == xo[2]){ if(xo[0] ==''){ win = true; winner = 'X'; wx = true; } if(xo[O]=='0'){ win = true; winner = '0'; WO = true; } } if(x0[3 ] ==x0[4] && xo[4] == xo[5]){ if(xo [3] ==''){ win = true; winner = 'X'; wx = true; } if(x0 [3]=='0'){ win = true; winner = '0'; WO = true: 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 ! 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 } } if(x0 [6] ==xo [7] && Xo [7] xo[8]){ if(x0 [6] ==''){ win = true; winner = 'X'; wx = true; } if(xo[6] == '0'){ win = true; winner = '0'; wo = true; } } if(xo[0] ==x0[4] && Xo [4] == xo[8]){ if(xo [0] =='X'){ win = true; winner = 'X'; wx = true; } if(x0[0] =='0'){ win = true; winner = '0'; Wo = true; } } if(xo [2] ==x0[4] && xo[4] == xo[6]){ if(x0[2] ==''){ win = true; winner = 'X'; 108 109 110 111 112 113 114 115 116 117 118 IRID_D 119 120 121 122 == x0[6]){ 118 119 120 121 122 . 123 124 125 126 127 128 129 } if(xo [ 2 ] ==x0[4] && Xo [4] if(x0[2] =='X'){ win = true; winner 'X'; wx = true; } if(x0[2] =='0'){ win = true; winner = '0'; wo =true; } } return win; 130 131 132 } 134 135 136 137 138 139 140 141 142 143 //checks if a board is a tie bool is_tie(string xo, char&tie){ bool draw = true; char vi //for all nine spaces... for(int i = 0; i num0+1) { valid = false; } /ot valid if BOTH sides wins on a single board if(wx && wo) { valid = false; } return valid; } 167 168 169 170 171 172 173 174 176 177 178 179 180 181 182 //print all possible boards vector get_all_boards() { string board; vector allBoards; char winner = '; //doing this 319 times int Xwin = 0, Owin = 0, tie = 0; for(int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!