Skip to content

Instantly share code, notes, and snippets.

@erdman
Last active December 12, 2016 00:28
Show Gist options
  • Save erdman/7fb6b8ec5e3a993c60e4e7a9e170c4d2 to your computer and use it in GitHub Desktop.
Save erdman/7fb6b8ec5e3a993c60e4e7a9e170c4d2 to your computer and use it in GitHub Desktop.
Improving the Halite RandomBot (Python3)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
myID, game_map = hlt.get_init()
hlt.send_init("RandomPythonBot")
while True:
game_map.get_frame()
moves = [Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL))) for square in game_map if square.owner == myID]
hlt.send_frame(moves)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
myID, game_map = hlt.get_init()
hlt.send_init("PythonBot")
def assign_move(square):
if square.strength == 0:
return Move(square, STILL)
else:
return Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL)))
while True:
game_map.get_frame()
moves = [assign_move(square) for square in game_map if square.owner == myID]
hlt.send_frame(moves)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
myID, game_map = hlt.get_init()
hlt.send_init("PythonBot")
def assign_move(square):
if square.strength < 5 * square.production:
return Move(square, STILL)
else:
return Move(square, random.choice((NORTH, EAST, SOUTH, WEST, STILL)))
while True:
game_map.get_frame()
moves = [assign_move(square) for square in game_map if square.owner == myID]
hlt.send_frame(moves)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
myID, game_map = hlt.get_init()
hlt.send_init("PythonBot")
def assign_move(square):
if square.strength < 5 * square.production:
return Move(square, STILL)
else:
return Move(square, random.choice((NORTH, WEST)))
while True:
game_map.get_frame()
moves = [assign_move(square) for square in game_map if square.owner == myID]
hlt.send_frame(moves)
import hlt
from hlt import NORTH, EAST, SOUTH, WEST, STILL, Move, Square
import random
myID, game_map = hlt.get_init()
hlt.send_init("PythonBot")
def assign_move(square):
for direction, neighbor in enumerate(game_map.neighbors(square)):
if neighbor.owner != myID and neighbor.strength < square.strength:
return Move(square, direction)
if square.strength < 5 * square.production:
return Move(square, STILL)
else:
return Move(square, random.choice((NORTH, WEST)))
while True:
game_map.get_frame()
moves = [assign_move(square) for square in game_map if square.owner == myID]
hlt.send_frame(moves)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment