Skip to content

Instantly share code, notes, and snippets.

@Sohaib03
Created March 24, 2020 13:32
Show Gist options
  • Save Sohaib03/2dffc5adb384ba0a035753d719ff7ec0 to your computer and use it in GitHub Desktop.
Save Sohaib03/2dffc5adb384ba0a035753d719ff7ec0 to your computer and use it in GitHub Desktop.
import sys
import math
# Deliver more amadeusium to hq (left side of the map) than your opponent. Use radars to find amadeusium but beware of traps!
# height: size of the map
def debug(*args):
for i in args:
print(i, file = 'sys.stderr')
width, height = [int(i) for i in input().split()]
NONE = -1
ROBOT_ALLY = 0
ROBOT_ENEMY = 1
HOLE = 1
RADAR = 2
TRAP = 3
AMADEUSIUM = 4
class Pos:
def __init__(self, x, y):
self.x = x
self.y = y
def distance(self, pos):
return abs(self.x - pos.x) + abs(self.y - pos.y)
class Entity(Pos):
def __init__(self, x, y, type, id):
super().__init__(x, y)
self.type = type
self.id = id
class Robot(Entity):
command = str()
def __init__(self, x, y, type, id, item):
super().__init__(x, y, type, id)
self.item = item
def is_dead(self):
return self.x == -1 and self.y == -1
def move(x, y, message=""):
self.command = f"MOVE {x} {y} {message}"
def wait(message=""):
self.command = f"WAIT {message}"
def dig(x, y, message=""):
self.command = f"DIG {x} {y} {message}"
def request(requested_item, message=""):
if requested_item == RADAR:
self.command = f"REQUEST RADAR {message}"
elif requested_item == TRAP:
self.command = f"REQUEST TRAP {message}"
else:
raise Exception(f"Unknown item {requested_item}")
def get_pos(self):
return [self.x, self.y]
def execute(self):
if self.command:
print(self.command)
else:
print("WAIT (by default waiting)")
class Cell(Pos):
def __init__(self, x, y, amadeusium, hole):
super().__init__(x, y)
self.amadeusium = amadeusium
self.hole = hole
def has_hole(self):
return self.hole == HOLE
def update(self, amadeusium, hole):
self.amadeusium = amadeusium
self.hole = hole
class Grid:
def __init__(self):
self.cells = []
for y in range(height):
for x in range(width):
self.cells.append(Cell(x, y, 0, 0))
def get_cell(self, x, y):
if width > x >= 0 and height > y >= 0:
return self.cells[x + width * y]
return None
class Game:
def __init__(self):
self.grid = Grid()
self.my_score = 0
self.enemy_score = 0
self.radar_cooldown = 0
self.trap_cooldown = 0
self.radars = []
self.traps = []
self.my_robots = []
self.enemy_robots = []
def reset(self):
self.radars = []
self.traps = []
self.enemy_robots = []
game = Game()
# game loop
while True:
# my_score: Players score
game.my_score, game.enemy_score = [int(i) for i in input().split()]
for i in range(height):
inputs = input().split()
for j in range(width):
# amadeusium: amount of amadeusium or "?" if unknown
# hole: 1 if cell has a hole
amadeusium = inputs[2 * j]
hole = int(inputs[2 * j + 1])
game.grid.get_cell(j, i).update(amadeusium, hole)
# entity_count: number of entities visible to you
# radar_cooldown: turns left until a new radar can be requested
# trap_cooldown: turns left until a new trap can be requested
entity_count, game.radar_cooldown, game.trap_cooldown = [int(i) for i in input().split()]
game.reset()
for i in range(entity_count):
# id: unique id of the entity
# type: 0 for your robot, 1 for other robot, 2 for radar, 3 for trap
# y: position of the entity
# item: if this entity is a robot, the item it is carrying (-1 for NONE, 2 for RADAR, 3 for TRAP, 4 for AMADEUSIUM)
id, type, x, y, item = [int(j) for j in input().split()]
if type == ROBOT_ALLY:
game.my_robots.append(Robot(x, y, type, id, item))
elif type == ROBOT_ENEMY:
game.enemy_robots.append(Robot(x, y, type, id, item))
elif type == TRAP:
game.traps.append(Entity(x, y, type, id))
elif type == RADAR:
game.radars.append(Entity(x, y, type, id))
for i in range(len(game.my_robots)):
game.my_robots[i].execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment