private static bool ProcessLeafGroup(ref JumpTree tree) { bool forced; bool added = false; var leaves = tree.GetLeaves(true); foreach (var node in leaves) { node.CheckAgain = false; var targets = GetPossibleTargetFields(node.Board, node.Position, out forced); if (!forced) { continue; } tree.AddTargets(node, targets); added = true; } return added; }
public static IEnumerable<IMove> GetAllMovesFromField(GameBoard board, BoardPosition fromFieldPosition, out bool forcedOnly) { PlayerColor player = board[fromFieldPosition].Occupation; List<IMove> moves = new List<IMove>(); var firstTargets = GetPossibleTargetFields(board, fromFieldPosition, out forcedOnly); if (!forcedOnly) { moves.AddRange(firstTargets.Select(pos => new SimpleMove(player, fromFieldPosition, pos, board[fromFieldPosition].Piece == PieceType.King, false))); return moves; } JumpTree tree = new JumpTree(fromFieldPosition, firstTargets, board); ConstructJumpTree(ref tree); var paths = tree.Linearize(); tree = null; foreach (var path in paths) { if (path.Count == 2) { moves.Add(new SimpleMove(player, path[0], path[1], board[fromFieldPosition].Piece == PieceType.King, true)); } else { CompoundMove move = CompoundMove.FromPositions(player, path.First(), path.Last(), board[fromFieldPosition].Piece == PieceType.King, path.GetRange(1, path.Count - 2).ToArray()); moves.Add(move); } } return moves; }
private static void ConstructJumpTree(ref JumpTree tree) { while (ProcessLeafGroup(ref tree)) ; }