Advertisement
Guest User

mazestuff

a guest
Jul 25th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. public class MyMazeSolver : BaseMazeSolver{
  2. public MyMazeSolver(){ //this implicitly extends the default constructor of the base class
  3.  
  4. //if you don't want to lock the UI, you can't really do this with a loop. T
  5. //his problem also persists if you have students editing main
  6. //while (WinnerWinnerChickenDinner() == false){
  7. // TurnLeft();
  8. // GoForward();
  9. //}
  10.  
  11. //if the students don't have any way of inspecting the maze state from code (other than they won)
  12. //then all they can to is starting moves, then repeatforever moves
  13. DoThisOnce();
  14. ThenDoThisUntilIWin();
  15. }
  16.  
  17. public void DoThisOnce(){
  18. //example student code
  19. TurnLeft();
  20. int i = 0;
  21. for (i = 0; i < 15; i++){
  22. GoForward();
  23. }
  24. //these happen once at the start
  25. }
  26.  
  27. public void ThenDoThisUntilIWin(){
  28. //example student code
  29. TurnRight();
  30. TurnRight();
  31. TurnLeft();
  32. GoForward();
  33. }
  34. }
  35.  
  36. public class BaseMazeSolver(){
  37. public BaseMazeSolver(){
  38. this.StartingMovesQueue = new PriorityQueue<Move>();
  39. }
  40. //protected will be accessible to subclasses, if it's easier, just make those things public (since it's the same to the students)
  41. //however, don't make the private things anything but private, since you want to hide them from autocompletion
  42. protected void TurnLeft(){
  43. this.MovesQueue.Add(Move.Left);
  44. };
  45. protected void TurnRight(){
  46. //and so on
  47. //...
  48. this.MovesQueue.Add(Move.Down);
  49. }
  50.  
  51. private Queue<Move> MovesQueue{get; private set;} //i'm using C# properties, they're more terse
  52.  
  53. //no good way to hide this from the autocompletion without mucking around with packages (not worth it)
  54. public Move GetNextMove(){
  55. //TODO loop detection here
  56. if (MovesQueue.Count() == 0){
  57. this.ThenDoThisUntilIWin();
  58. }
  59. var nextMove = MovesQueue.poll();
  60. return nextMove();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement