From bd762a970f61df7ecb39db98ab9b5142cc3f2036 Mon Sep 17 00:00:00 2001 From: linhara Date: Sat, 3 Oct 2020 14:29:47 +0200 Subject: [PATCH 1/5] ignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 1b05740..359a063 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ __pycache__/ + +venv/ + +.idea/ From 9f318dac4708045a18493bc5252fec54c163cfc7 Mon Sep 17 00:00:00 2001 From: linhara Date: Sat, 3 Oct 2020 14:31:57 +0200 Subject: [PATCH 2/5] sak --- .idea/Considition-2020.iml | 5 +++-- .idea/misc.xml | 4 ---- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/Considition-2020.iml b/.idea/Considition-2020.iml index d0876a7..49018d0 100644 --- a/.idea/Considition-2020.iml +++ b/.idea/Considition-2020.iml @@ -1,8 +1,9 @@ - - + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index d1e22ec..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file From c9c3cff598f4734640986cf22172af82a11eeb07 Mon Sep 17 00:00:00 2001 From: linhara Date: Sat, 3 Oct 2020 17:54:32 +0200 Subject: [PATCH 3/5] Auto stash before merge of "linus" and "origin/felix-lek" --- .idea/Considition-2020.iml | 9 --------- main.py | 27 ++++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) delete mode 100644 .idea/Considition-2020.iml diff --git a/.idea/Considition-2020.iml b/.idea/Considition-2020.iml deleted file mode 100644 index 49018d0..0000000 --- a/.idea/Considition-2020.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/main.py b/main.py index 964df87..7057a20 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) -useTestStrategy = False +useTestStrategy = True def main(): @@ -34,7 +34,28 @@ def main(): print("Done with game: " + game_layer.game_state.game_id) print("Final score was: " + str(game_layer.get_score()["finalScore"])) +def linus_take_turn(): + mylist = [] + state = game_layer.game_state + for i in range(len(state.map)-1): + for j in range(len(state.map)-1): + if state.map[i][j] == 0: + mylist.append((i,j)) + #print(mylist) + + if (game_layer.game_state.turn == 0): + game_layer.place_foundation(mylist[0], game_layer.game_state.available_residence_buildings[0].building_name) + the_only_residence = state.residences[0] + if the_only_residence.build_progress < 100: + game_layer.build(mylist[0]) + else: + # messages and errors for console log + game_layer.wait() + for message in game_layer.game_state.messages: + print(message) + for error in game_layer.game_state.errors: + print("Error: " + error) def take_turn(): # TODO Implement your artificial intelligence here. @@ -90,6 +111,10 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) +def available_ground(): + + + if __name__ == "__main__": main() From ab936cdcf3e094376feee014155a295aed4871cb Mon Sep 17 00:00:00 2001 From: linhara Date: Sat, 3 Oct 2020 19:34:20 +0200 Subject: [PATCH 4/5] fortsatt prova skit --- main.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/main.py b/main.py index 7057a20..9e40a39 100644 --- a/main.py +++ b/main.py @@ -21,34 +21,48 @@ def main(): start_time = time.time() while game_layer.game_state.turn < game_layer.game_state.max_turns: try: - take_turn() + linus_take_turn() except: - e = sys.exc_info()[0] - print(e) + print(traceback.format_exc()) game_layer.end_game() exit() time_diff = time.time() - start_time - if time_diff > 40: + if time_diff > timeUntilRunEnds: 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 linus_take_turn(): - mylist = [] + freeSpace = [] + state = game_layer.game_state for i in range(len(state.map)-1): for j in range(len(state.map)-1): if state.map[i][j] == 0: - mylist.append((i,j)) + freeSpace.append((i,j)) #print(mylist) if (game_layer.game_state.turn == 0): - game_layer.place_foundation(mylist[0], game_layer.game_state.available_residence_buildings[0].building_name) - the_only_residence = state.residences[0] - if the_only_residence.build_progress < 100: - game_layer.build(mylist[0]) + game_layer.place_foundation(freeSpace[2], game_layer.game_state.available_residence_buildings[0].building_name) + the_first_residence = state.residences[0] + if the_first_residence.build_progress < 100: + game_layer.build(freeSpace[2]) + if len(state.residences)==1: + game_layer.place_foundation(freeSpace[3], game_layer.game_state.available_residence_buildings[4].building_name) + the_second_residence = state.residences[1] + if the_second_residence.build_progress < 100: + game_layer.build(freeSpace[3]) + elif the_first_residence.health < 70: + game_layer.maintenance(freeSpace[2]) + elif the_second_residence.health < 70: + game_layer.maintenance(freeSpace[3]) + elif (the_second_residence.health > 70) and not len(state.utilities) > 0: + game_layer.place_foundation(freeSpace[4], game_layer.game_state.available_utility_buildings[2].building_name) + elif (state.utilities[0].build_progress < 100): + game_layer.build(freeSpace[4]) + else: # messages and errors for console log game_layer.wait() @@ -61,7 +75,7 @@ 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: + if not usePrebuiltStrategy: state = game_layer.game_state print("testrunda") # messages and errors for console log @@ -74,7 +88,7 @@ def take_turn(): # pre-made test strategy # which came with # starter kit - if useTestStrategy: + if usePrebuiltStrategy: state = game_layer.game_state if len(state.residences) < 1: for i in range(len(state.map)): @@ -111,10 +125,6 @@ def take_turn(): for error in game_layer.game_state.errors: print("Error: " + error) -def available_ground(): - - - if __name__ == "__main__": main() From 2ef69e9c8d676fd4ac274caf7c2cc239a650e2aa Mon Sep 17 00:00:00 2001 From: linhara Date: Sat, 3 Oct 2020 19:34:41 +0200 Subject: [PATCH 5/5] la till timeUntilTimeEnds --- main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9e40a39..f3a605b 100644 --- a/main.py +++ b/main.py @@ -3,16 +3,20 @@ import time import sys from sys import exit from game_layer import GameLayer +import traceback + +timeUntilRunEnds = 30 api_key = "74e3998d-ed3d-4d46-9ea8-6aab2efd8ae3" # The different map names can be found on considition.com/rules map_name = "training1" # TODO: You map choice here. If left empty, the map "training1" will be selected. game_layer = GameLayer(api_key) -useTestStrategy = True +usePrebuiltStrategy = False def main(): + #game_layer.force_end_game() game_layer.new_game(map_name) print("Starting game: " + game_layer.game_state.game_id)