import Turtle; class DanceMove implements Comparable{ public int move; private int qual; //create a random move public DanceMove() { int h = 0; for ( int i=0; i<8; i++) { int r = (int)(Math.random()*16); h= h<<4 | r; } move = h; } //do a particular motion from a move public static void move(int x) throws InterruptedException { if (x==0){Turtle.forward(300); }else if (x==1) {Turtle.backward(300); }else if (x==2) {Turtle.turn(-150); }else if (x==3) {Turtle.turn(-90); Turtle.turn(180); }else if (x==4) {Turtle.forward(10); Turtle.stop(); Turtle.forward(10); }else if (x==5) {Turtle.turn(20); }else if (x==6) {Turtle.turn(180); Turtle.backward(200); Turtle.stop(); }else if (x==7) {Turtle.turn(-15); }else if (x==8) {Turtle.turn(150); }else if (x==9) {Turtle.turn(-20); }else if (x==10) {Turtle.forward(175); Turtle.turn(-360); }else if (x==11) {Turtle.turn(4); }else if (x==12) {Turtle.stop(); Turtle.stop(); Turtle.stop(); }else if (x==13) {Turtle.turn(30); }else if (x==14) {Turtle.forward(40); Turtle.turn(180); Turtle.forward(40); Turtle.turn(180); }else if (x==15) {Turtle.turn(-45); Turtle.turn(180); Turtle.backward(100); Turtle.stop(); } } //returns the integer that represents move public int moveIs(){ return this.move; } //does the move piece by piece public void doMove() throws InterruptedException { int moveA = this.move; // breaks the integer down byte by byte to do moves. for(int i=0; i<8; i++){ int y = (moveA & 0xF); // y is the rightmost "nibble" of combo move(y); moveA = moveA >>4; // eliminate that nibble by right shifting } } //sets the quality of the move public void setQuality(int i){ qual = i; } //returns the quality of the move public int getQuality(){ return this.qual; } //tests to see if a move is the same as another public boolean equals(DanceMove d){ int thismove = this.move; int thatmove = d.move; boolean value = true; for(int i=0; i<8; i++){ int thisy = (thismove & 0xF); // y is the rightmost "nibble" of combo int thaty = (thatmove & 0xF); if(thisy != thaty) value = false; thismove = thismove >>4; // eliminate that nibble by right shifting thismove = thismove >>4; } return value; } //used for comparing items public int compareTo(Object x){ DanceMove d = (DanceMove)x; if(d.getQuality() == this.qual) return 0; else if(d.getQuality() > this.qual) return 1; else return -1; } }