private static IEnumerable <Location> MovesInOneDirection(Location from, Board board, Location dir, bool infinit) { var fromColoredPiece = board.Get(from); for (var i = 1; i < (infinit ? 8 : 2); i++) { var to = new Location(from.X + dir.X * i, from.Y + dir.Y * i); if (!to.InBoard) { break; } var toColoredPiece = board.Get(to); if (toColoredPiece.Piece == null) { yield return(to); } else { if (toColoredPiece.Color != fromColoredPiece.Color) { yield return(to); } yield break; } } }
public void Undo() { board.Set(from, board.Get(to)); board.Set(to, oldDestinationPiece); }