Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. public State getNextState(State s, Action a) {
  2. State succState = s.clone();
  3. // TODO: fill out this function
  4. switch(a) {
  5. case TURN_ON:
  6. succState.turned_on = true;
  7. break;
  8. case TURN_OFF:
  9. succState.turned_on = false;
  10. break;
  11. case TURN_RIGHT:
  12. succState.orientation += 1;
  13. succState.orientation %= 4;
  14. break;
  15. case TURN_LEFT:
  16. succState.orientation -= 1;
  17. if(succState.orientation < 0) {
  18. succState.orientation += 4;
  19. }
  20. succState.orientation %= 4;
  21. break;
  22. case GO:
  23. switch (succState.orientation) {
  24. case 0:
  25. succState.position.y++;
  26. break;
  27. case 1:
  28. succState.position.x++;
  29. break;
  30. case 2:
  31. succState.position.y--;
  32. break;
  33. case 3:
  34. succState.position.x--;
  35. break;
  36. }
  37. break;
  38. case SUCK:
  39. succState.dirt.remove(succState.position.clone());
  40. break;
  41. }
  42. //System.out.println("move: " + a + " -> next state: " + succState);
  43. return succState;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement