Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class Node {
  2.  
  3. private static int MAX_A = 3;
  4. private static int MAX_B = 5;
  5. private static int MAX_C = 8;
  6.  
  7. int stateA;
  8. int stateB;
  9. int stateC;
  10.  
  11. public Node (int a, int b, int c) {
  12. stateA = a; stateB = b; stateC = c;
  13. }
  14.  
  15. public boolean equalNodes (Node n) {
  16. if (n.stateA == stateA && n.stateB == stateB && n.stateC == stateC)
  17. return true;
  18. else
  19. return false;
  20. }
  21.  
  22. public Node performAction(int action) {
  23.  
  24. int a = stateA;
  25. int b = stateB;
  26. int c = stateC;
  27. int temp = 0;
  28.  
  29. switch (action) {
  30. case 0: return new Node(MAX_A, stateB, stateC);
  31. case 1: return new Node(stateA, MAX_B, stateC);
  32. case 2: return new Node(stateA, stateB, MAX_C);
  33. case 3: return new Node(0, stateB, stateC);
  34. case 4: return new Node(stateA, 0, stateC);
  35. case 5: return new Node(stateA, stateB, 0);
  36. case 6:
  37. b += stateA;
  38. if (b > MAX_B) {
  39. temp = b-MAX_B;
  40. b = MAX_B;
  41. }
  42. a = temp;
  43.  
  44. return new Node(a, b, stateC);
  45. case 7:
  46. c += stateA;
  47. if (c > MAX_C) {
  48. temp = c-MAX_C;
  49. c = MAX_C;
  50. }
  51. a = temp;
  52.  
  53. return new Node(a, stateB, c);
  54. case 8:
  55. a += stateB;
  56. if (a > MAX_A) {
  57. temp = a-MAX_A;
  58. a = MAX_A;
  59. }
  60. b = temp;
  61.  
  62. return new Node(a, b, stateC);
  63. case 9:
  64. c += stateB;
  65. if (c > MAX_C) {
  66. temp = c-MAX_C;
  67. c = MAX_C;
  68. }
  69. b = temp;
  70.  
  71. return new Node(stateA, b, c);
  72. case 10:
  73. a += stateC;
  74. if (a > MAX_A) {
  75. temp = a-MAX_A;
  76. a = MAX_A;
  77. }
  78. c = temp;
  79.  
  80. return new Node(a, stateB, c);
  81. case 11:
  82. b += stateC;
  83. if (b > MAX_B) {
  84. temp = b-MAX_B;
  85. b = MAX_B;
  86. }
  87. c = temp;
  88.  
  89. return new Node(stateA, b, c);
  90. }
  91. return null;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement