Exemple #1
0
 bool CanTakeEnPassant(Checkerboard checkerboard, Pawn pawn, Pawn sidePawn, Position finalPawnPos, out Pawn sidePosPawn)
 {
     sidePosPawn = null;
     return(pawn.Position.Digit == (pawn.PawnColor == PawnColor.White ? 4 : 3) &&
            pawn.AreOppositeColor(sidePawn) &&
            checkerboard.AllMoves.Last().Pawn.PawnType == PawnType.Pawn &&
            checkerboard.AllMoves.Last().NewPawnPos == sidePawn.Position &&
            checkerboard.IsOccupied(sidePawn.Position, out sidePosPawn) &&
            !checkerboard.IsOccupied(finalPawnPos, out _));
 }
Exemple #2
0
        public IEnumerable <Move> GetTakes(Checkerboard checkerboard, Pawn pawn)
        {
            Position leftPos;
            Position rightPos;
            Position frontLeftPos;
            Position frontRightPos;

            int curPawnLetter = pawn.Position.Letter;
            int curPawnDigit  = pawn.Position.Digit;

            if (pawn.PawnColor == PawnColor.White)
            {
                frontLeftPos  = new Position((curPawnLetter - 1), curPawnDigit + 1);
                frontRightPos = new Position((curPawnLetter + 1), curPawnDigit + 1);
                leftPos       = new Position((curPawnLetter - 1), curPawnDigit);
                rightPos      = new Position((curPawnLetter + 1), curPawnDigit);
            }
            else
            {
                frontLeftPos  = new Position((curPawnLetter + 1), curPawnDigit - 1);
                frontRightPos = new Position((curPawnLetter - 1), curPawnDigit - 1);
                leftPos       = new Position((curPawnLetter - 1), curPawnDigit);
                rightPos      = new Position((curPawnLetter + 1), curPawnDigit);
            }

            if (checkerboard.IsOccupied(leftPos, out Pawn oppositeLeftPawn) && CanTakeEnPassant(checkerboard, pawn, oppositeLeftPawn, frontLeftPos, out Pawn frontLeftPawn))
            {
                yield return(checkerboard.GetMove(pawn, frontLeftPos, frontLeftPawn));
            }
            if (checkerboard.IsOccupied(rightPos, out Pawn oppositeRightPawn) && CanTakeEnPassant(checkerboard, pawn, oppositeRightPawn, frontRightPos, out Pawn frontRightPawn))
            {
                yield return(checkerboard.GetMove(pawn, frontRightPos, frontRightPawn));
            }

            if (checkerboard.IsOccupied(frontLeftPos, out Pawn frontLeftPawn1) && pawn.AreOppositeColor(frontLeftPawn1))
            {
                yield return(checkerboard.GetMove(pawn, frontLeftPos, frontLeftPawn1));
            }

            if (checkerboard.IsOccupied(frontRightPos, out Pawn frontRightPawn1) && pawn.AreOppositeColor(frontRightPawn1))
            {
                yield return(checkerboard.GetMove(pawn, frontRightPos, frontRightPawn1));
            }
        }
Exemple #3
0
        public static IEnumerable <Move> FindMovesAlongDirection(this Checkerboard checkerboard, Pawn pawn, Position delta)
        {
            var currPosition = pawn.Position + delta;

            while (Checkerboard.Exists(currPosition))
            {
                if (checkerboard.IsOccupied(currPosition, out Pawn currPosPawn))
                {
                    if (currPosPawn.AreOppositeColor(pawn))
                    {
                        yield return(checkerboard.GetMove(pawn, currPosition, currPosPawn));
                    }
                    break;
                }
                else if (checkerboard.IsEmptyButExists(currPosition))
                {
                    yield return(checkerboard.GetMove(pawn, currPosition));
                }
                currPosition += delta;
            }
        }