Skip to content

Instantly share code, notes, and snippets.

@truell20
Forked from erdman/RandomBot.py
Created December 12, 2016 00:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save truell20/cd964cd3513066b7ff28b7aa5481333b to your computer and use it in GitHub Desktop.
Save truell20/cd964cd3513066b7ff28b7aa5481333b 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