Esempio n. 1
0
    public void HandleInput(ChessGameController gameController)
    {
        if (piecePromotionIsActive)
        {
            HandlePromotion(gameController);
            return;
        }

        ChessPlayer player = gameController.ActivePlayer;
        Board       board  = gameController.Board;

        if (board.TurnIsActive || (gameController.State != GameState.Normal && gameController.State != GameState.Check))
        {
            return;
        }

        ChessPlayer   playerCopy = new ChessPlayer(null, player.TeamColor);
        ChessPlayer   enemyCopy  = new ChessPlayer(null, gameController.GetOppositeToActivePlayer().TeamColor);
        ChessGridInfo gridCopy   = playerCopy.TeamColor == TeamColor.White ? ChessGridInfo.CopyGrid(board.ChessGrid, playerCopy, enemyCopy) :
                                   ChessGridInfo.CopyGrid(board.ChessGrid, enemyCopy, playerCopy);

        Move foundMove = FindBestMove(gridCopy, playerCopy, enemyCopy);
        Move bestMove  = new Move(board.ChessGrid.GetPieceOnSquareIndex(foundMove.MovingPiece), foundMove.TargetSquare,
                                  board.ChessGrid.GetPieceOnSquareIndex(foundMove.TargetPiece), foundMove.PromotionFlag, foundMove.CastlingFlag,
                                  board.ChessGrid.GetPieceOnSquareIndex(foundMove.CastlingPiece), foundMove.CastlingTargetSquare);

        board.OnSelectPiece(bestMove.MovingPiece);
        board.OnSelectedPieceMove(bestMove);
        gameController.OnEnteredNormalMode();
        board.OnDeselectActivePiece();
    }
Esempio n. 2
0
    public void GenerateAllPossibleMoves(ChessGridInfo grid, bool checkMovesValidity, bool checkSpecialMoves)
    {
        ChessGridInfo gridCopy   = null;
        ChessPlayer   enemyCopy  = null;
        ChessPlayer   playerCopy = null;

        if (checkMovesValidity)
        {
            TeamColor opponentColor = TeamColor == TeamColor.White ? TeamColor.Black : TeamColor.White;
            playerCopy = new ChessPlayer(null, TeamColor);
            enemyCopy  = new ChessPlayer(null, opponentColor);
            gridCopy   = opponentColor == TeamColor.White ? ChessGridInfo.CopyGrid(grid, enemyCopy, playerCopy)
                : ChessGridInfo.CopyGrid(grid, playerCopy, enemyCopy);
        }

        AllPossibleMoves.Clear();
        for (int i = 0; i < ActivePieces.Count; i++)
        {
            ActivePieces[i].GeneratePossibleMoves(grid, gridCopy, playerCopy, enemyCopy, checkMovesValidity, checkSpecialMoves);
            AllPossibleMoves.AddRange(ActivePieces[i].AvailableMoves);
        }
    }