コード例 #1
0
 public void Crack()
 {
     var board = HorseBoard.CreateStartPostion();
     var state = new HorseBoardState(board);
     var result = doIteration(new[] {state});
     print(result);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: HorseBoardState.cs プロジェクト: rnofenko/devPuzzle
 public HorseBoardState(HorseBoard board, HorseBoardState state)
 {
     Board = board;
     History.AddRange(state.History);
     History.Add(state.Board);
 }