Question: COP 2362 AI TIC TAC TOE GAME Dr. Webster's COP 2362 Artificial Intelligence Tic Tac Toe Game Tie game Startingplayers TumPlayer is O Game

COP 2362 AI TIC TAC TOE GAME Dr. Webster's COP 2362 Artificial  
Intelligence Tic Tac Toe Game Tie game Startingplayers TumPlayer is O GameOver Al Tumed: ON oox X FSW AI 1 2 3 usingSystem.IO; 4 using System.Windows. Forms; 5 6 Enamespace Greenville RevenueGUI |{ 78 9 8 y161123 u5 167892812234 25 26 27 28 29 30313233343536373839546 47 10 14 15 20 using System; using System.Drawing; 44 4references public partial class Form1 : Form { Boolean GameOver= false; Stringfilenameback = ""; Image tictactoebackground = null; String filenameX0 = ""; ImagetictactoeX = null; Image tictactoe0 = null; Image tictactoeblurbackground = null; constint SIZE = 9; const int ROW_SIZE = 3; const int COL_SIZE= 3; char [] gameGrid = new char[ROW_SIZE, COL_SIZE]; Boolean players Turn= true; Boolean isDone= false; PlayerWon= true; Boolean 1 reference public {Form1() InitializeComponent(); this.Size = new Size (800, 600); //keep this size windowthis. Set DesktopLocation (0, 0); filenameback = Directory.GetCurrent Directory() +"\\cards\\wwwtictactoe.png"; tictactoebackground= Image.FromFile (filenameback); filenameX0 = Directory.GetCurrent Directory() +"\\cards\\tictactoex.png"; tictactoeX = Image.FromFile(filenameX0); filenameXO =

COP 2362 AI TIC TAC TOE GAME Dr. Webster's COP 2362 Artificial Intelligence Tic Tac Toe Game Tie game Startingplayers TumPlayer is O Game Over Al Tumed: ON oox X FSW AI 1 2 3 using System.IO; 4 using System.Windows. Forms; 5 6 Enamespace Greenville RevenueGUI |{ 7 8 9 8 y161123 u5 167892812234 25 26 27 28 29 303132333435363738395 46 47 10 14 15 20 using System; using System.Drawing; 44 4 references public partial class Form1 : Form { Boolean GameOver= false; String filenameback = ""; Image tictactoebackground = null; String filenameX0 = ""; Image tictactoeX = null; Image tictactoe0 = null; Image tictactoeblurbackground = null; const int SIZE = 9; const int ROW_SIZE = 3; const int COL_SIZE = 3; char [] gameGrid = new char[ROW_SIZE, COL_SIZE]; Boolean players Turn = true; Boolean isDone= false; PlayerWon= true; Boolean 1 reference public { Form1() InitializeComponent(); this.Size = new Size (800, 600); //keep this size window this. Set DesktopLocation (0, 0); filenameback = Directory.GetCurrent Directory() +"\\cards\\wwwtictactoe.png"; tictactoebackground= Image. FromFile (filenameback); filenameX0 = Directory.GetCurrent Directory() +"\\cards\\tictactoex.png"; tictactoeX = Image.FromFile(filenameX0); filenameXO = Directory.GetCurrent Directory() +"\\cards\\tictactoe0.png"; tictactoe0 = Image.FromFile(filenamex0); filenamex0 = Directory.GetCurrent Directory() + "\\cards\\tictactoeopenblur.png"; tictactoeblurbackground = Image. FromFile(filenameXO); BigPurpleBucsButton(); 48 A 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 78 79 80 81 82 83 84 85 86 87 88 89 90 8 8 8 8 1 reference private void Button1_Click(object sender, EventArgs e) { } 2 references private void BigPurpleBucsButton () { } //- BigPurpleBucsButton(); ||-- } isDone = false; //assume this to start PlayerWon = true; //assume this too InitGameGrid(); InitGameGraphics(); TIC TAC TOE CODE 1 reference public Boolean CheckForWinnerRows Cols Diagonals() { isDone = false; //assume this to start PlayerWon = true; //assume this too for (int x = 0; x < 3; ++x) { //-- // CHECKS ALL 3 ROWS //-- if (!gameGrid [x, 0].Equals('N')) { } if (gameGrid [x, 0] == gameGrid[x, 1] && gameGrid[x, 0] == gameGrid [x, 2]) { isDone= true; if (gameGrid[x, 0].Equals(0)) { PlayerWon= false; } return isDone; return isDone; 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 8 -0 8 -0- 8 0- 1 reference public void CheckForWinner() { isDone = CheckForWinnerRows ColsDiagonals(); if (isDone) { if (PlayerWon) { ! MessageBox. Show("GAME OVER Player X WON"); } else { MessageBox.Show("GAME OVER Player O WON"); 113 114 115 116 8 117 118 8 119 120 8 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 9 references public void RWWcheckbutton Click(int row, int col) { String msg = ""; if (!isDone) { if (gameGrid[row, col]. Equals('N')) { if (playersTurn) { setplayers Turn(false); SetGridGraphics Tox(row, col); } else { setplayers Turn(true); SetGridGraphicsToO (row, col); } msg = "". Msglabel.Text = msg; Msglabel. Refresh(); } else { //you need to write this!!! CheckForWinner(); msg = "That position is already taken "; Msglabel.Text = msg; Msglabel. Refresh(); 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 8 E -0- 185 8 186 187 188 189 190 191 private void { button4_Click_1(object sender, EventArgs e) int row 0; int col = 0; RWWcheckbuttonclick(row, col); } 1 reference private void button2_Click(object sender, EventArgs e) { int row = 0; int col = 1; RWwcheckbuttonClick(row, col); } 1 reference private void button3_Click(object sender, EventArgs e) { } int row = 0; int col = 2; RWWcheckbuttonClick(row, col); 1 reference private void button14_Click(object sender, EventArgs e) { int row = 1; int col = 0; RWWcheckbuttonClick(row, col); } 1 reference private void button8_Click_1(object sender, EventArgs e) { int row = 1; int col = 1; RWWcheckbuttonClick(row, col); } 1 reference private void button7_Click_1(object sender, EventArgs e) { int row = 1; int col = 2; RWWcheckbuttonClick(row, col); 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 -0 1 reference private void button5_Click_1(object sender, EventArgs e) { } int row = 2; int col = 0; RWWcheckbuttonClick(row, col); 1 reference private void button6_Click_1(object sender, EventArgs e) { } int row = 2; int col = 1; RWWcheckbuttonClick(row, col); 1 reference private void button9_Click_1(object sender, EventArgs e) { int row = 2; int col = 2; RWWcheckbuttonClick(row, col); 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 8 8 8 //- // HELPER CODE HERE _//-- //--- // THIS RESETS ALL GRID CHARS TO START A NEW GAME ||- 1 reference public void InitGameGrid() { for (int row = 0; row < ROW_SIZE; row++) { for (int col = 0; col < COL_SIZE; col++) { gameGrid [row, col] = 'N'; //- // THIS IS ALL METHODS FOR GRAPHICS ||--- 1 reference public void InitGameGraphics() { for (int row = 0; row < ROW_SIZE; row++) { for (int col = 0; col < COL_SIZE; col++) { ResetGridGraphics (row, col); 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 8 2 references private void setplayersTurn (Boolean setplayerturn) { if (setplayerturn) { playersTurn = true; Players Turnlabel.Text = "Player's Turn is: " + Players Turnlabel. Refresh(); } else { players Turn = false; Players Turnlabel. Text = "Opponent's Turn is: " + '0'; Players Turnlabel. Refresh(); 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 // THIS SETS ANY SPOT TO X WHEN THE USER CLICKS THE BUTTON // 1 reference private void SetGridGraphicsToX(int row, int col) Addxoro (row, col, 'X');// this sets the data structure in gameGrid [] switch (row) //row is 0 case 0: switch (col) { case 0: row@colebutton. Background Image = tictactoex; row@colebutton. Refresh(); case 1: break; //row is 1 case 1: break; row@collbutton. Background Image = tictactoex; row@collbutton. Refresh(); case 2: row col2button. Background Image = tictactoex; row@col2button. Refresh(); break; break; //row is 2 break; switch (col) case 0: rowl colebutton. BackgroundImage = tictactoex; rowlcolebutton. Refresh(); break; case 1: rowlcollbutton. BackgroundImage = tictactoex; rowlcollbutton. Refresh(); break; case 2: rowl col2button. Background Image = tictactoeX; rowlcol2button. Refresh(); break; 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 -0-00- 8 case 2: switch (col) { case 0: row2colobutton. Background Image = tictactoex; row2colebutton. Refresh(); break; case 1: break; row2collbutton. Background Image = tictactoex; row2collbutton. Refresh(); break; case 2: row2col2button. Background Image = tictactoex; row2col2button. Refresh(); break; 335 336 337 338 339 340 341 342 343 344 345 346 347 348 358 359 360 361 362 363 364 365 366 349 350 351 352 353 354 355 356 357 |-| 367 368 369 370 371 372 373 374 375 376 377 378 379 8 380 381 382 8 8 1-I 8 8 8 //- // THIS SETS ANY SPOT TO O WHEN THE USER CLICKS THE BUTTON | |-- 1 reference private void SetGridGraphicsToo(int row, int col) { Addxoro (row, col, '0');// this sets the data structure in gameGrid [] switch (row) { //row is 0 case 0: switch (col) { case 0: row@colebutton. Background Image = tictactoe0; row@colebutton. Refresh(); case 1: break; //row is 1 case 1: break; row.collbutton. BackgroundImage = tictactoe0; row@collbutton. Refresh(); case 2: break; } break; //row is 2 row@col2button. BackgroundImage tictactoe0; row col2button. Refresh (); break; switch (col) { case 0: rowlcolebutton. BackgroundImage = tictactoe0; rowlcolebutton. Refresh(); break; case 1: rowlcollbutton. Background Image = tictactoe0; rowlcollbutton. Refresh(); break; case 2: rowlcol2button. Background Image tictactoe0; rowlcol2button. Refresh(); break; 383 384 385 386 387 388 389 390 391 392 393 394 8 395 396 397 398 399 400 0-0- 401 402 102 8 case switch (col) { case 0: row2colobutton. Background Image = tictactoe0; row2colebutton. Refresh(); break; case 1: } break; row2collbutton. Background Image row2collbutton. Refresh(); break; case 2: = tictactoe0; row2col2button. BackgroundImage = tictactoe0; row2col2button. Refresh(); break; 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 8 431 432 8 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 8 -0- -0-0 8 8 -0 8 //- // THIS SETS ALL SPOTS TO BLUR TO RESET THE GAME //- 1 reference private void ResetGridGraphics (int row, int col) { switch (row) { //row is 0 case 0: switch (col) { case 0: row colebutton. Background Image = tictactoeblurbackground; row@colebutton. Refresh(); break; case 1: } break; //row is 1 case 1: row@collbutton. Background Image = tictactoeblurbackground; row collbutton. Refresh (); break; case 2: row col2button. Background Image = tictactoeblurbackground; row.col2button. Refresh(); break; switch (col) { case 0: rowl colebutton. BackgroundImage = tictactoeblurbackground; rowlcolebutton. Refresh(); break; case 1: rowlcollbutton. BackgroundImage = tictactoeblurbackground; rowl collbutton. Refresh(); break; case 2: rowlcol2button. Background Image = tictactoeblurbackground; rowlcol2button. Refresh(); break; } break; //row is 2 448 449 450 451 452 8 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 0-0- 475 476 477 478 479 480 481 482 8 8 8 case 2: 15 2 switch (col) { case 0: row2colebutton. Background Image = tictactoeblurbackground; row2colobutton. Refresh(); } break; break; case 1: row2collbutton. Background Image = tictactoeblurbackground; row2collbutton. Refresh(); break; case 2: row2col2button. Background Image = tictactoeblurbackground; row2col2button. Refresh(); break; 2 references public void AddXoro(int row, int col, char isxoro) { gameGrid [row, col] = isXor0; // this sets the data grid for X O or N 1 reference private void labell_Click(object sender, EventArgs e) {

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 Algorithms Questions!