This commit is contained in:
Hourglass 2023-06-05 14:46:09 +02:00
parent 3dea3909dd
commit 1fcd5eaf4a

View File

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