Forked from benjaminfspector/Improving the Halite Random Bot (Python 3)
Last active
November 12, 2016 04:17
-
-
Save JCGrant/5ea767bae8a725f738d75649e5f2c91a to your computer and use it in GitHub Desktop.
Halite Random Improvement Sample Code (Python 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This Gist contains the sample code for improving the sample Halite random bot in Python 3. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goes in MyBot.py | |
from hlt import * | |
from networking import * | |
myID, gameMap = getInit() | |
sendInit("MyPythonBot") | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
location = Location(x, y) | |
if gameMap.getSite(location).owner == myID: | |
moves.append(Move(location, random.choice(DIRECTIONS))) | |
sendFrame(moves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goes in MyBot.py | |
from hlt import * | |
from networking import * | |
myID, gameMap = getInit() | |
sendInit("PythonBot") | |
def move(location): | |
site = gameMap.getSite(location) | |
if site.strength == 0: | |
return Move(location, STILL) | |
return Move(location, random.choice(DIRECTIONS)) | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
location = Location(x, y) | |
if gameMap.getSite(location).owner == myID: | |
moves.append(move(location)) | |
sendFrame(moves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goes in MyBot.py | |
from hlt import * | |
from networking import * | |
myID, gameMap = getInit() | |
sendInit("PythonBot") | |
def move(location): | |
site = gameMap.getSite(location) | |
if site.strength < site.production * 5: | |
return Move(location, STILL) | |
return Move(location, random.choice(DIRECTIONS)) | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
location = Location(x, y) | |
if gameMap.getSite(location).owner == myID: | |
moves.append(move(location)) | |
sendFrame(moves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goes in MyBot.py | |
from hlt import * | |
from networking import * | |
myID, gameMap = getInit() | |
sendInit("PythonBot") | |
def move(location): | |
site = gameMap.getSite(location) | |
if site.strength < site.production * 5: | |
return Move(location, STILL) | |
return Move(location, NORTH if random.random() > 0.5 else WEST) | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
location = Location(x, y) | |
if gameMap.getSite(location).owner == myID: | |
moves.append(move(location)) | |
sendFrame(moves) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Goes in MyBot.py | |
from hlt import * | |
from networking import * | |
myID, gameMap = getInit() | |
sendInit("PythonBot") | |
def move(location): | |
site = gameMap.getSite(location) | |
for d in CARDINALS: | |
neighbour_site = gameMap.getSite(location, d) | |
if neighbour_site.owner != myID and neighbour_site.strength < site.strength: | |
return Move(location, d) | |
if site.strength < site.production * 5: | |
return Move(location, STILL) | |
return Move(location, NORTH if random.random() > 0.5 else WEST) | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
location = Location(x, y) | |
if gameMap.getSite(location).owner == myID: | |
moves.append(move(location)) | |
sendFrame(moves) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment