Skip to content

Commit

Permalink
Added turn limit of 1000 and generated image after last turn.
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Hamilton committed Feb 2, 2011
1 parent 6e05fed commit ba11795
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ def switch_players(m, a, b):
ant.owner = a
return m

def save_image(map, turn):
img = map.render()
scale = 4
new_size = (img.size[0] * scale, img.size[1] * scale)
img = img.resize(new_size)
img.save("playback/frame" + str(turn).zfill(5) + ".png")

def play_game(map_filename, players):
m = Map(map_filename)
initial_food_density = 0.01
food_amount = int(initial_food_density * m.land_area)
m.randomly_place_food(food_amount)
turn_count = 1
while not m.game_over():
while not m.game_over() and turn_count < 1000:
print "turn:", turn_count
img = m.render()
scale = 4
new_size = (img.size[0] * scale, img.size[1] * scale)
img = img.resize(new_size)
img.save("playback/frame" + str(turn_count).zfill(5) + ".png")
save_image(m, turn_count)
for i, player in enumerate(players):
player_number = i + 1
reflected_map = switch_players(m, player_number, 1)
Expand All @@ -34,7 +37,8 @@ def play_game(map_filename, players):
m.do_order(order)
m.do_turn()
turn_count += 1
save_image(m, turn_count)

#players = [RandomBot(), RandomBot(), RandomBot(), HunterBot()]
players = [HunterBot(), HunterBot(), HunterBot(), HunterBot()]
play_game("four_map.png", players)
play_game("simple_map_large.png", players)

0 comments on commit ba11795

Please sign in to comment.