Improve movement logic #21
64
main.py
64
main.py
@ -175,6 +175,15 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
x = cords['x']
|
x = cords['x']
|
||||||
y = cords['y']
|
y = cords['y']
|
||||||
dir = agent.get_direction()
|
dir = agent.get_direction()
|
||||||
|
fuel = agent.get_tank_capacity()
|
||||||
|
water = agent.get_water()
|
||||||
|
feritizer = agent.get_feritizer()
|
||||||
|
seeds = agent.get_seeds()
|
||||||
|
carrots = agent.get_carrots()
|
||||||
|
potatoes = agent.get_potatoes()
|
||||||
|
wheat = agent.get_wheat()
|
||||||
|
print("fuel:", fuel, "water:", water, "feritizer:", feritizer, "seeds:", seeds, "carrots:", carrots,
|
||||||
|
"potatoes:", potatoes, "wheat:", wheat)
|
||||||
if k == 0 and len(fields_to_harvest) > 0 and decision == False: # harvest
|
if k == 0 and len(fields_to_harvest) > 0 and decision == False: # harvest
|
||||||
field_to_visit, l = get_closest_field(fields_to_harvest, x, y, dir, fields_for_astar)
|
field_to_visit, l = get_closest_field(fields_to_harvest, x, y, dir, fields_for_astar)
|
||||||
x1, y1 = field_to_visit[0], field_to_visit[1]
|
x1, y1 = field_to_visit[0], field_to_visit[1]
|
||||||
@ -189,6 +198,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'wheat_empty'
|
fields_with_plants[x1][y1] = 'wheat_empty'
|
||||||
fields_for_movement[x1][y1] = possibleFields['wheat_empty'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['wheat_empty'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
wheat += 1
|
||||||
|
agent.set_wheat(wheat)
|
||||||
elif fields_with_plants[x1][y1] == 'carrot_feritized':
|
elif fields_with_plants[x1][y1] == 'carrot_feritized':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -199,6 +210,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'carrot_empty'
|
fields_with_plants[x1][y1] = 'carrot_empty'
|
||||||
fields_for_movement[x1][y1] = possibleFields['carrot_empty'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['carrot_empty'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
carrots += 1
|
||||||
|
agent.set_carrots(carrots)
|
||||||
elif fields_with_plants[x1][y1] == 'potato_feritized':
|
elif fields_with_plants[x1][y1] == 'potato_feritized':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -209,6 +222,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'potato_empty'
|
fields_with_plants[x1][y1] = 'potato_empty'
|
||||||
fields_for_movement[x1][y1] = possibleFields['potato_empty'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['potato_empty'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
potatoes += 1
|
||||||
|
agent.set_potatoes(potatoes)
|
||||||
if len(fields_to_harvest) == 0:
|
if len(fields_to_harvest) == 0:
|
||||||
k += 1
|
k += 1
|
||||||
elif k == 1 and len(fields_to_water) > 0 and decision == False: # water
|
elif k == 1 and len(fields_to_water) > 0 and decision == False: # water
|
||||||
@ -225,6 +240,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'wheat_watered'
|
fields_with_plants[x1][y1] = 'wheat_watered'
|
||||||
fields_for_movement[x1][y1] = possibleFields['wheat_watered'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['wheat_watered'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
water -= 1
|
||||||
|
agent.set_water(water)
|
||||||
elif fields_with_plants[x1][y1] == 'carrot_sow':
|
elif fields_with_plants[x1][y1] == 'carrot_sow':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -235,6 +252,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'carrot_watered'
|
fields_with_plants[x1][y1] = 'carrot_watered'
|
||||||
fields_for_movement[x1][y1] = possibleFields['carrot_watered'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['carrot_watered'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
water -= 1
|
||||||
|
agent.set_water(water)
|
||||||
elif fields_with_plants[x1][y1] == 'potato_sow':
|
elif fields_with_plants[x1][y1] == 'potato_sow':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -245,6 +264,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'potato_watered'
|
fields_with_plants[x1][y1] = 'potato_watered'
|
||||||
fields_for_movement[x1][y1] = possibleFields['potato_watered'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['potato_watered'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
water -= 1
|
||||||
|
agent.set_water(water)
|
||||||
if len(fields_to_water) == 0:
|
if len(fields_to_water) == 0:
|
||||||
k += 1
|
k += 1
|
||||||
elif k == 2 and len(fields_to_feritize) > 0 and decision == False: # feritize
|
elif k == 2 and len(fields_to_feritize) > 0 and decision == False: # feritize
|
||||||
@ -261,6 +282,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'wheat_feritized'
|
fields_with_plants[x1][y1] = 'wheat_feritized'
|
||||||
fields_for_movement[x1][y1] = possibleFields['wheat_feritized'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['wheat_feritized'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
feritizer -= 1
|
||||||
|
agent.set_feritizer(feritizer)
|
||||||
elif fields_with_plants[x1][y1] == 'carrot_watered':
|
elif fields_with_plants[x1][y1] == 'carrot_watered':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -271,6 +294,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'carrot_feritized'
|
fields_with_plants[x1][y1] = 'carrot_feritized'
|
||||||
fields_for_movement[x1][y1] = possibleFields['carrot_feritized'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['carrot_feritized'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
feritizer -= 1
|
||||||
|
agent.set_feritizer(feritizer)
|
||||||
elif fields_with_plants[x1][y1] == 'potato_watered':
|
elif fields_with_plants[x1][y1] == 'potato_watered':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -281,6 +306,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'potato_feritized'
|
fields_with_plants[x1][y1] = 'potato_feritized'
|
||||||
fields_for_movement[x1][y1] = possibleFields['potato_feritized'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['potato_feritized'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
feritizer -= 1
|
||||||
|
agent.set_feritizer(feritizer)
|
||||||
if len(fields_to_feritize) == 0:
|
if len(fields_to_feritize) == 0:
|
||||||
k += 1
|
k += 1
|
||||||
elif k == 3 and len(fields_to_sow) > 0 and decision == False: # sow
|
elif k == 3 and len(fields_to_sow) > 0 and decision == False: # sow
|
||||||
@ -297,6 +324,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'wheat_sow'
|
fields_with_plants[x1][y1] = 'wheat_sow'
|
||||||
fields_for_movement[x1][y1] = possibleFields['wheat_sow'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['wheat_sow'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
seeds -= 1
|
||||||
|
agent.set_seeds(seeds)
|
||||||
elif fields_with_plants[x1][y1] == 'carrot_empty':
|
elif fields_with_plants[x1][y1] == 'carrot_empty':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -307,6 +336,8 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'carrot_sow'
|
fields_with_plants[x1][y1] = 'carrot_sow'
|
||||||
fields_for_movement[x1][y1] = possibleFields['carrot_sow'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['carrot_sow'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
seeds -= 1
|
||||||
|
agent.set_seeds(seeds)
|
||||||
elif fields_with_plants[x1][y1] == 'potato_empty':
|
elif fields_with_plants[x1][y1] == 'potato_empty':
|
||||||
state = astar.State(dir, x, y)
|
state = astar.State(dir, x, y)
|
||||||
move_list = (
|
move_list = (
|
||||||
@ -317,9 +348,27 @@ def generate_movement(fields_for_astar, fields_with_plants, fields_for_movement,
|
|||||||
fields_with_plants[x1][y1] = 'potato_sow'
|
fields_with_plants[x1][y1] = 'potato_sow'
|
||||||
fields_for_movement[x1][y1] = possibleFields['potato_sow'].tile.object
|
fields_for_movement[x1][y1] = possibleFields['potato_sow'].tile.object
|
||||||
draw_window(agent, fields_for_movement)
|
draw_window(agent, fields_for_movement)
|
||||||
|
seeds -= 1
|
||||||
|
agent.set_seeds(seeds)
|
||||||
if len(fields_to_sow) == 0:
|
if len(fields_to_sow) == 0:
|
||||||
k = 0
|
k = 0
|
||||||
|
elif decision:
|
||||||
|
print("Going back to base")
|
||||||
|
state = astar.State(dir, x, y)
|
||||||
|
move_list = (
|
||||||
|
astar.graphsearch([], astar.f, [], [0, 0], state, fields_for_astar,
|
||||||
|
astar.succ))
|
||||||
|
agent_movement(move_list, agent, fields_for_movement, fields_for_astar)
|
||||||
|
draw_window(agent, fields_for_movement)
|
||||||
|
agent.set_tank_capacity(1500)
|
||||||
|
agent.set_water(50)
|
||||||
|
agent.set_feritizer(50)
|
||||||
|
agent.set_seeds(50)
|
||||||
|
agent.set_carrots(0)
|
||||||
|
agent.set_potatoes(0)
|
||||||
|
agent.set_wheat(0)
|
||||||
|
print("I'm in base")
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -347,6 +396,19 @@ def agent_movement(move_list, agent, fields, fields_2):
|
|||||||
agent_action(agent.rotate(action))
|
agent_action(agent.rotate(action))
|
||||||
elif action == 'f':
|
elif action == 'f':
|
||||||
agent_action(agent.move(action))
|
agent_action(agent.move(action))
|
||||||
|
cords = agent.coordinates()
|
||||||
|
x = cords['x']
|
||||||
|
y = cords['y']
|
||||||
|
fuel = agent.get_tank_capacity()
|
||||||
|
if fields_2[x][y] == 'dirt':
|
||||||
|
fuel -= 5
|
||||||
|
elif fields_2[x][y] == 'cobble':
|
||||||
|
fuel -= 1
|
||||||
|
elif fields_2[x][y] == 'grass':
|
||||||
|
fuel -= 3
|
||||||
|
elif fields_2[x][y] == 'sand':
|
||||||
|
fuel -= 10
|
||||||
|
agent.set_tank_capacity(fuel)
|
||||||
draw_window(agent, fields)
|
draw_window(agent, fields)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user