Exemple #1
0
 public void revertStep()
 {
     if (board.revertStep(true))
     {
         ismarked  = false;
         whiteTurn = !whiteTurn;
         if (playerBoth)
         {
             playerWhite = !playerWhite;
         }
         possibleMoves = Rules.checkMoves(board, whiteTurn, true);
         checkCheck();
     }
 }
Exemple #2
0
        private static int minimax(Board board, int depth, bool isWhite, int alpha, int beta)
        {
            if (depth == 0)
            {
                checkedMoves++;
                return(evalBoard(board));
            }

            List <Move> moves = Rules.checkMoves(board, isWhite, true);

            if (isWhite)
            {
                int bestMove = -99999;
                for (int i = 0; i < moves.Count; i++)
                {
                    board.move(moves[i], false);
                    bestMove = Math.Max(bestMove, minimax(board, depth - 1, !isWhite, alpha, beta));
                    board.revertStep(false);
                    alpha = Math.Max(alpha, bestMove);
                    if (beta <= alpha)
                    {
                        return(bestMove);
                    }
                }
                return(bestMove);
            }
            else
            {
                int bestMove = 99999;
                for (int i = 0; i < moves.Count; i++)
                {
                    board.move(moves[i], false);
                    bestMove = Math.Min(bestMove, minimax(board, depth - 1, !isWhite, alpha, beta));
                    board.revertStep(false);
                    beta = Math.Min(beta, bestMove);
                    if (beta <= alpha)
                    {
                        return(bestMove);
                    }
                }
                return(bestMove);
            }
        }
Exemple #3
0
 public void reset()
 {
     board.reset();
     ismarked  = false;
     whiteTurn = true;
     check     = false;
     checkmate = false;
     draw      = false;
     if (playerBoth)
     {
         playerWhite = true;
     }
     possibleMoves = Rules.checkMoves(board, whiteTurn, true);
     if (playerWhite != whiteTurn)
     {
         Opponent.move(board, possibleMoves, whiteTurn, difficulty);
         whiteTurn     = !whiteTurn;
         possibleMoves = Rules.checkMoves(board, whiteTurn, true);
     }
 }
Exemple #4
0
        public void tryMove(int x, int y)
        {
            if (checkmate)
            {
                return;
            }

            if (posIsPlayer(x, y))
            {
                ismarked = false;
            }

            if (ismarked)
            {
                for (int i = 0; i < possiblePos.Count; i++)
                {
                    if (possiblePos[i].x == x && possiblePos[i].y == y)
                    {
                        board.move(new Move(marked, new Position(y, x)), true);
                        whiteTurn = !whiteTurn;
                        if (playerBoth)
                        {
                            playerWhite = !playerWhite;
                        }
                        possibleMoves = Rules.checkMoves(board, whiteTurn, true);
                        if (playerWhite != whiteTurn && possibleMoves.Count > 0)
                        {
                            Opponent.move(board, possibleMoves, whiteTurn, difficulty);
                            whiteTurn     = !whiteTurn;
                            possibleMoves = Rules.checkMoves(board, whiteTurn, true);
                        }
                        checkCheck();
                        break;
                    }
                }
                ismarked = false;
            }
            else
            {
                int start = 7;
                if (playerWhite)
                {
                    start = 1;
                }
                if ((int)board.pieces[y, x] >= start && (int)board.pieces[y, x] < start + 6)
                {
                    possiblePos.Clear();
                    for (int i = 0; i < possibleMoves.Count; i++)
                    {
                        if (possibleMoves[i].source.x == x && possibleMoves[i].source.y == y)
                        {
                            possiblePos.Add(possibleMoves[i].target);
                        }
                    }
                    if (possiblePos.Count > 0)
                    {
                        ismarked = true;
                        marked.x = x;
                        marked.y = y;
                    }
                }
            }
        }