public void ShoudBeEquals() { var move1 = new MazeMove(Direction.Right, new Frame(new CellType[3, 3] { { CellType.Wall, CellType.Wall, CellType.Wall }, { CellType.Empty, CellType.Empty, CellType.Empty }, { CellType.Wall, CellType.Wall, CellType.Wall } })); var move2 = new MazeMove(Direction.Right, new Frame(new CellType[3, 3] { { CellType.Wall, CellType.Wall, CellType.Wall }, { CellType.Empty, CellType.Empty, CellType.Empty }, { CellType.Wall, CellType.Wall, CellType.Wall } })); Assert.Equal(move1, move2); }
public async Task ShouldSaveMoveToStack() { var map = @"1111 1R 1111"; var robot = Create.LocalRobot(map); var solver = Create.MazeSolver(Create.LocalRobot(map)); await solver.MakeMove(Direction.Right); var mazeMove = solver.MazeMoves.Peek(); var expectedMove = new MazeMove(Direction.Right, new Frame(new CellType[3, 3] { { CellType.Wall, CellType.Wall, CellType.Wall }, { CellType.Empty, CellType.Empty, CellType.Empty }, { CellType.Wall, CellType.Wall, CellType.Wall } })); Assert.Single(solver.MazeMoves); Assert.Equal(expectedMove, mazeMove); }
protected bool Equals(MazeMove other) { return(Direction == other.Direction && Frame == other.Frame ); }
//moves the user through the maze depending on the input received. private void move(MazeMove the_move) { //if the user pull up the hint, then remove it if (my_solution_path != null) { my_solution_path = null; pnlDraw.Refresh(); } //generate graph if necessary generateGraph(); DSInteger current_move = my_user_solution_path.last(); List <SimpleEdge <DSInteger> > next_moves = my_maze_graph.getEdgesIncidentTo(current_move); //get the next moves in the graph (adjacent vertices) DSInteger check; bool found = false; //which move was chosen switch (the_move) { case MazeMove.Up: check = new DSInteger(current_move.value - my_cols); if (checkContains(next_moves, check)) { found = true; } break; case MazeMove.Down: check = new DSInteger(current_move.value + my_cols); if (checkContains(next_moves, check)) { found = true; } break; case MazeMove.Left: check = new DSInteger(current_move.value - 1); if (checkContains(next_moves, check)) { found = true; } break; default: //right check = new DSInteger(current_move.value + 1); if (checkContains(next_moves, check)) { found = true; } break; } //if the user can move in that direction (no wall - an edge exists in the graph) if (found) { //check for backtracking (the second to last element was the last move if (my_user_solution_path.size() > 1 && my_user_solution_path.get(my_user_solution_path.size() - 2).Equals(check)) { //the last element is my_current_move DSInteger removed = my_user_solution_path.removeAt(my_user_solution_path.size() - 1); //update the maze drawUserSolution(false, removed); } else { my_user_solution_path.add(check); drawUserSolution(false, null); } //check for reaching the finish node userReachsFinish(my_user_solution_path.last()); } }