コード例 #1
0
ファイル: Player.cs プロジェクト: Kevin-Jin/kvj-board-games
        internal void Castle(ChessBoard board, bool kingSide)
        {
            MoveSet prevMoves = moves;
            if (moves != null)
            {
                ResetSelected();
                board.UnhighlightSquare(firstSelection);
            }

            SquareCoordinates kingStart, kingEnd, rookStart, rookEnd;
            ChessPiece piece;

            int rank = white ? 0 : 7;
            kingStart = new SquareCoordinates(4, rank);
            if (kingSide)
            {
                kingEnd = new SquareCoordinates(6, rank);
                rookStart = new SquareCoordinates(7, rank);
                rookEnd = new SquareCoordinates(5, rank);
            }
            else
            {
                kingEnd = new SquareCoordinates(2, rank);
                rookStart = new SquareCoordinates(0, rank);
                rookEnd = new SquareCoordinates(3, rank);
            }
            //rookEnd = new SquareCoordinates((kingStart.File + kingEnd.File) / 2, rank);

            piece = board.ClearSquare(kingStart);
            piece.LastSquare = kingStart;
            piece.LastMove = board.CurrentMove;
            board.DrawPiece(kingEnd, piece);
            material.MovePiece(PieceType.KING, kingStart, kingEnd);

            piece = board.ClearSquare(rookStart);
            piece.LastSquare = rookStart;
            piece.LastMove = board.CurrentMove;
            board.DrawPiece(rookEnd, piece);
            material.MovePiece(PieceType.ROOK, rookStart, rookEnd);

            PerformedCastle(board, kingSide, prevMoves);
            board.UpdateLastMoveFromCastle(kingSide);
            board.NextTurn();
        }