use of ww.Point in project cg by nmahoude.
the class Divination method removeMyVision.
private long removeMyVision(GameState state, long potential) {
// remove my vision
for (int id = 0; id < 2; id++) {
Agent agent = state.agents[id];
// remove the point
potential &= ~agent.position.mask;
for (int i = 0; i < Dir.LENGTH; i++) {
Cell around = agent.cell.neighbors[i];
if (around != Cell.InvalidCell) {
// remove the point
potential &= ~around.position.mask;
}
}
}
return potential;
}
use of ww.Point in project cg by nmahoude.
the class Divination method getCorrectInformationsFromCurrentStateOrLockedAgents.
private void getCorrectInformationsFromCurrentStateOrLockedAgents(GameState state) {
for (int i = 0; i < 2; i++) {
if (state.agents[2 + i].position != Point.unknown) {
if (guessedPosition[1 - i] == state.agents[2 + i].position) {
// we had inversed the agents, correct error now
guessedPosition[1 - i] = guessedPosition[i];
guessedPositionLocked[1 - i] = guessedPositionLocked[i];
}
// save the point but we know it
guessedPosition[i] = state.agents[2 + i].position;
guessedPositionLocked[i] = isLocked(state.agents[2 + i]);
if (debugMode)
System.err.println("CG Info : set " + i + " @ " + guessedPosition[i]);
stillToFind--;
} else {
if (guessedPositionLocked[i] == true) {
if (debugMode)
System.err.println("CG Info & locked " + i + " @ " + guessedPosition[i]);
stillToFind--;
} else {
guessedPosition[i] = Point.unknown;
}
}
}
}
use of ww.Point in project cg by nmahoude.
the class Oracle method checkForMove.
private void checkForMove(GameState currentState, Cell locatedConstruction) {
HashSet<Point>[] possibilitiesByAgent = (HashSet<Point>[]) new HashSet[4];
possibilitiesByAgent[2] = bruteForce(currentState, 2, formerPossiblePositions[2], locatedConstruction.position);
if (possibilitiesByAgent[2].contains(locatedConstruction)) {
possibilitiesByAgent[2].remove(locatedConstruction);
}
possibilitiesByAgent[3] = bruteForce(currentState, 3, formerPossiblePositions[3], locatedConstruction.position);
if (possibilitiesByAgent[3].contains(locatedConstruction)) {
possibilitiesByAgent[3].remove(locatedConstruction);
}
// if agents was seen and is still seen and didn't move, it's cant be him
for (int id = 2; id < 4; id++) {
if (hasBeenStill(currentState, id)) {
possibilitiesByAgent[id].clear();
}
if (hasMoved(currentState, id) || locatedConstruction.position == formerSimulatedState.agents[id].position) {
possibilitiesByAgent[theOtherId(id)].clear();
}
}
int count = (possibilitiesByAgent[2].size() != 0 ? 1 : 0) + (possibilitiesByAgent[3].size() != 0 ? 1 : 0);
if (count == 0) {
debugException(currentState, locatedConstruction, possibilitiesByAgent);
if (!PROD) {
throw new RuntimeException("Nobody in the range to make the move !");
} else {
fillAllPossiblePositions(currentState, possiblePositions[2]);
fillAllPossiblePositions(currentState, possiblePositions[3]);
}
} else if (count == 1) {
int id = possibilitiesByAgent[2].size() > 0 ? 2 : 3;
if (!currentState.agents[id].inFogOfWar()) {
possiblePositions[id].add(currentState.agents[id].position);
} else {
possiblePositions[id].addAll(possibilitiesByAgent[id]);
}
possiblePositions[theOtherId(id)].addAll(formerPossiblePositions[theOtherId(id)]);
} else {
// on ne sait pas qui a fait quoi, donc on doit ajouter toutes les cellules possibles aux 2 agents :(
possiblePositions[2].addAll(formerPossiblePositions[2]);
possiblePositions[3].addAll(formerPossiblePositions[3]);
for (int i = 0; i < 8; i++) {
Cell cellToCheck = locatedConstruction.neighbors[i];
if (!cellToCheck.isValid())
continue;
if (canSeeCell(currentState.agents[0], cellToCheck))
continue;
if (canSeeCell(currentState.agents[1], cellToCheck))
continue;
possiblePositions[2].add(cellToCheck.position);
possiblePositions[3].add(cellToCheck.position);
}
}
}
use of ww.Point in project cg by nmahoude.
the class Oracle method fillAllPossiblePositions.
public static void fillAllPossiblePositions(GameState state, Set<Point> pos) {
pos.clear();
for (int y = 0; y < GameState.size; y++) {
for (int x = 0; x < GameState.size; x++) {
Cell cell = state.grid.get(x, y);
if (!cell.isValid())
continue;
pos.add(cell.position);
}
}
}
use of ww.Point in project cg by nmahoude.
the class Oracle method apply.
// ----- old
/**
* Apply the Oracle
* @param state
*/
public void apply(GameState state) {
for (int id = 2; id < 4; id++) {
if (!state.agents[id].inFogOfWar()) {
possiblePositions[id].clear();
possiblePositions[id].add(state.agents[id].position);
} else if (possiblePositions[id].size() == 1) {
Point p = possiblePositions[id].iterator().next();
state.positionAgent(state.agents[id], p);
} else {
if (debugMode)
System.err.println("We don't know where the agent " + id + " is but he is in " + possiblePositions[id]);
// heightest place for unknown enemy
if (possiblePositions[id].size() > 0) {
int bestHeigh = -1;
Point bestPoint = null;
for (Point p : possiblePositions[id]) {
Cell cell = state.grid.get(p);
if (cell.height != 4 && cell.height > bestHeigh) {
bestHeigh = cell.height;
bestPoint = p;
}
}
state.positionAgent(state.agents[id], bestPoint);
}
}
}
}