Skip to content

Commit

Permalink
Working tests with winning games!
Browse files Browse the repository at this point in the history
  • Loading branch information
adamf committed Nov 26, 2011
1 parent d6d8d22 commit e13c76a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
7 changes: 0 additions & 7 deletions QEServer/qe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
41 changes: 27 additions & 14 deletions QEServer/tests/test_qe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.