Beispiel #1
0
        /// <summary>
        ///     Generates all legal <see cref="IPawn" /> moves
        /// </summary>
        /// <param name="boardState"></param>
        public override void GenerateMoves(IBoardState boardState)
        {
            IChessPieceMover cpm = ModelLocator.ChessPieceMover;

            MoveSet.Clear();
            ChessPosition oneSpaceFromLocation = Color == ChessColor.White ? cpm.North(Location) : cpm.South(Location);
            bool          oneSpaceMoveIsLegal  = !boardState.Contains(oneSpaceFromLocation);

            if (oneSpaceMoveIsLegal)
            {
                MoveSet.Add(oneSpaceFromLocation);
            }
            else
            {
                return;
            }

            ChessPosition twoSpaceFromLocation = Color == ChessColor.White
                ? cpm.North(oneSpaceFromLocation)
                : cpm.South(oneSpaceFromLocation);
            bool twoSpaceMoveIsLegal = !boardState.Contains(twoSpaceFromLocation);

            if (!HasMoved && twoSpaceMoveIsLegal)
            {
                MoveSet.Add(Color == ChessColor.White
                    ? cpm.North(cpm.North(Location))
                    : cpm.South(cpm.South(Location)));
            }
        }
Beispiel #2
0
        /// <summary>
        ///     Will update whether the Pawn is able to be promoted or captured via En Passant.
        /// </summary>
        /// <param name="position"></param>
        public override void MoveTo(ChessPosition position)
        {
            if (!HasMoved)
            {
                IChessPieceMover cpm = ModelLocator.ChessPieceMover;
                bool             moveIsTwoForward = Color == ChessColor.White
                    ? position == cpm.North(cpm.North(Location))
                    : position == cpm.South(cpm.South(Location));

                IsCapturableByEnPassant = moveIsTwoForward;
            }
            else
            {
                IsCapturableByEnPassant = false;
            }

            base.MoveTo(position);

            ChessPosition promotionRank = Color == ChessColor.White ? ChessPosition.Rank8 : ChessPosition.Rank1;

            if ((position & promotionRank) == position)
            {
                IsPromotable = true;
            }
        }
        public void Should_GenerateOneMoveSouth()
        {
            // execute
            ChessPosition position = _mover.South(ChessPosition.A2);

            // verify
            Assert.AreEqual(ChessPosition.A1, position);
        }
Beispiel #4
0
        private void GenerateSouthMoves(IBoardState boardState, IChessPieceMover cpm)
        {
            ChessPosition nextMove = cpm.South(Location);

            if (!boardState.Contains(nextMove))
            {
                MoveSet.Add(nextMove);
            }
        }
Beispiel #5
0
        private void GenerateSouthSouthWestMove(IBoardState boardState, IChessPieceMover cpm)
        {
            ChessPosition move = cpm.South(cpm.SouthWest(Location));

            if (!boardState.Contains(move))
            {
                MoveSet.Add(move);
            }
        }
Beispiel #6
0
        public ChessPosition GetLocationOfPieceBeingCaptured(IPiece capturingPiece, ICapture capture)
        {
            IChessPieceMover cpm = ModelLocator.ChessPieceMover;
            // get the position of the piece we're trying to capture via En Passant
            ChessPosition locationOfPotentiallyCapturedPiece = capturingPiece.Color == ChessColor.White
                ? cpm.South(capture.EndingPosition)
                : cpm.North(capture.EndingPosition);

            return(locationOfPotentiallyCapturedPiece);
        }
Beispiel #7
0
        private void GenerateSouthCaptures(IBoardState enemyBoardState, IChessPieceMover cpm)
        {
            ChessPosition capture = cpm.South(Location);

            AddCaptureToCaptureSet(capture, enemyBoardState);
        }