Esempio n. 1
0
 private static void SecondGameCalculation(SecondGameTree gameTree)
 {
     sbyte row, col;
     if (CheckerPiece.CanABlackPieceEatOnTheBoard(gameTree.board, out row, out col))
     {
         for (; row < 8; row++)
             for (; col < 8; col++)
             {
                 if (gameTree.board[row, col] == -1)
                 {
                     List<sbyte[,]> list = new List<sbyte[,]>();
                     CheckerPiece.Eat(row, col, gameTree.board, list);
                     foreach (sbyte[,] board in list)
                     {
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, board, 2);
                     }
                 }
                 else if (gameTree.board[row, col] == -2)
                 {
                     List<sbyte[,]> list = new List<sbyte[,]>();
                     CheckerPiece.Eat(row, col, gameTree.board, list);
                     foreach (sbyte[,] board in list)
                     {
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, board, 2);
                     }
                 }
             }
     }
     else
     {
         for (sbyte i = 0; i < 8; i++)
             for (sbyte j = 0; j < 8; j++)
             {
                 if (gameTree.board[i, j] == -1)
                 {
                     if (CheckerPiece.CanMinus1MoveUpRight(gameTree.board, i, j))
                     {
                         CheckerPiece.MoveMinus1UpRight(gameTree.board, i, j);
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         CheckerPiece.UndoMoveMinus1UpRight(gameTree.board, i, j);
                     }
                     if (CheckerPiece.CanMinus1MoveUpLeft(gameTree.board, i, j))
                     {
                         CheckerPiece.MoveMinus1UpLeft(gameTree.board, i, j);
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         CheckerPiece.UndoMoveMinus1UpLeft(gameTree.board, i, j);
                     }
                 }
                 else if (gameTree.board[i, j] == -2)
                 {
                     int amountOfMoves1 = CheckerPiece.AmoutOfMinus2UpRightMoves(gameTree.board, i, j);
                     for (int k = 0; k < amountOfMoves1; k++)
                     {
                         gameTree.board[i, j] = 0;
                         gameTree.board[i - k - 1, j + k + 1] = -2;
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         gameTree.board[i, j] = -2;
                         gameTree.board[i - k - 1, j + k + 1] = 0;
                     }
                     int amountOfMoves2 = CheckerPiece.AmoutOfMinus2UpLeftMoves(gameTree.board, i, j);
                     for (int k = 0; k < amountOfMoves2; k++)
                     {
                         gameTree.board[i, j] = 0;
                         gameTree.board[i - k - 1, j - k - 1] = -2;
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         gameTree.board[i, j] = -2;
                         gameTree.board[i - k - 1, j - k - 1] = 0;
                     }
                     int amountOfMoves3 = CheckerPiece.AmoutOfMinus2DownRightMoves(gameTree.board, i, j);
                     for (int k = 0; k < amountOfMoves3; k++)
                     {
                         gameTree.board[i, j] = 0;
                         gameTree.board[i + k + 1, j - k - 1] = -2;
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         gameTree.board[i, j] = -2;
                         gameTree.board[i + k + 1, j - k - 1] = 0;
                     }
                     int amountOfMoves4 = CheckerPiece.AmoutOfMinus2DownLeftMoves(gameTree.board, i, j);
                     for (int k = 0; k < amountOfMoves4; k++)
                     {
                         gameTree.board[i, j] = 0;
                         gameTree.board[i + k + 1, j + k + 1] = -2;
                         GameTree newGameTree = new GameTree(Program.CalculateAdvantage(gameTree.board));
                         gameTree.list.Add(newGameTree);
                         GameCalculation(newGameTree, gameTree.board, 2);
                         gameTree.board[i, j] = -2;
                         gameTree.board[i + k + 1, j + k + 1] = 0;
                     }
                 }
             }
     }
 }
Esempio n. 2
0
 private static void SetRestTreeValues(GameTree gameTree, int turn)
 {
     if (gameTree.list.Count > 0)
     {
         foreach (GameTree newGameTree in gameTree.list)
         {
             SetRestTreeValues(newGameTree, turn + 1);
         }
         if (turn % 2 == 0)
         {
             int max = -100;
             foreach (GameTree newGameTree in gameTree.list)
             {
                 if (newGameTree.value > max)
                 {
                     max = newGameTree.value;
                 }
             }
             gameTree.value = max;
         }
         else
         {
             int min = 100;
             foreach (GameTree newGameTree in gameTree.list)
             {
                 if (newGameTree.value < min)
                 {
                     min = newGameTree.value;
                 }
             }
             gameTree.value = min;
         }
     }
 }
Esempio n. 3
0
 private static void GameCalculation(GameTree gameTree, sbyte[,] board, double turn)
 {
     if (turn < 8)
     {
         string whiteGameState = Program.GameState(board, "white");
         bool whoMoves = (turn % 2 == 0);
         if (whoMoves && whiteGameState == "no winner")
         {
             sbyte row, col;
             if (CheckerPiece.CanAWhitePieceEatOnTheBoard(board, out row, out col))
             {
                 for (; row < 8; row++)
                     for (; col < 8; col++)
                         if (CheckerPiece.CanAWhitePieceEat(board, ref row, ref col))
                         {
                             List<sbyte[,]> list = new List<sbyte[,]>();
                             CheckerPiece.Eat(row, col, board, list);
                             foreach (sbyte[,] newBoard in list)
                             {
                                 GameTree newGameTree = new GameTree(Program.CalculateAdvantage(newBoard));
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, newBoard, turn + 1);
                             }
                         }
             }
             else
             {
                 for (sbyte i = 0; i < 8; i++)
                     for (sbyte j = 0; j < 8; j++)
                     {
                         if (board[i, j] == 1)
                         {
                             if (CheckerPiece.CanPlus1MoveUpRight(board, i, j))
                             {
                                 CheckerPiece.MovePlus1UpRight(board, i, j);
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 CheckerPiece.UndoMovePlus1UpRight(board, i, j);
                             }
                             if (CheckerPiece.CanPlus1MoveUpLeft(board, i, j))
                             {
                                 CheckerPiece.MovePlus1UpLeft(board, i, j);
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 CheckerPiece.UndoMovePlus1UpLeft(board, i, j);
                             }
                         }
                         else if (board[i, j] == 2)
                         {
                             int amountOfMoves1 = CheckerPiece.AmoutOfPlus2UpRightMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves1; k++)
                             {
                                 board[i, j] = 0;
                                 board[i + k + 1, j - k - 1] = 2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = 2;
                                 board[i + k + 1, j - k - 1] = 0;
                             }
                             int amountOfMoves2 = CheckerPiece.AmoutOfPlus2UpLeftMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves2; k++)
                             {
                                 board[i, j] = 0;
                                 board[i + k + 1, j + k + 1] = 2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = 2;
                                 board[i + k + 1, j + k + 1] = 0;
                             }
                             int amountOfMoves3 = CheckerPiece.AmoutOfPlus2DownRightMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves3; k++)
                             {
                                 board[i, j] = 0;
                                 board[i - k - 1, j + k + 1] = 2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = 2;
                                 board[i - k - 1, j + k + 1] = 0;
                             }
                             int amountOfMoves4 = CheckerPiece.AmoutOfPlus2DownLeftMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves4; k++)
                             {
                                 board[i, j] = 0;
                                 board[i - k - 1, j - k - 1] = 2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = 2;
                                 board[i - k - 1, j - k - 1] = 0;
                             }
                         }
                     }
             }
         }
         else if (whoMoves && whiteGameState != "no winner")
         {
             gameTree.list.Add(new GameTree(-50));
         }
         else if (Program.GameState(board, "black") == "no winner")
         {
             sbyte row, col;
             if (CheckerPiece.CanABlackPieceEatOnTheBoard(board, out row, out col))
             {
                 for (; row < 8; row++)
                     for (; col < 8; col++)
                         if (CheckerPiece.CanABlackPieceEat(board, ref row, ref col))
                         {
                             List<sbyte[,]> list = new List<sbyte[,]>();
                             CheckerPiece.Eat(row, col, board, list);
                             foreach (sbyte[,] newBoard in list)
                             {
                                 GameTree newGameTree = new GameTree(Program.CalculateAdvantage(newBoard));
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, newBoard, turn + 1);
                             }
                         }
             }
             else
             {
                 for (sbyte i = 0; i < 8; i++)
                     for (sbyte j = 0; j < 8; j++)
                     {
                         if (board[i, j] == -1)
                         {
                             if (CheckerPiece.CanMinus1MoveUpRight(board, i, j))
                             {
                                 CheckerPiece.MoveMinus1UpRight(board, i, j);
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 CheckerPiece.UndoMoveMinus1UpRight(board, i, j);
                             }
                             if (CheckerPiece.CanMinus1MoveUpLeft(board, i, j))
                             {
                                 CheckerPiece.MoveMinus1UpLeft(board, i, j);
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 CheckerPiece.UndoMoveMinus1UpLeft(board, i, j);
                             }
                         }
                         else if (board[i, j] == -2)
                         {
                             int amountOfMoves1 = CheckerPiece.AmoutOfMinus2UpRightMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves1; k++)
                             {
                                 board[i, j] = 0;
                                 board[i - k - 1, j + k + 1] = -2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = -2;
                                 board[i - k - 1, j + k + 1] = 0;
                             }
                             int amountOfMoves2 = CheckerPiece.AmoutOfMinus2UpLeftMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves2; k++)
                             {
                                 board[i, j] = 0;
                                 board[i - k - 1, j - k - 1] = -2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = -2;
                                 board[i - k - 1, j - k - 1] = 0;
                             }
                             int amountOfMoves3 = CheckerPiece.AmoutOfMinus2DownRightMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves3; k++)
                             {
                                 board[i, j] = 0;
                                 board[i + k + 1, j - k - 1] = -2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = -2;
                                 board[i + k + 1, j - k - 1] = 0;
                             }
                             int amountOfMoves4 = CheckerPiece.AmoutOfMinus2DownLeftMoves(board, i, j);
                             for (int k = 0; k < amountOfMoves4; k++)
                             {
                                 board[i, j] = 0;
                                 board[i + k + 1, j + k + 1] = -2;
                                 GameTree newGameTree = new GameTree(gameTree.value);
                                 gameTree.list.Add(newGameTree);
                                 GameCalculation(newGameTree, board, turn + 1);
                                 board[i, j] = -2;
                                 board[i + k + 1, j + k + 1] = 0;
                             }
                         }
                     }
             }
         }
         else
             gameTree.list.Add(new GameTree(50));
     }
 }