From c89e1df0fc6d77bd70c990d045312c5987bd912d Mon Sep 17 00:00:00 2001 From: Thefeli73 Date: Sat, 3 Oct 2020 16:08:12 +0200 Subject: [PATCH] api print, force endgame function, exit timer, --- api.py | 1 + game_layer.py | 6 ++++++ main.py | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 2306ed3..be881f9 100644 --- a/api.py +++ b/api.py @@ -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") diff --git a/game_layer.py b/game_layer.py index 3f555c0..8dc75d4 100644 --- a/game_layer.py +++ b/game_layer.py @@ -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. diff --git a/main.py b/main.py index a9abcf1..612c45f 100644 --- a/main.py +++ b/main.py @@ -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