api print, force endgame function, exit timer,

This commit is contained in:
Thefeli73 2020-10-03 16:08:12 +02:00
parent 661d542e79
commit c89e1df0fc
3 changed files with 19 additions and 1 deletions

1
api.py
View File

@ -52,6 +52,7 @@ def end_game(api_key, game_id=None):
sess = requests.Session()
response = sess.get(base_api_path + "end" + game_id, headers={"x-api-key": api_key})
if response.status_code == 200:
print("Game ended succesfully")
return
print("Fatal Error: could not end game")

View File

@ -26,6 +26,12 @@ class GameLayer:
"""
api.end_game(self.api_key, self.game_state.game_id)
def force_end_game(self):
"""
End the current game without gameID
"""
api.end_game(self.api_key)
def start_game(self):
"""
Starts the game.

13
main.py
View File

@ -1,4 +1,6 @@
# import api
import time
from sys import exit
from game_layer import GameLayer
api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3"
@ -10,28 +12,37 @@ useTestStrategy = False
def main():
#game_layer.force_end_game()
game_layer.new_game(map_name)
print("Starting game: " + game_layer.game_state.game_id)
game_layer.start_game()
# exit game after timeout
start_time = time.time()
while game_layer.game_state.turn < game_layer.game_state.max_turns:
take_turn()
time_diff = time.time() - start_time
if time_diff > 5:
game_layer.end_game()
exit()
print("Done with game: " + game_layer.game_state.game_id)
print("Final score was: " + str(game_layer.get_score()["finalScore"]))
def take_turn():
# TODO Implement your artificial intelligence here.
# TODO Take one action per turn until the game ends.
# TODO The following is a short example of how to use the StarterKit
if not useTestStrategy:
state = game_layer.game_state
print("testrunda")
# messages and errors for console log
for message in game_layer.game_state.messages:
print(message)
for error in game_layer.game_state.errors:
print("Error: " + error)
# pre-made test strategy
# which came with
# starter kit