Esempio n. 1
0
        private static IEnumerable <Location> MovesInOneDirection(Location from, Board board, Location dir, bool infinit)
        {
            var piece    = board.GetPiece(from);
            var distance = infinit ? int.MaxValue : 2;

            for (var i = 1; i < distance; i++)
            {
                var to = new Location(from.X + dir.X * i, from.Y + dir.Y * i);
                if (!board.Contains(to))
                {
                    break;
                }
                var destinationPiece = board.GetPiece(to);
                if (destinationPiece == null)
                {
                    yield return(to);
                }
                else
                {
                    if (destinationPiece.Color != piece.Color)
                    {
                        yield return(to);
                    }
                    yield break;
                }
            }
        }
Esempio n. 2
0
        private static IEnumerable <Location> GetPossibleLocationsToDirection(
            Location startLocation, Board board, Location direction, bool isInfinite)
        {
            var piece    = board.GetPiece(startLocation);
            var distance = isInfinite ? int.MaxValue : 2;

            for (var i = 1; i < distance; i++)
            {
                var nextLocation = new Location(startLocation.X + direction.X * i, startLocation.Y + direction.Y * i);
                if (!board.Contains(nextLocation))
                {
                    break;
                }
                var destinationPiece = board.GetPiece(nextLocation);
                if (destinationPiece == null)
                {
                    yield return(nextLocation);
                }
                else
                {
                    if (piece.IsOpponentPiece(destinationPiece))
                    {
                        yield return(nextLocation);
                    }
                    yield break;
                }
            }
        }