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();
    }
示例#2
0
 public void GoToMenu()
 {
     gameController.OnEnteredNormalMode();
     gameController.Board.ChessGrid.ResetGrid();
     randomBoard.CreateRandomBoardLayout();
     gameController.CameraController.RandomCameraMovement();
     ActivateMainMenu();
 }
示例#3
0
    public void HandleInput(ChessGameController gameController)
    {
        if (piecePromotionIsActive)
        {
            HandlePromotion(gameController);
            return;
        }

        Board board         = gameController.Board;
        bool  validPosition = board.CheckIfPositionIsValid(SelectedPosition);

        if (!validPosition)
        {
            board.OnDeselectActivePiece();
        }

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

        recievedInput = false;
        Vector2Int chosenPosition = Board.CalculateSquareIndexFromBoardPosition(SelectedPosition);
        Piece      chosenPiece    = board.ChessGrid.GetPieceOnSquareIndex(chosenPosition);

        if (board.ChessGrid.SelectedPiece != null)
        {
            if (board.ChessGrid.SelectedPiece.CanMoveToSquare(chosenPosition))
            {
                board.OnSelectedPieceMove(board.ChessGrid.SelectedPiece.GetMoveFromSquareIndex(chosenPosition));
                gameController.OnEnteredNormalMode();
            }
            board.OnDeselectActivePiece();
        }
        else if (chosenPiece != null && chosenPiece.TeamColor == gameController.ActivePlayer.TeamColor)
        {
            board.OnSelectPiece(chosenPiece);
        }
    }