Skip to content
Permalink
Browse files

Some bug fixes and added a simple algorithm to run trough the tree an…

…d give connections scores
  • Loading branch information
RafayelGardishyan committed Mar 21, 2020
1 parent 5fc99a1 commit f183bcd41a3cd25ec4d38c06c1be49a1d3c51770
Showing with 1,305 additions and 19 deletions.
  1. +78 −0 Article/rafayel/algorithm.py
  2. +1,223 −0 Article/rafayel/graph-backup.gv
  3. +1 −1 Article/rafayel/graph-decoder.py
  4. +2 −18 Article/rafayel/graph.gv
  5. +1 −0 Article/rafayel/tree.json
@@ -0,0 +1,78 @@
import json

vital_items = [
7, 111, 191, 237, 82, 303, 42, 85, 297, 163
]

won_times = 0

for i in range(5000):
tree_file = open('tree.json', 'r')
tree = json.loads(tree_file.read())
tree_file.close()
path = [1]
path_indices = []
running = True

current_node = 1

def do_game_over_stuff():
for i in range(len(path)):
try:
tree[str(path[i])]['connections'][path_indices[i]]["score"] *= 1 - (((1/2)/len(path)) * (i+1))
except IndexError:
pass

tree_file = open('tree.json', 'w')
tree_file.write(json.dumps(tree))


def do_game_won_stuff():
for i in range(len(path)):
try:
tree[str(path[i])]['connections'][path_indices[i]]["score"] *= 1 + (((1/2)/len(path)) * (i+1))
except IndexError:
pass

tree_file = open('tree.json', 'w')
tree_file.write(json.dumps(tree))


while running:
# print("Current node:", current_node)
node = tree[str(current_node)]

if 'GameOver' in node["connections"]:
do_game_over_stuff()
running = False
continue

if 'GameWon' in node["connections"]:
for item in vital_items:
if item not in path:
do_game_over_stuff()
running = False
continue

do_game_won_stuff()
print("Won!")
won_times += 1
running = False
continue


best_option = 0
best_score = 0
for option in node["connections"]:
if option["score"] > best_score:
best_option = node["connections"].index(option)
best_score = option["score"]

current_node = int(node["connections"][best_option]["to"])

path_indices.append(best_option)
path.append(current_node)

# print("Final path => {}".format(path))

print("Won {} times".format(won_times))

0 comments on commit f183bcd

Please sign in to comment.
You can’t perform that action at this time.