Permalink
Browse files

Working tests with winning games!

  • Loading branch information...
adamf committed Nov 26, 2011
1 parent d6d8d22 commit e13c76a1fad533ec736c01355bbd2a7ec796c267
Showing with 27 additions and 21 deletions.
  1. +0 −7 QEServer/qe.py
  2. +27 −14 QEServer/tests/test_qe.py
View
@@ -35,13 +35,6 @@ def main():
application = tornado.web.Application([
-####
-# Need to add: map generation, map data model, retrieving an old
-# game from the server (w/ map & state), creating a game, starting
-# a game, taking turns, inviting users to play the game, handling
-# winning and losing, notifing the players of their turn happening.
-####
-
# REST interface, everything under /api
# user managment
(r"/api/signupnewplayer", json.SignUpNewPlayerHandler, dg),
View
@@ -26,6 +26,7 @@ def __init__(self, _host, _port):
self.dir_y = 1
self.y = -1
self.gid = ""
+ self.turn = 0
def do_get(self, path, qstring):
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
@@ -71,7 +72,7 @@ def creategame(self, players):
params = {'players': tornado.escape.json_encode(players),
'map_width': 5,
'map_height': 5,
- 'planet_percentage': 50,
+ 'planet_percentage': 20,
'mean_uranium': 100,
'mean_planet_lifetime': 100,
'starting_uranium': 4000
@@ -91,6 +92,7 @@ def getstatus(self):
self.y = status["my_state"]["yLocation"]
self.myturn = status["my_turn"]
print status
+ return status["whose_turn"]["id"]
def loadgame(self):
json = self.do_get("/api/loadgame", "game_id=" + str(self.gid))
@@ -141,7 +143,7 @@ def move(self):
self.x = params['new_x']
self.y = params['new_y']
- if move_state["planet"] != []:
+ if move_state["status"] == "ok" and move_state["planet"] != []:
return move_state["planet"]["id"]
return None
@@ -183,20 +185,31 @@ def buyplanet(self, planetid):
won_game = False
turn_count = 0
+ whose_turn = players[0].getstatus()
+
while not won_game and turn_count < 400:
turn_count = turn_count + 1
print turn_count
- for player in players:
- player.getstatus()
- if player.myturn:
- won_game = player.startturn()
- if won_game:
- print "We have a winner!", player.pid
- exit(1)
- has_planet = player.move()
- while not has_planet:
- has_planet = player.move()
+ played = 0
+ while played < len(players):
+ for player in players:
+ if player.pid == whose_turn:
+ won_game = player.startturn()
+ if won_game:
+ print "We have a winner!", player.pid
+ exit(1)
- player.buyplanet(has_planet)
- player.endturn()
+ has_planet = player.move()
+ move_count = 0
+ while not has_planet and move_count < 10:
+ move_count = move_count + 1
+ has_planet = player.move()
+
+ if move_count < 10:
+ player.buyplanet(has_planet)
+
+ player.endturn()
+ whose_turn = player.getstatus()
+ played = played + 1
+ break

0 comments on commit e13c76a

Please sign in to comment.