Skip to content

Commit

Permalink
ChFixed so that priority locks down.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgoadric committed Dec 2, 2011
1 parent b621344 commit 10ee1d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 88 deletions.
106 changes: 20 additions & 86 deletions Cube.java
Expand Up @@ -24,6 +24,7 @@ public class Cube {
public static final int ZDOWN = 5;
public static final int NONE = -1;
public static final String[] fnames = {"x+", "x-", "y+", "y-", "z+", "z-"};
public static final int[] opposite ={XDOWN, XUP, YDOWN, YUP, ZDOWN, ZUP};

// Data members
private int[] location;
Expand Down Expand Up @@ -297,10 +298,18 @@ public ArrayList<String> freeFaces() {

public boolean legal() {
// if you are not at Z level 1, you need support.
boolean locked = false;
if (location[Z] > 1) {
String support = getNeighborString(ZDOWN, 1);
if (!board.containsKey(support)) {
return false;
} else {
if ((faces[ZDOWN] == DOME && board.get(support).getFace(ZUP) == EMPTY) ||
(faces[ZDOWN] == EMPTY && board.get(support).getFace(ZUP) == DOME)){
locked = true;
} else {
return false;
}
}
}

Expand All @@ -309,93 +318,18 @@ public boolean legal() {
if (location[Z] == 1 && (firstDome() == ZDOWN || secondDome() == ZDOWN)) {
return false;
}
boolean locked = false;

for (int i = 0; i < faces.length; i++) {
String neighbor = null;
if (i == XUP) {
neighbor = "" + (location[X] + 1) + "," +
location[Y] + "," +
location[Z];
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(XDOWN) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(XDOWN) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(XDOWN) == DOME) {
return false;
}
}
}
if (i == XDOWN) {
neighbor = "" + (location[X] - 1) + "," +
location[Y] + "," +
location[Z];
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(XUP) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(XUP) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(XUP) == DOME) {
return false;
}
}
}
if (i == YUP) {
neighbor = "" + location[X] + "," +
(location[Y] + 1) + "," +
location[Z];
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(YDOWN) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(YDOWN) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(YDOWN) == DOME) {
return false;
}
}
}
if (i == YDOWN) {
neighbor = "" + location[X] + "," +
(location[Y] - 1) + "," +
location[Z];
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(YUP) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(YUP) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(YUP) == DOME) {
return false;
}
}
}
if (i == ZUP) {
neighbor = "" + location[X] + "," +
location[Y] + "," +
(location[Z] + 1);
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(ZDOWN) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(ZDOWN) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(ZDOWN) == DOME) {
return false;
}
}
}
if (i == ZDOWN) {
neighbor = "" + location[X] + "," +
location[Y] + "," +
(location[Z] - 1);
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(ZUP) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(ZUP) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(ZUP) == DOME) {
return false;
}
}
}
String neighbor = getNeighborString(i, 1);
if (board.containsKey(neighbor)) {
if ((faces[i] == DOME && board.get(neighbor).getFace(opposite[i]) == EMPTY) ||
(faces[i] == EMPTY && board.get(neighbor).getFace(opposite[i]) == DOME)){
locked = true;
}
if (faces[i] == DOME && board.get(neighbor).getFace(opposite[i]) == DOME) {
return false;
}
}
}
return locked;
}
Expand Down
4 changes: 2 additions & 2 deletions ShowBoard.java
Expand Up @@ -108,9 +108,9 @@ public ShowBoard(Scanner scan) {
Transform3D transform = new Transform3D();
Box cone = null;
if (color.equals("black")) {
cone = new Box(0.49f, 0.49f, 0.49f, redAppear);
cone = new Box(0.4f, 0.4f, 0.4f, redAppear);
} else {
cone = new Box(0.49f, 0.49f, 0.49f, whiteAppear);
cone = new Box(0.4f, 0.4f, 0.4f, whiteAppear);
}
Vector3f vector = new Vector3f(x, y, z);
transform.setTranslation(vector);
Expand Down

0 comments on commit 10ee1d7

Please sign in to comment.