summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpygame_snake.py22
-rw-r--r--snake.py7
2 files changed, 19 insertions, 10 deletions
diff --git a/pygame_snake.py b/pygame_snake.py
index dece4a4..c2ac323 100755
--- a/pygame_snake.py
+++ b/pygame_snake.py
@@ -40,7 +40,9 @@ class PygameSnakeEngine(SnakeEngine):
EDGE_COLOR = (255, 255, 255)
EDGE_WIDTH = 1
- def __init__(self, rows, columns, n_apples, width=800, height=600, fullscreen=False):
+ def __init__(self, rows, columns, n_apples,
+ width=800, height=600, fullscreen=False,
+ **kwargs):
flags = 0
if fullscreen:
flags |= pygame.FULLSCREEN
@@ -49,7 +51,8 @@ class PygameSnakeEngine(SnakeEngine):
self.width = width
self.height = height
- super(PygameSnakeEngine, self).__init__(rows, columns, n_apples)
+ super(PygameSnakeEngine, self).__init__(rows, columns, n_apples,
+ **kwargs)
def new_game(self, rows, columns, n_apples):
super(PygameSnakeEngine, self).new_game(rows, columns, n_apples)
@@ -140,11 +143,12 @@ if __name__ == '__main__':
from bots import *
from oldbot import BotWrapper
- game = PygameSnakeEngine(25, 25, 50)
- game.add_bot(right_bot)
- game.add_bot(random_bot)
- game.add_bot(random_bounds_bot)
- game.add_bot(random_square_bot)
- game.add_bot(BotWrapper('oldbots/peter.py'))
- game.run()
+ while True:
+ game = PygameSnakeEngine(25, 25, 50, results=True)
+ game.add_bot(right_bot)
+ game.add_bot(random_bot)
+ game.add_bot(random_bounds_bot)
+ game.add_bot(random_square_bot)
+ game.add_bot(BotWrapper('oldbots/peter.py'))
+ game.run()
diff --git a/snake.py b/snake.py
index 022f897..3a286e7 100644
--- a/snake.py
+++ b/snake.py
@@ -2,8 +2,10 @@
from __future__ import division
+import sys
import time
import string
+import random
from random import randint
from collections import deque
from copy import deepcopy
@@ -18,6 +20,8 @@ class SnakeEngine(object):
self.letters = list(string.lowercase)
self.letters.reverse()
+ self.game_id = random.randint(0, sys.maxint)
+
self.bots = {}
self.results = None
if results:
@@ -91,7 +95,8 @@ class SnakeEngine(object):
pass
else:
apple_score = len(bot[2])
- self.results.write('%s,%s,%s\n' % (name, apple_score, time_score))
+ self.results.write('%s,%s,%s,%s\n' % \
+ (self.game_id, name, apple_score, time_score))
self.results.flush()
def update_snakes(self, directions_id=id(directions)):