public void makeMove(AvailableLocation al) { int x = al.getX(); int y = al.getY(); int[] compass = al.getCompass(); placeToken(x, y, currentPlayer); for (int i = 0; i < 8; i++) { makeMoveHelper(x, y, i, compass[i]); } }
// once an empty space around a opposites players peice is found, this function // looks for valid moves and make an entry in the valid moves array. private void availbleLocationHelper(int x, int y) { int compass[] = new int[8]; AvailableLocation newLoc; // boolean e, ne, n, nw, w, sw, s, se; // e = ne = n = nw = w = sw = s = se = true; // Checks for board boundries for (int i = 0; i < 8; i++) { compass[i] = 0; } if (x + 1 >= size) { // ne = e = se = false; compass[7]--; compass[0]--; compass[1]--; } if (y - 1 < 0) { // nw = n = ne = false; compass[1]--; compass[2]--; compass[3]--; } if (x - 1 < 0) { // nw = w = sw = false; compass[3]--; compass[4]--; compass[5]--; } if (y + 1 >= size) { // sw = s = se = false; compass[5]--; compass[6]--; compass[7]--; } // Validation if (compass[0] == 0) { compass[0] = testE(x, y); } if (compass[1] == 0) { compass[1] = testNE(x, y); } if (compass[2] == 0) { compass[2] = testN(x, y); } if (compass[3] == 0) { compass[3] = testNW(x, y); } if (compass[4] == 0) { compass[4] = testW(x, y); } if (compass[5] == 0) { compass[5] = testSW(x, y); } if (compass[6] == 0) { compass[6] = testS(x, y); } if (compass[7] == 0) { compass[7] = testSE(x, y); } newLoc = new AvailableLocation(x, y, compass); if (newLoc.getCompassTotal() > 0) validLoc.add(newLoc); }