private static IEnumerable <int> GetWhiteLanceMoves(int index) { while (Board.IsInBoard(++index)) { yield return(index); } }
private static IEnumerable <int> GetBlackLanceMoves(int index) { while (Board.IsInBoard(--index)) { yield return(index); } }
// 現在の局面で、与えられたマス・手番に対して、縦横斜めの遠方へ移動可能な全マスを返す private static IEnumerable <int> GetMovableRange(int index, Color color, Board board) { foreach (int direction in new int[] { -11, -10, -9, -1, 1, 9, 10, 11 }) { int i = index + direction; while (Board.IsInBoard(i)) { if (board[i] != Piece.Empty) { // 自分の駒ならそれ以上先に進めない if (board[i].ToColor() == color) { break; } // 敵の駒なら駒を取ってその地点まで進める if (board[i].ToColor() != color) { yield return(i); break; } } yield return(i); i += direction; } } }
// 非合法手を含めた移動可能なすべてのマスを返す。 public static IEnumerable <int> GetMovableIndexes(Piece p, int index) { foreach (int candidate in _movableIndexesFactories[p](index)) { if (Board.IsInBoard(candidate)) { yield return(candidate); } } }
private static IEnumerable <int> GetRookMoves(int index) { foreach (int direction in new int[] { -10, -1, 1, 10 }) { int pos = index + direction; while (Board.IsInBoard(pos)) { yield return(pos); pos += direction; } } }
private static IEnumerable <int> GetBishopMoves(int index) { foreach (int direction in new int[] { -11, -9, 9, 11 }) { int pos = index + direction; while (Board.IsInBoard(pos)) { yield return(pos); pos += direction; } } }