Asad Abbas wrote: > Hi All, > i was making "tictac toe" a famous game. > > i made it but the following portion of the prog although it works but it does > not seems good to me. > i wonder if i can do it with some loops or something else... > > // checking if any player has entered a winning combination > // this code cheks all 8 winning combinations! > //but i wud like to know if i can do it with some alternative way > //2D array name "tictac[][]" > > > if (tictac[0][0]==tictac[0][1] && tictac[0][1]==tictac[0][2]) > flag=tictac[0][0]; > else if (tictac[1][0]==tictac[1][1] && tictac[1][1]==tictac[1][2]) > flag=tictac[1][0]; > else if (tictac[2][0]==tictac[2][1] && tictac[2][1]==tictac[2][2]) > flag=tictac[2][0]; > else if (tictac[0][0]==tictac[1][0] && tictac[1][0]==tictac[2][0]) > flag=tictac[0][0]; > else if (tictac[0][1]==tictac[1][1] && tictac[1][1]==tictac[2][1]) > flag=tictac[0][1]; > else if (tictac[0][2]==tictac[1][2] && tictac[1][2]==tictac[2][2]) > flag=tictac[0][0]; > else if (tictac[0][0]==tictac[1][1] && tictac[1][1]==tictac[2][2]) > flag=tictac[0][0]; > else if(tictac[2][0]==tictac[1][1] && tictac[1][1]==tictac[0][2]) > flag=tictac[2][0];
Well, Tic Tac Toe is a simple enough game that a series of if-statements is a generally acceptable solution. If you plan on expanding the game later to support NxN boards, then you would want to consider for-loops, etc. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
