Пример #1
0
 public Board WithNewLocation(Loc loc, Loc newLoc)
 {
     var newPices = Pieces.ToDictionary(i => i.Key, i => i.Value);
     newPices[newLoc] = newPices[loc];
     newPices.Remove(loc);
     return new Board(newPices);
 }
Пример #2
0
 public virtual IEnumerable<Board> PossibleMoves(Board currentBoard, byte row, byte col)
 {
     var currentLoc = new Loc(row, col);
     foreach (var loc in TilesCovered(currentBoard, row, col))
     {
         if (!currentBoard.IsOccupied(loc, IsWhite))
             yield return currentBoard.WithNewLocation(currentLoc, loc);
     }
 }
Пример #3
0
 public override IEnumerable<Board> PossibleMoves(Board currentBoard, byte row, byte col)
 {
     var currentLoc = new Loc(row, col);
     var boards = new List<Board>();
     foreach (var loc in TilesCovered(currentBoard, row, col))
     {
         if (!currentBoard.IsCovered(IsWhite, loc))
         {
             boards.Add(currentBoard.WithNewLocation(currentLoc, loc));
         }
     }
     return boards;
 }
Пример #4
0
        public override IEnumerable<Board> PossibleMoves(Board currentBoard, byte row, byte col)
        {
            var direction = -1;
            if (IsWhite) direction = 1;

            if (row + direction < 0 || row + direction > 7)
                yield break;

            var newLoc = new Loc(row + direction, col);
            var currentLoc = new Loc(row, col);
            if (!currentBoard.IsOccupied(newLoc))
            {
                yield return currentBoard.WithNewLocation(currentLoc, newLoc);
            }
        }
Пример #5
0
 public override IEnumerable<Loc> TilesCovered(Board currentBoard, byte row, byte col)
 {
     for (sbyte i = -1; i < 2; i++)
     {
         for (sbyte j = -1; j < 2; j++)
         {
             if (row + i < 0 || row + i > 7) continue;
             if (col + j < 0 || col + j > 7) continue;
             var loc = new Loc((byte)(row + i), (byte)(col + j));
             if (!currentBoard.IsOccupied(loc, IsWhite))
             {
                 yield return loc;
             }
         }
     }
 }
Пример #6
0
        public static IEnumerable<Loc> _TilesCovered(Board currentBoard, byte row, byte col)
        {
            var covered = new List<Loc>();
            for (int i = 1; i < 8; i++)
            {
                var loc = new Loc(row + i, col);
                if (!Board.InsideBoard(loc)) break;
                covered.Add(loc);
                if (currentBoard.IsOccupied(loc)) break;
            }

            for (int i = 1; i < 8; i++)
            {
                var loc = new Loc(row - i, col);
                if (!Board.InsideBoard(loc)) break;
                covered.Add(loc);
                if (currentBoard.IsOccupied(loc)) break;
            }

            for (int i = 1; i < 8; i++)
            {
                var loc = new Loc(row, col + i);
                if (!Board.InsideBoard(loc)) break;
                covered.Add(loc);
                if (currentBoard.IsOccupied(loc)) break;
            }

            for (int i = 1; i < 8; i++)
            {
                var loc = new Loc(row, col - i);
                if (!Board.InsideBoard(loc)) break;
                covered.Add(loc);
                if (currentBoard.IsOccupied(loc)) break;
            }
            return covered;
        }
Пример #7
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            for (byte row = 0; row < 8; row++)
            {
                sb.Append(row + " ");
                for (byte col = 0; col < 8; col++)
                {
                    var loc = new Loc(row, col);
                    if (Pieces.ContainsKey(loc))
                        sb.Append(GetName(Pieces[loc].Type) + " ");
                    else
                        sb.Append("  ");
                }
                sb.AppendLine();
            }
            return sb.ToString();
        }
Пример #8
0
 public bool IsCovered(bool white, Loc loc) => CoveredTiles(white).Contains(loc);
Пример #9
0
 public static bool InsideBoard(Loc location) =>
     location.Row >= 0 && location.Row <= 7 &&
     location.Col >= 0 && location.Col <= 7;
Пример #10
0
 public bool IsOccupied(Loc loc, bool white) =>
     Pieces.ContainsKey(loc) ? Pieces[loc].IsWhite == white : false;
Пример #11
0
 public bool IsOccupied(Loc loc) => IsOccupied(loc, true) || IsOccupied(loc, false);