From 92383758d15a12d25467bf5857e01bff03ca6c93 Mon Sep 17 00:00:00 2001 From: Joseph Carolan Date: Fri, 21 Sep 2018 22:47:25 -0500 Subject: [PATCH 1/4] Implemented framework for all bots --- MyBot.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/MyBot.py b/MyBot.py index da84b75..9315bb0 100755 --- a/MyBot.py +++ b/MyBot.py @@ -33,20 +33,30 @@ def get_winning_stance(stance): me = game.get_self() - if me.location == me.destination: # check if we have moved this turn - # get all living monsters closest to me - monsters = game.nearest_monsters(me.location, 1) + opponent = game.get_opponent() - # choose a monster to move to at random - monster_to_move_to = monsters[random.randint(0, len(monsters)-1)] + if me.location == me.destination: - # get the set of shortest paths to that monster - paths = game.shortest_paths(me.location, monster_to_move_to.location) - destination_node = paths[random.randint(0, len(paths)-1)][0] + adjacent_nodes = game.get_adjacent_nodes + adjacent_nodes[adjacent_nodes.len] = me.location + + maxVal = node_value(adjacent_nodes[0], game) + + destination_node = me.location + + for i in game.get_adjacent_nodes(me.location): + + current_value = node_value(i, game) + + if (current_value > maxVal): + destination_node = i + maxVal = current_value else: destination_node = me.destination - if game.has_monster(me.location): + if opponent.location != me.location: + chosen_stance = best_stance(game) + elif game.has_monster(me.location): # if there's a monster at my location, choose the stance that damages that monster chosen_stance = get_winning_stance(game.get_monster(me.location).stance) else: @@ -54,4 +64,4 @@ def get_winning_stance(stance): chosen_stance = stances[random.randint(0, 2)] # submit your decision for the turn (This function should be called exactly once per turn) - game.submit_decision(destination_node, chosen_stance) + game.submit_decision(destination_node, chosen_stance) \ No newline at end of file From bd40c1c84919ed77bb571c969226dd79bf3f0b1f Mon Sep 17 00:00:00 2001 From: Joseph Carolan Date: Fri, 21 Sep 2018 22:51:30 -0500 Subject: [PATCH 2/4] Created a test random bot --- MyBot.py | 3 ++- bots/randomBot.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 bots/randomBot.py diff --git a/MyBot.py b/MyBot.py index 9315bb0..e6bab58 100755 --- a/MyBot.py +++ b/MyBot.py @@ -5,6 +5,7 @@ # your import statements here import random +from bots import randomBot first_line = True # DO NOT REMOVE @@ -55,7 +56,7 @@ def get_winning_stance(stance): destination_node = me.destination if opponent.location != me.location: - chosen_stance = best_stance(game) + chosen_stance = stances[best_stance(game)] elif game.has_monster(me.location): # if there's a monster at my location, choose the stance that damages that monster chosen_stance = get_winning_stance(game.get_monster(me.location).stance) diff --git a/bots/randomBot.py b/bots/randomBot.py new file mode 100644 index 0000000..1cbcd0a --- /dev/null +++ b/bots/randomBot.py @@ -0,0 +1,9 @@ +import game_API + +import random + +def node_value(node, map): + return random.randint(0,10) + +def best_stance(map): + return random.randint(0,2) \ No newline at end of file From 984911446c159981f05833bd5a811e33e60b7dec Mon Sep 17 00:00:00 2001 From: Joseph Carolan Date: Fri, 21 Sep 2018 23:32:48 -0500 Subject: [PATCH 3/4] Refined random bot template --- MyBot.py | 9 +++++++-- bots/randomBot.py | 9 --------- 2 files changed, 7 insertions(+), 11 deletions(-) delete mode 100644 bots/randomBot.py diff --git a/MyBot.py b/MyBot.py index e6bab58..7436363 100755 --- a/MyBot.py +++ b/MyBot.py @@ -5,7 +5,6 @@ # your import statements here import random -from bots import randomBot first_line = True # DO NOT REMOVE @@ -20,6 +19,12 @@ def get_winning_stance(stance): elif stance == "Scissors": return "Rock" +def node_value(node, map): + return random.randint(0,10) + +def best_stance(map): + return random.randint(0,2) + # main player script logic # DO NOT CHANGE BELOW ---------------------------- for line in fileinput.input(): @@ -39,7 +44,7 @@ def get_winning_stance(stance): if me.location == me.destination: adjacent_nodes = game.get_adjacent_nodes - adjacent_nodes[adjacent_nodes.len] = me.location + adjacent_nodes[len(adjacent_nodes)] = me.location maxVal = node_value(adjacent_nodes[0], game) diff --git a/bots/randomBot.py b/bots/randomBot.py deleted file mode 100644 index 1cbcd0a..0000000 --- a/bots/randomBot.py +++ /dev/null @@ -1,9 +0,0 @@ -import game_API - -import random - -def node_value(node, map): - return random.randint(0,10) - -def best_stance(map): - return random.randint(0,2) \ No newline at end of file From 58d66493c6a5e38318e6bde363272dc3c4cd15e3 Mon Sep 17 00:00:00 2001 From: Joseph Carolan Date: Fri, 21 Sep 2018 23:36:38 -0500 Subject: [PATCH 4/4] Created random bot --- MyBot.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MyBot.py b/MyBot.py index 7436363..3e70c82 100755 --- a/MyBot.py +++ b/MyBot.py @@ -19,12 +19,18 @@ def get_winning_stance(stance): elif stance == "Scissors": return "Rock" + + def node_value(node, map): return random.randint(0,10) + + def best_stance(map): return random.randint(0,2) + + # main player script logic # DO NOT CHANGE BELOW ---------------------------- for line in fileinput.input(): @@ -44,7 +50,7 @@ def best_stance(map): if me.location == me.destination: adjacent_nodes = game.get_adjacent_nodes - adjacent_nodes[len(adjacent_nodes)] = me.location + adjacent_nodes.append(me.location) maxVal = node_value(adjacent_nodes[0], game)