//hexBoard.java import java.util.*; import java.io.*; //import java.awt.*; //For graphics (later) //import java.applet.*; class occupantType { private int kindOf; occupantType(){ kindOf = 0; } occupantType(int a){ kindOf = a; } boolean equalsTo(occupantType fake){ if (fake.kindOf == this.kindOf) return true; else return false; } boolean isEmpty(){ if (kindOf == 0) return true; else return false; } public String toString(){ String result; switch(kindOf){ case 0: {result = " . "; break;} case 1: {result = " V "; break;} case 2: {result = " H "; break;} default: {result = "-E-"; break;} } return result; } static occupantType EMPTY = new occupantType(0); static occupantType VERT = new occupantType(1); static occupantType HORZ = new occupantType(2); } class coords { int x; int y; coords(){ x = 0; y = 0; } coords(int a, int b){ x = a; y = b; } } class Move { occupantType theMover; coords hex; Move(){} Move(int a, int b){ hex = new coords(a,b); } Move(coords there){ hex = new coords(there.x, there.y); } Move(occupantType it, coords there){ theMover = it; hex = new coords(there.x, there.y); } coords getCoords(){ return hex; } occupantType getMover(){ return theMover; } public String toString(){ String result = new String(); result = hex.y + "-" + hex.x; return result; } } class testSquare { occupantType contains; boolean connected; boolean tested; testSquare(){ this(occupantType.EMPTY, false, false); } testSquare(occupantType typeOf, boolean toTop, boolean isTested){ contains = typeOf; connected = toTop; tested = isTested; } testSquare(int typeOf, boolean toTop, boolean isTested){ contains = new occupantType(typeOf); connected = toTop; tested = isTested; } void untest(){ tested = false; } void markTested(){ tested = true; } void put(occupantType c){ contains = c; } } class hexBoard{ int SIZE; testSquare board[][]; hexBoard(){ this(15); } hexBoard(int largeness){ if (largeness < 1) largeness = 15; board = new testSquare[largeness][largeness]; SIZE = largeness; makeBlankBoard(); } void makeBlankBoard(){ int i, j; for (i=0; i=SIZE || l>=SIZE) continue; //Make sure the indices are in the valid range. if (board[k][l].contains == side && board[k][l].tested == false) { if (directionConnected(k, l, side)) { result = true; break; } } } } return result; } public boolean isWon(occupantType side) { int otherEdge, j; boolean result = false; otherEdge = SIZE - 1; for(j=0; j < SIZE; j++) { if (side == occupantType.VERT){ if(board[otherEdge][j].contains == occupantType.VERT && board[otherEdge][j].tested == false) { //We have to test whether the bottom is connected to the top. if(directionConnected(otherEdge, j, side)) { result = true; break; } } } else { if(board[j][otherEdge].contains == occupantType.HORZ && board[j][otherEdge].tested == false) { //We have to test whether the bottom is connected to the top. if(directionConnected(j, otherEdge, side)) { result = true; break; } } } } return result; } public void displayHexBoard() { int i, j; int k; for(i=0;i