Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions scripts/CommsHandlerTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ public class MapSymmetry {
public class ControlStatus {
public static final int UNKNOWN = 0;
public static final int OURS = 1;
public static final int THEIRS = 2;
public static final int EXPLORING = 3;
public static final int EXPLORING = 2;
public static final int MINOR_ENEMY = 3;
public static final int MEDIUM_ENEMY = 4;
public static final int MAJOR_ENEMY = 5;
// Enemy_offset = first status representing enemy control
public static final int ENEMY_OFFSET = 3;
public static final int CLUSTER_ENEMY_LEVELS = 3;
}
public class ClaimStatus {
public static final int UNCLAIMED = 0;
Expand Down
31 changes: 13 additions & 18 deletions scripts/generate_comms_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
'y_coord': 6,
}
},
'miner_count': { # make sure this is in a single int
'slots': 1,
'bits': {
'': 8,
}
},
'soldier_count': { # mamke sure this is in a single int
'slots': 1,
'bits': {
'': 8,
}
},
'cluster': {
'slots': 100,
'bits': {
Expand All @@ -20,6 +32,7 @@
'combat_cluster': {
'slots': 10,
'bits': {
'priority': 2,
'index': 7,
}
},
Expand All @@ -37,24 +50,6 @@
'index': 7,
}
},
'filler_do_not_use': {
'slots': 1,
'bits': {
'': 6,
}
},
'miner_count': { # make sure this is in a single int
'slots': 1,
'bits': {
'': 8,
}
},
'soldier_count': { # mamke sure this is in a single int
'slots': 1,
'bits': {
'': 8,
}
},
'last_archon': {
'slots': 1,
'bits': {
Expand Down
58 changes: 48 additions & 10 deletions src/ares/Archon.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class Archon extends Robot {
int minerCount = 0;
int soldierCount = 0;

// Start and end indices for resetting
int startResetCluster = 0;

boolean archonZeroAlive = true;
boolean archonOneAlive = true;
boolean archonTwoAlive = true;
Expand Down Expand Up @@ -79,6 +82,8 @@ public void runUnit() throws GameActionException {

build();
repair();

resetClusterControlStatus();
}

public void updateUnitCounts() throws GameActionException {
Expand All @@ -94,6 +99,15 @@ public void updateUnitCounts() throws GameActionException {
}
}

public boolean isTheirs(int controlStatus) {
if (controlStatus == CommsHandler.ControlStatus.MINOR_ENEMY ||
controlStatus == CommsHandler.ControlStatus.MEDIUM_ENEMY ||
controlStatus == CommsHandler.ControlStatus.MAJOR_ENEMY) {
return true;
}
return false;
}

/**
* Sets initial explore clusters
*
Expand Down Expand Up @@ -162,9 +176,8 @@ public void setPriorityClusters() throws GameActionException {

// String status = "";
// for (int i = 0; i < commsHandler.COMBAT_CLUSTER_SLOTS; i++) {
// int cluster = commsHandler.readCombatClusterIndex(i);
// status += " " + cluster + "(" +
// commsHandler.readClusterControlStatus(cluster) + ")";
// int cluster = commsHandler.readCombatClusterIndex(i);
// status += " " + cluster + "(" + commsHandler.readClusterControlStatus(cluster) + ")";
// }
// System.out.println("Combat"+status);
// String status = "";
Expand All @@ -189,7 +202,7 @@ public void setPriorityClusters() throws GameActionException {
if (cluster == commsHandler.UNDEFINED_CLUSTER_INDEX) {
continue;
}
if (commsHandler.readClusterControlStatus(cluster) != CommsHandler.ControlStatus.THEIRS) {
if (!isTheirs(commsHandler.readClusterControlStatus(cluster))) {
commsHandler.writeCombatClusterIndex(i, commsHandler.UNDEFINED_CLUSTER_INDEX);
}
}
Expand All @@ -201,7 +214,7 @@ public void setPriorityClusters() throws GameActionException {
}
int resourceCount = commsHandler.readClusterResourceCount(cluster);
int controlStatus = commsHandler.readClusterControlStatus(cluster);
if (resourceCount == 0 || controlStatus == CommsHandler.ControlStatus.THEIRS) {
if (resourceCount == 0 || isTheirs(controlStatus)) {
commsHandler.writeMineClusterIndex(i, commsHandler.UNDEFINED_CLUSTER_INDEX);
} else {
commsHandler.writeMineClusterClaimStatus(i, resourceCount / 4);
Expand All @@ -218,8 +231,8 @@ public void setPriorityClusters() throws GameActionException {
int nearestClusterStatus = (nearestClusterAll & 128) >> 7; // 2^7
int controlStatus = commsHandler.readClusterControlStatus(nearestCluster);
if (nearestClusterStatus == CommsHandler.ClaimStatus.CLAIMED
|| controlStatus == CommsHandler.ControlStatus.OURS
|| controlStatus == CommsHandler.ControlStatus.THEIRS) {
|| controlStatus == CommsHandler.ControlStatus.OURS
|| isTheirs(controlStatus)) {
// Also resets claimed/unclaimed bit to unclaimed
commsHandler.writeExploreClusterAll(i, commsHandler.UNDEFINED_CLUSTER_INDEX);
}
Expand Down Expand Up @@ -280,8 +293,8 @@ public void setPriorityClusters() throws GameActionException {
int resourceCount = commsHandler.readClusterResourceCount(i);
resourcesOnMap += resourceCount * LEAD_RESOLUTION;
// Combat cluster
if (combatClusterIndex < commsHandler.COMBAT_CLUSTER_SLOTS
&& controlStatus == CommsHandler.ControlStatus.THEIRS) {
if (combatClusterIndex < commsHandler.COMBAT_CLUSTER_SLOTS
&& isTheirs(controlStatus)) {
// Verify cluster is not already in comms list
boolean isValid = true;
for (int j = 0; j < commsHandler.COMBAT_CLUSTER_SLOTS; j++) {
Expand All @@ -292,6 +305,8 @@ public void setPriorityClusters() throws GameActionException {
}
if (isValid) {
commsHandler.writeCombatClusterIndex(combatClusterIndex, i);
// Writes a 0 for miners, 1 for 1 soldier, 2 for multi-soldiers.
commsHandler.writeCombatClusterPriority(combatClusterIndex, controlStatus - CommsHandler.ControlStatus.ENEMY_OFFSET);
combatClusterIndex++;

// Preserve combat clusters which still have enemies
Expand All @@ -306,7 +321,7 @@ public void setPriorityClusters() throws GameActionException {
}
// Mine cluster
if (mineClusterIndex < commsHandler.MINE_CLUSTER_SLOTS && resourceCount > 0
&& controlStatus != CommsHandler.ControlStatus.THEIRS) {
&& isTheirs(controlStatus)) {
// Verify cluster is not already in comms list
boolean isValid = true;
for (int j = 0; j < commsHandler.MINE_CLUSTER_SLOTS; j++) {
Expand Down Expand Up @@ -363,6 +378,29 @@ public void setPriorityClusters() throws GameActionException {
// exploreClusterIndex);
}


public void resetClusterControlStatus() throws GameActionException {
int frequency = 4;
if (!lastArchon) {
return;
}
int nbl = Clock.getBytecodesLeft() / 200;
int endResetCluster = Math.min(startResetCluster + numClusters/frequency, numClusters);
endResetCluster = Math.min(startResetCluster + nbl, endResetCluster);
int diff = endResetCluster - startResetCluster;
System.out.println("indices: " + startResetCluster + " " + endResetCluster);
System.out.println("RESETTTING: " + diff);

for (int i=startResetCluster; i < endResetCluster; i++) {
commsHandler.writeClusterControlStatus(i, 0);
}
if (endResetCluster == numClusters) {
startResetCluster = 0;
} else {
startResetCluster = endResetCluster;
}
}

/**
* Builds a unit
*
Expand Down
Loading