Advertisement
AvengersAssemble

Comparing-Winner-Systems-Length

Sep 7th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. static int Winner(char[,] board, char userType) //בודק אם יש מנצח
  2.         {
  3.             int winner = 0;
  4.             for (int n = 0; n < board.GetLength(0); n++)
  5.             {
  6.                 for (int h = 0; h < board.GetLength(1); h++)
  7.                 {
  8.                     if (board[h, n] == userType)
  9.                         winner ++;
  10.                     else if (board[n, h] == userType)
  11.                         winner++;
  12.                     else if (board[0, 0] == userType && board[1,1] == userType && board[2,2] == userType)
  13.                         winner=3;
  14.                     else if (board[0, 2] == userType && board[1, 1] == userType && board[2, 0] == userType)
  15.                         winner=3;
  16.                     else
  17.                         winner = 0;
  18.                 }
  19.                 if (winner == 3)
  20.                     break;
  21.                 else
  22.                     winner = 0;
  23.             }
  24.             return winner;
  25.             /*
  26.             if (board[0, 0] == userType && board[1, 0] == userType && board[2, 0] == userType)
  27.                 return 1;
  28.             else if (board[0, 1] == userType && board[1, 1] == userType && board[2, 1] == userType)
  29.                 return 1;
  30.             else if (board[0, 2] == userType && board[1, 2] == userType && board[2, 2] == userType)
  31.                 return 1;
  32.             else if (board[0, 0] == userType && board[1, 1] == userType && board[2, 2] == userType)
  33.                 return 1;
  34.             else if (board[0, 2] == userType && board[1, 1] == userType && board[2, 0] == userType)
  35.                 return 1;
  36.             else if (board[0, 0] == userType && board[0, 1] == userType && board[0, 2] == userType)
  37.                 return 1;
  38.             else if (board[1, 0] == userType && board[1, 1] == userType && board[1, 2] == userType)
  39.                 return 1;
  40.             else if (board[2, 0] == userType && board[2, 1] == userType && board[2, 2] == userType)
  41.                 return 1;
  42.             else
  43.                 return 0;
  44.              */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement