Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node {
- private static int MAX_A = 3;
- private static int MAX_B = 5;
- private static int MAX_C = 8;
- int stateA;
- int stateB;
- int stateC;
- public Node (int a, int b, int c) {
- stateA = a; stateB = b; stateC = c;
- }
- public boolean equalNodes (Node n) {
- if (n.stateA == stateA && n.stateB == stateB && n.stateC == stateC)
- return true;
- else
- return false;
- }
- public Node performAction(int action) {
- int a = stateA;
- int b = stateB;
- int c = stateC;
- int temp = 0;
- switch (action) {
- case 0: return new Node(MAX_A, stateB, stateC);
- case 1: return new Node(stateA, MAX_B, stateC);
- case 2: return new Node(stateA, stateB, MAX_C);
- case 3: return new Node(0, stateB, stateC);
- case 4: return new Node(stateA, 0, stateC);
- case 5: return new Node(stateA, stateB, 0);
- case 6:
- b += stateA;
- if (b > MAX_B) {
- temp = b-MAX_B;
- b = MAX_B;
- }
- a = temp;
- return new Node(a, b, stateC);
- case 7:
- c += stateA;
- if (c > MAX_C) {
- temp = c-MAX_C;
- c = MAX_C;
- }
- a = temp;
- return new Node(a, stateB, c);
- case 8:
- a += stateB;
- if (a > MAX_A) {
- temp = a-MAX_A;
- a = MAX_A;
- }
- b = temp;
- return new Node(a, b, stateC);
- case 9:
- c += stateB;
- if (c > MAX_C) {
- temp = c-MAX_C;
- c = MAX_C;
- }
- b = temp;
- return new Node(stateA, b, c);
- case 10:
- a += stateC;
- if (a > MAX_A) {
- temp = a-MAX_A;
- a = MAX_A;
- }
- c = temp;
- return new Node(a, stateB, c);
- case 11:
- b += stateC;
- if (b > MAX_B) {
- temp = b-MAX_B;
- b = MAX_B;
- }
- c = temp;
- return new Node(stateA, b, c);
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement