diff --git a/Program.py b/Program.py index 5bc11ef..4c78e9e 100644 --- a/Program.py +++ b/Program.py @@ -11,14 +11,20 @@ VERTICAL = 750 TILE_SIZE = 50 -c_label = random.randint(0, 3) # 0 - no label, 1 - fragile, 2 - hazardous, 3 - any other -c_size = random.randint(1, 3) # 1 - small, 2 - medium, 3 - large -c_weight = random.randint(1, 3) # -||- -c_urgent = random.randint(0, 1) # yes/no -c_weekend = random.randint(0, 1) # stays for the weekend yes/no -c_payment_method = random.randint(0, 2) # not paid, prepaid, cash on delivery -c_international = random.randint(1, 4) # domestic, european, us, everywhere else -c_delayed = random.randint(0, 1) # yes/no + +def roll_pack(tree): + c_label = random.randint(0, 3) # 0 - no label, 1 - fragile, 2 - hazardous, 3 - any other + c_size = random.randint(1, 3) # 1 - small, 2 - medium, 3 - large + c_weight = random.randint(1, 3) # -||- + c_urgent = random.randint(0, 1) # yes/no + c_weekend = random.randint(0, 1) # stays for the weekend yes/no + c_payment_method = random.randint(0, 2) # not paid, prepaid, cash on delivery + c_international = random.randint(1, 4) # domestic, european, us, everywhere else + c_delayed = random.randint(0, 1) # yes/no + + decision = decision_tree.make_decision(tree, c_label, c_size, c_weight, c_urgent, c_weekend, + c_payment_method, c_international, c_delayed) + return decision # sectors: # 1 - regular, @@ -26,38 +32,38 @@ c_delayed = random.randint(0, 1) # yes/no # 3 - international, # 4 - overdue -tree = decision_tree.treelearn() -decision = decision_tree.make_decision(tree, c_label, c_size, c_weight, c_urgent, c_weekend, c_payment_method, c_international, c_delayed) -def handle_decision(): - global row, col +def handle_decision(decision): if decision == '1': row = 10 + 2 * random.randint(0, 2) col = random.randint(1, 5) + 6 * random.randint(0, 1) print('regular') - if decision == '2': + elif decision == '2': row = 10 + 2 * random.randint(0, 2) col = random.randint(1, 5) + 6 * random.randint(2, 3) print('hazardous') - if decision == '3': + elif decision == '3': row = 2 * random.randint(0, 2) col = random.randint(1, 5) + 6 * random.randint(0, 1) print('international') - if decision == '4': + else: row = 2 * random.randint(0, 2) col = random.randint(1, 5) + 6 * random.randint(2, 3) print('overdue') return row, col -def handle_turn(initial_state, turn_count): +def handle_turn(initial_state, turn_count, tree): if turn_count % 2 == 0: commands = a_star.a_star(state=initial_state, goal=(7, 23)) else: # row = random.randint(0, 1) * 10 + 2 * random.randint(0, 2) # col = random.randint(1, 5) + 6 * random.randint(0, 3) - commands = a_star.a_star(state=initial_state, goal=(handle_decision())) - print('I need to go to row, column: ' + str(handle_decision())) + decision = roll_pack(tree) + destination = handle_decision(decision) + + commands = a_star.a_star(state=initial_state, goal=destination) + print('I need to go to row, column: ' + str(destination)) return commands @@ -76,11 +82,10 @@ class Program: initial_state = a_star.State(row=int(self.agent.y / 50), column=int(self.agent.x / 50), direction=self.agent.direction) + tree = decision_tree.treelearn() + while running: - - handle_decision() - - commands = handle_turn(initial_state=initial_state, turn_count=turn_count) + commands = handle_turn(initial_state=initial_state, turn_count=turn_count, tree=tree) while commands: pygame.event.poll()