Last active
November 13, 2016 04:25
-
-
Save benjaminfspector/73cd76d10de7e5147d7e0b49eb65f288 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: | |
movedPiece = False | |
if not movedPiece and gameMap.getSite(Location(y, x)).strength == 0: | |
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), 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
Minor Fix to Revision1.py in my fork -- Fix coordinate from (y, x) to (x, y) and remove unnecessary variable.