Skip to content

Instantly share code, notes, and snippets.

@hav4ik
Last active January 30, 2021 18:58
Show Gist options
  • Save hav4ik/a6cc1953e1487f224ec6f7d947976c81 to your computer and use it in GitHub Desktop.
Save hav4ik/a6cc1953e1487f224ec6f7d947976c81 to your computer and use it in GitHub Desktop.
Pseudo-python code that shows how you can incorporate the GeoBeeater with your code. This is a mere snippets for you to copy-paste and adapt it to your code.
class YourAgent:
def __init__(self,
# ... other params
# ...
antigeo_thresh=20):
# ...
# Initialize your agent here ...
# ...
# Store our last move
self.latest_action = None
# GeoBeater params
self.antigeo_thresh = antigeo_thresh
if self.antigeo_thresh is not None:
self.geobeater = GeobotBeater()
self.geobeater_score = 0
self.geobeater_last_move = None
self.should_use_geobeater = False
def __call__(self, obs, conf):
# First, update geobot actions before making any changes to self.latest_actions
if self.antigeo_thresh is not None and obs.step > 0:
# Calculate geobeater's score
if self.geobeater_last_move is not None:
if self.geobeater_last_move == (obs.lastOpponentAction + 1) % 3:
self.geobeater_score += 1
elif self.geobeater_last_move == (obs.lastOpponentAction + 2) % 3:
self.geobeater_score -= 1
# Get geobeater's last action
self.geobeater_last_move = self.geobeater(
obs.step, self.latest_action, obs.lastOpponentAction)
# ...
# Make updates to self.last_action here
# ...
# Try to understand if we can use anti-geometric strat (it's very subtle)
if self.antigeo_thresh is not None and obs.step > 0:
# If it's already winning, it is clearly up to something
if (self.geobeater_score >= self.antigeo_thresh and \
self.current_score < self.geobeater_score) or \
self.current_score <= -self.antigeo_thresh:
# Unleash the geobeater forever
self.should_use_geobeater = True
if self.should_use_geobeater:
self.latest_action = self.geobeater_last_move
# Return an action
return self.latest_action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment