Ejemplo n.º 1
0
        public IEnumerable <Move> GetMoves(Checkerboard checkerboard, Pawn pawn)
        {
            Position posPlus1;
            Position posPlus2;

            if (pawn.PawnColor == PawnColor.White)
            {
                posPlus1 = pawn.Position + new Position(0, 1);
                posPlus2 = posPlus1 + new Position(0, 1);
            }
            else
            {
                posPlus1 = pawn.Position - new Position(0, 1);
                posPlus2 = posPlus1 - new Position(0, 1);
            }

            bool canMove1SquareForward = checkerboard.IsEmptyButExists(posPlus1);
            bool canMove2SquareForward = pawn.Position.Digit == (pawn.PawnColor == PawnColor.White ? 1 : 6) && checkerboard.IsEmptyButExists(posPlus2);

            if (canMove1SquareForward)
            {
                yield return(checkerboard.GetMove(pawn, posPlus1));

                if (canMove2SquareForward)
                {
                    yield return(checkerboard.GetMove(pawn, posPlus2));
                }
            }

            foreach (var take in GetTakes(checkerboard, pawn))
            {
                yield return(checkerboard.GetMove(pawn, take.NewPawnPos, take.TakenPawn));
            }
        }
Ejemplo n.º 2
0
 Move?FindMove(Checkerboard checkerboard, Pawn pawn, Position position)
 {
     if (checkerboard.IsEmptyButExists(position))
     {
         return(checkerboard.GetMove(pawn, position));
     }
     return(null);
 }
Ejemplo n.º 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;
            }
        }