public void Crack() { var board = HorseBoard.CreateStartPostion(); var state = new HorseBoardState(board); var result = doIteration(new[] {state}); print(result); }
private void print(HorseBoardState state) { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(); Console.WriteLine("Total Steps = " + state.History.Count); var i = 0; foreach (var horseBoard in state.History) { Console.WriteLine($"Step {++i}"); print(horseBoard); } Console.WriteLine($"Step {++i}"); print(state.Board); }
private HorseBoardState doIteration(IEnumerable<HorseBoardState> oldStates) { var newStates = new List<HorseBoardState>(); foreach (var state in oldStates) { var newBoards = findAllPossibleMoves(state.Board); foreach (var board in newBoards.Where(addToUniqueStorage)) { var newState = new HorseBoardState(board, state); if (board.IsFinalState()) { return newState; } newStates.Add(newState); } } return doIteration(newStates); }
public HorseBoardState(HorseBoard board, HorseBoardState state) { Board = board; History.AddRange(state.History); History.Add(state.Board); }