Forked from benjaminfspector/Improving the Halite Random Bot (Python 3)
Last active
November 13, 2016 04:18
-
-
Save drryd/a8dd2ac1827f863b5fba78bc84746c4c 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): | |
if gameMap.getSite(Location(x, y)).owner == myID: | |
moves.append(Move(Location(x, y), int(random.random() * 5))) | |
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") | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
if gameMap.getSite(Location(x, y)).owner == myID: | |
if gameMap.getSite(Location(x, y)).strength == 0: | |
moves.append(Move(Location(x, y), STILL)) | |
else: | |
moves.append(Move(Location(x, y), int(random.random() * 5))) | |
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") | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
if gameMap.getSite(Location(x, y)).owner == myID: | |
movedPiece = False | |
if not movedPiece and gameMap.getSite(Location(x, y)).strength < gameMap.getSite(Location(x, y)).production * 5: | |
moves.append(Move(Location(x, y), STILL)) | |
movedPiece = True | |
if not movedPiece: | |
moves.append(Move(Location(x, y), int(random.random() * 5))) | |
movedPiece = True | |
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") | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
if gameMap.getSite(Location(x, y)).owner == myID: | |
movedPiece = False | |
if not movedPiece and gameMap.getSite(Location(x, y)).strength < gameMap.getSite(Location(x, y)).production * 5: | |
moves.append(Move(Location(x, y), STILL)) | |
movedPiece = True | |
if not movedPiece: | |
moves.append(Move(Location(x, y), NORTH if bool(int(random.random() * 2)) else WEST)) | |
movedPiece = True | |
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") | |
while True: | |
moves = [] | |
gameMap = getFrame() | |
for y in range(gameMap.height): | |
for x in range(gameMap.width): | |
if gameMap.getSite(Location(x, y)).owner == myID: | |
movedPiece = False | |
for d in CARDINALS: | |
if gameMap.getSite(Location(x, y), d).owner != myID and gameMap.getSite(Location(x, y), d).strength < gameMap.getSite(Location(x, y)).strength: | |
moves.append(Move(Location(x, y), d)) | |
movedPiece = True | |
break | |
if not movedPiece and gameMap.getSite(Location(x, y)).strength < gameMap.getSite(Location(x, y)).production * 5: | |
moves.append(Move(Location(x, y), STILL)) | |
movedPiece = True | |
if not movedPiece: | |
moves.append(Move(Location(x, y), NORTH if bool(int(random.random() * 2)) else WEST)) | |
movedPiece = True | |
sendFrame(moves) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment