Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyMazeSolver : BaseMazeSolver{
- public MyMazeSolver(){ //this implicitly extends the default constructor of the base class
- //if you don't want to lock the UI, you can't really do this with a loop. T
- //his problem also persists if you have students editing main
- //while (WinnerWinnerChickenDinner() == false){
- // TurnLeft();
- // GoForward();
- //}
- //if the students don't have any way of inspecting the maze state from code (other than they won)
- //then all they can to is starting moves, then repeatforever moves
- DoThisOnce();
- ThenDoThisUntilIWin();
- }
- public void DoThisOnce(){
- //example student code
- TurnLeft();
- int i = 0;
- for (i = 0; i < 15; i++){
- GoForward();
- }
- //these happen once at the start
- }
- public void ThenDoThisUntilIWin(){
- //example student code
- TurnRight();
- TurnRight();
- TurnLeft();
- GoForward();
- }
- }
- public class BaseMazeSolver(){
- public BaseMazeSolver(){
- this.StartingMovesQueue = new PriorityQueue<Move>();
- }
- //protected will be accessible to subclasses, if it's easier, just make those things public (since it's the same to the students)
- //however, don't make the private things anything but private, since you want to hide them from autocompletion
- protected void TurnLeft(){
- this.MovesQueue.Add(Move.Left);
- };
- protected void TurnRight(){
- //and so on
- //...
- this.MovesQueue.Add(Move.Down);
- }
- private Queue<Move> MovesQueue{get; private set;} //i'm using C# properties, they're more terse
- //no good way to hide this from the autocompletion without mucking around with packages (not worth it)
- public Move GetNextMove(){
- //TODO loop detection here
- if (MovesQueue.Count() == 0){
- this.ThenDoThisUntilIWin();
- }
- var nextMove = MovesQueue.poll();
- return nextMove();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement