コード例 #1
0
 protected PiecePlacement GetNewPlacement(BoardVector atPosition)
 {
     return(new PiecePlacement(new PieceT()
     {
         Team = team
     }, atPosition));
 }
コード例 #2
0
ファイル: PieceKing.cs プロジェクト: tomi901/Unity-Chess-MVC
        protected override IEnumerable <BoardMovement> GetAllExtraRelativeMovements(Board board)
        {
            // Castling
            if (Rank == 1 && !HasMoved && !Checked)
            {
                var nextMovements = new HashSet <BoardVector>(CurrentTurn.NextCalculatedTurnsMovements
                                                              .Select(kvp => kvp.Key.to));

                for (int x = -CastlingDistance; x <= CastlingDistance; x += CastlingDistance * 2)
                {
                    BoardVector movement = new BoardVector(x, 0);

                    BoardVector nextTilePos = Coordinates + movement.Normalized;
                    if (nextMovements.Contains(nextTilePos))
                    {
                        continue;
                    }

                    Piece foundPiece = board.Raycast(Coordinates, movement);
                    if (foundPiece is PieceRook && foundPiece.Rank == 1 && !foundPiece.HasMoved)
                    {
                        yield return(new BoardMovement(movement));
                    }
                }
            }
        }
コード例 #3
0
ファイル: PiecePawn.cs プロジェクト: tomi901/Unity-Chess-MVC
        protected override void OnMovementDone(BoardVector deltaMovement)
        {
            if (System.Math.Abs(deltaMovement.vertical) == 2)
            {
                LastDoubleMovementTurn = CurrentTurn.Number;
            }

            // After a diagonal movement we check one tile behind to check if we should apply
            // En Passant rule
            if (deltaMovement.horizontal != 0 && ContainingBoard[Coordinates - GetTransformedMovementForTeam(0, 1)]
                .CurrentPiece is PiecePawn pawn && pawn.Team != this.Team)
            {
                pawn.Capture(this);
            }
        }
コード例 #4
0
ファイル: PiecePawn.cs プロジェクト: tomi901/Unity-Chess-MVC
        protected override IEnumerable <BoardMovement> GetAllPosibleRelativeMovements(Board board)
        {
            IEnumerable <BoardMovement> All()
            {
                foreach (BoardMovement movement in GetBlockableLine(board, GetTransformedMovementForTeam(0, 1),
                                                                    result => result == MovementAttemptResult.Unblocked, HasMoved ? 1 : 2))
                {
                    yield return(movement);
                }

                for (int h = -1; h <= 1; h += 2)
                {
                    BoardVector movement = GetTransformedMovementForTeam(h, 1);

                    // Check for a pawn in that side and if it moved to spaces to
                    // see if the En Passant rule is applyable
                    BoardVector sidePosition = Coordinates + new BoardVector(h, 0);
                    bool        passantRule  = board.PositionIsInside(sidePosition) &&
                                               board[sidePosition].CurrentPiece is PiecePawn pawn &&
                                               pawn.EnPassantRuleCapturable(this);

                    // Check for En Passant rule or regular capture
                    if (passantRule || (board.GetMovementAttemptResult(GetMovementFromRelative(movement)) ==
                                        MovementAttemptResult.OtherTeam))
                    {
                        yield return((BoardMovement)movement);
                    }
                }
            }

            foreach (BoardMovement movement in All())
            {
                if (GetRank(Coordinates.vertical + movement.to.vertical) == PromoteRank)
                {
                    foreach (ChessPieceType piecePromotion in promotablePieces)
                    {
                        yield return(new BoardMovement(movement, piecePromotion));
                    }
                }
                else
                {
                    yield return(movement);
                }
            }
        }
コード例 #5
0
ファイル: PieceKing.cs プロジェクト: tomi901/Unity-Chess-MVC
        protected override void OnMovementDone(BoardVector deltaMovement)
        {
            // After castling
            if (Math.Abs(deltaMovement.horizontal) == CastlingDistance)
            {
                if (Checked)
                {
                    throw new Exception("Castling invalid, king checked.");
                }

                Piece castlingRook = ContainingBoard.Raycast(Coordinates, deltaMovement) as PieceRook;
                if (castlingRook == null)
                {
                    throw new Exception("Castling invalid, no rook found.");
                }

                BoardVector rookTargetPos = Coordinates - deltaMovement.Normalized;
                ContainingBoard.DoMovement(new BoardMovement(castlingRook.Coordinates, rookTargetPos));
            }
        }
コード例 #6
0
ファイル: Board.cs プロジェクト: tomi901/Unity-Chess-MVC
 public Tile this[BoardVector coords]
 {
     get => this[coords.horizontal, coords.vertical];
コード例 #7
0
 public MirroredPiecesEntry(PieceTeam team, BoardVector position) : base(team)
 {
     this.position = position;
 }
コード例 #8
0
 public SinglePieceEntry(PieceTeam team, BoardVector startPosition) : base(team)
 {
     this.position = startPosition;
 }
コード例 #9
0
 public PiecePlacement(Piece piece, BoardVector atPosition)
 {
     this.piece      = piece ?? throw new ArgumentNullException(nameof(piece));
     this.atPosition = atPosition;
 }