public List <Move> Solution() { var root = new SolutionNode(null, Game.Current); if (Game.Current.IsSameBoard(Game.Solved)) { var moves = new List <Move>(); moves.Add(new Move(Move.Moves.Start)); return(moves); } var legalMoves = Game.Current.LegalMoves(); var visited = new List <Tuple <SolutionNode, Move> >(); visited.Add(new Tuple <SolutionNode, Move>(root, new Move(Move.Moves.Start))); var nodeQueue = new Queue <Tuple <SolutionNode, Move> >(); foreach (var move in legalMoves) { var board = new Board(Game.Current); board.ApplyMove(move); var node = new SolutionNode(root, board); root.Children.Add(move, node); if (board.IsSameBoard(Game.Solved)) { var n = new Tuple <SolutionNode, Move>(node, move); visited.Add(n); return(SolutionPath(n, visited)); } else { nodeQueue.Enqueue( new Tuple <SolutionNode, Move>(node, move)); } } return(BreadthFirstSearch(nodeQueue, visited)); }
public List<Move> Solution() { var root = new SolutionNode(null, Game.Current); if (Game.Current.IsSameBoard(Game.Solved)) { var moves = new List<Move>(); moves.Add(new Move(Move.Moves.Start)); return moves; } var legalMoves = Game.Current.LegalMoves(); var visited = new List<Tuple<SolutionNode, Move>>(); visited.Add(new Tuple<SolutionNode, Move>(root, new Move(Move.Moves.Start))); var nodeQueue = new Queue<Tuple<SolutionNode, Move>>(); foreach (var move in legalMoves) { var board = new Board(Game.Current); board.ApplyMove(move); var node = new SolutionNode(root, board); root.Children.Add(move, node); if (board.IsSameBoard(Game.Solved)) { var n = new Tuple<SolutionNode, Move>(node, move); visited.Add(n); return SolutionPath(n, visited); } else { nodeQueue.Enqueue( new Tuple<SolutionNode, Move>(node, move)); } } return BreadthFirstSearch(nodeQueue, visited); }
public SolutionNode(SolutionNode parent, Board board) { _parent = parent; _current = board; }