public void reValue(Board3D board) { int sum = 0; Node3D tempNode; foreach (Vector3D direction in Vector3D.directions) { if (board.isInBounds(getPosition() + direction)) { tempNode = board.get(getPosition() + direction); if (tempNode is Bridge3D) { if (board.isInBounds(tempNode.getPosition() + ((Bridge3D)tempNode).getDirection()) && board.get(tempNode.getPosition() + ((Bridge3D)tempNode).getDirection()) == this) { sum += ((Bridge3D)board.get(getPosition() + direction)).isDoubleBridge() ? 2 : 1; } if (board.isInBounds(tempNode.getPosition() - ((Bridge3D)tempNode).getDirection()) && board.get(tempNode.getPosition() - ((Bridge3D)tempNode).getDirection()) == this) { sum += ((Bridge3D)board.get(getPosition() + direction)).isDoubleBridge() ? 2 : 1; } } } } value = sum; }
private bool generateNewIsland(Board3D board, List <Island3D> islands, Vector3D direction, Vector3D origin) { Vector3D current = origin + direction; Vector3D lastPossible = null; if (!board.isInBounds(current)) { return(false); } if (!board.canBuildBridge(current)) { return(false); } while (true) { current += direction; if (!board.isInBounds(current)) { return(false); } if (board.canPlaceIsland(current)) { lastPossible = current; if (board.canBuildBridge(current)) { if (Random.Range(0, 2) == 1 ? true : false) { continue; } else { createIsland(board, origin, lastPossible, islands, direction); return(true); } } else { createIsland(board, origin, lastPossible, islands, direction); return(true); } } else if (board.get(current) is Island3D) { return(false); } else if (board.canBuildBridge(current)) { continue; } else if (lastPossible != null) { createIsland(board, origin, lastPossible, islands, direction); return(true); } else { return(false); } } }
public List <Island3D> generateIslands(int x, int y, int z, int number) { Board3D board = generate(x, y, z, number); List <Island3D> islands = new List <Island3D> (); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { for (int k = 0; k < z; k++) { if (board.get(i, j, k) is Island3D) { islands.Add(board.get(i, j, k) as Island3D); ((Island3D)board.get(i, j, k)).reValue(board); } } } } board.display(); return(islands); }