Robot Rumble ALPHA
discord
try it!
boards
tutorial
docs
login
/
signup
import random def robot(state, unit): ally_units = state.objs_by_team(state.our_team) enemy_units = state.objs_by_team(state.other_team) self_coords = unit.coords dirs = ((1, 0, Direction.East), (0, 1, Direction.South), (-1, 0, Direction.West), (0, -1, Direction.North)) board_len = 19; def construct_grid(): grid = [[0 for j in range(board_len)] for i in range(board_len)] for i in range(board_len): grid[0][i] = 3; grid[board_len - 1][i] = 3; grid[i][0] = 3; grid[i][board_len - 1] = 3; for k in range(1, 6): for i in range(k): x_len = i; y_len = k - i; grid[x_len][y_len] = 3; grid[board_len - x_len - 1][y_len] = 3; grid[x_len][board_len - y_len - 1] = 3; grid[board_len - x_len - 1][board_len - y_len - 1] = 3; for unit in ally_units: coords = unit.coords grid[coords[0]][coords[1]] = 1 for unit in enemy_units: coords = unit.coords grid[coords[0]][coords[1]] = 2 return grid grid = construct_grid() def flee(): candidate_dirs = [] for d in dirs: x = d[0] + self_coords[0]; y = d[1] + self_coords[1]; if grid[x][y] == 0: candidate_dirs.append(d[2]) return Action.move(random.choice(candidate_dirs)) def attack(): direction = Direction.North min_dist = 500 for unit in enemy_units: coords = unit.coords dist = self_coords.walking_distance_to(coords) if dist < min_dist: min_dist = dist direction = self_coords.direction_to(coords) if min_dist == 1: return Action.attack(direction) return Action.move(direction) #attack if surrounded attack_dir = None enemy_surr_cnt = 0 surr_cnt = 0 for d in dirs: x = d[0] + self_coords[0]; y = d[1] + self_coords[1]; if grid[x][y] != 0: surr_cnt += 1 if grid[x][y] == 2: enemy_surr_cnt += 1 attack_dir = d[2] if surr_cnt == 4 and attack_dir: return Action.attack(attack_dir) if unit.health > 1 and enemy_surr_cnt < 2: return attack() else: return flee()
Made with <3 by Anton and Noa
github org