Dodano visited, mapowanie ruchow, zmiana datasetu

This commit is contained in:
Anna Nowak 2019-06-05 21:48:44 +02:00
parent d9fc9e1384
commit cf3bf3d4f5
39 changed files with 361 additions and 28 deletions

View File

@ -1,5 +1,6 @@
import pygame
from DataModels.Cell import Cell
from VowpalWabbit.vowpal_utils import MAP_CONTENT
class Dump( Cell ):
def __init__( self, x, y, max_rubbish, dump_type, yellow = 0, green = 0, blue = 0 ):
@ -12,3 +13,10 @@ class Dump( Cell ):
self.container.yellow, self.container.green, self.container.blue = collector.container.empty(dump_type,
[self.container.yellow, self.container.green, self.container.blue])
self.update_image()
def Visit(self):
self.unvisited = not self.unvisited
if self.unvisited:
MAP_CONTENT[self.y][self.x] = self.dump_type[5]
else:
MAP_CONTENT[self.y][self.x] = "V"

View File

@ -46,31 +46,34 @@ class GC(Cell):
x = self.x
y = self.y
whole_result=[]
result = []
element_list=[]
house_count_after_search=house_count
for home in range(house_count):
last_x = x
last_y = y
avalible_moves = check_moves(enviromnent, x,y)
if mode == "DFS":
house,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],House)
elif mode == "BFS":
house,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],House)
result = result[1::]
whole_result.extend(result)
self.moves.extend(parse_list(result[1:], last_x,last_y))
element_list.append(house)
house.Visit()
for dump in range(dump_count):
last_x = x
last_y = y
avalible_moves = check_moves(enviromnent, x,y)
if mode == "DFS":
dump,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],Dump)
elif mode == "BFS":
dump,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],Dump)
whole_result.extend(result)
self.moves.extend(parse_list(result[1:], last_x,last_y))
element_list.append(dump)
dump.Visit()
for x in element_list:
x.unvisited = True
self.moves.extend(parse_list(whole_result))
x.Visit()
self.moves.reverse()
save_moveset(self.moves)
def find_houses_BestFS(self, environment):
@ -79,7 +82,6 @@ class GC(Cell):
x = self.x
y = self.y
result = [[x,y]]
whole_result=[]
houses_list = []
dump_list = []
a = 0
@ -94,20 +96,24 @@ class GC(Cell):
a += 1
x, y = self.x, self.y
for i in range(len(houses_list)):
last_x = x
last_y = y
available_movement = check_moves(environment, x, y)
output = BestFS(environment, available_movement, [[x,y]], houses_list)
if(output != None):
[x,y],result,houses_list = output[0], output[1], output[2]
whole_result.extend(result[1:])
[x,y],result,houses_list,house = output[0], output[1], output[2], output[3]
house.Visit()
self.moves.extend(parse_list(result[1:], last_x,last_y))
for i in range(len(dump_list)):
last_x = x
last_y = y
available_movement = check_moves(environment, x, y)
output = BestFS(environment, available_movement, [[x,y]], dump_list)
if(output != None):
[x,y],result,dump_list = output[0], output[1], output[2]
whole_result.extend(result[1:])
self.moves.extend(parse_list(whole_result,self.x,self.y))
[x,y],result,dump_list,dump = output[0], output[1], output[2], output[3]
dump.Visit()
self.moves.extend(parse_list(result[1:], last_x,last_y))
self.moves.reverse()
save_moveset(self.moves)

View File

@ -1,5 +1,5 @@
from DataModels.Cell import Cell
from VowpalWabbit.vowpal_utils import MAP_CONTENT
class House(Cell):
def __init__(self, x, y, max_rubbish, yellow=0, green=0, blue=0):
@ -10,3 +10,10 @@ class House(Cell):
self.container.yellow, self.container.green, self.container.blue = collector.container.add(
[self.container.yellow, self.container.green, self.container.blue])
self.update_image()
def Visit(self):
self.unvisited = not self.unvisited
if self.unvisited:
MAP_CONTENT[self.y][self.x] = "H"
else:
MAP_CONTENT[self.y][self.x] = "V"

View File

@ -0,0 +1,8 @@
8 6
7 1
R H R E B E R E
R R R R R R R R
R E E H E E R H
R R R R R R R R
R Y G E H E R E
R E E E E E R E

View File

@ -0,0 +1,9 @@
13 7
0 6
B E E R E E E E E E R E R
R R H R E E E H E E R E R
R R R R R R R R R R R R R
E E E R E E H E Y E R E R
E E E R E E E E E H R H R
H H E R E E H E E G R E R
R R R R R R R R R R R R R

View File

@ -0,0 +1,8 @@
14 6
1 0
R R R R R R R R R R R R R R
E E E R H E E H R E R G R E
E H H R E H E E R E R B R E
R R R R R R R R R R R R R R
E E E E E H R Y R E R E R E
E E E E E E H E R R R E R E

View File

@ -0,0 +1,8 @@
13 6
3 3
R R R R R R R R R R R R R
R E E R E R E H E H R E R
R E E R E R H E E E R E E
R R R R R R R R R R R R R
R G E R H H R E E H R E E
R E Y R B E E E E E R H E

View File

@ -0,0 +1,7 @@
5 5
0 3
R R R R R
R E E R B
R E H R Y
R R R R R
R E G R E

View File

@ -0,0 +1,8 @@
15 6
5 2
R E Y E H R E H E E E R E E H
R R R R R R R R R R R R R R R
E H H E H R E E E E E R E R E
E E E E E R R R H E E R E R E
G B E E H R H R E E E R E R E
R R R R R R R R R R R R R R R

View File

@ -0,0 +1,11 @@
10 9
3 8
E E E R R R E R H E
E E E R E R E R E E
E E Y R H R E R H E
E E E R B R H R E E
H R E R E R E R E G
R R R R R R R R R R
E H E R E R H R E E
E R E R E R E R E R
R R R R R R R R R R

View File

@ -0,0 +1,7 @@
10 5
9 1
E E E R E H H G R Y
R R R R R R R R R R
E E E R B H R E R E
R R R R R R R R R R
E E E R H E E E R H

View File

@ -0,0 +1,11 @@
14 9
7 7
E E E E E R H H R E E E E E
E E E E E R E E R E E E E E
E E E E E R R R R H E E E E
E H E E E R B E R E E E R E
R R R R R R R R R R R R R R
R H E E E R E H R E E E Y E
H H E R E R E H R E E H E H
R R R R R R R R R R R R R R
E R E E H R E G R H E E E E

View File

@ -0,0 +1,11 @@
5 9
3 2
E R R R R
E R E E R
R R R R R
E R E H R
E R E E R
H R E B R
H R E E R
H R G Y R
R R R R R

View File

@ -0,0 +1,9 @@
13 7
7 1
R H G R E E R H E H E E H
R R R R R R R R R R R R R
R E E R E E R H B E R E E
R E E R E E R E H R R E E
R R R R R R R R R R R R R
R H E R H E R E Y E E H E
R E R R E E R E E E E E E

View File

@ -0,0 +1,7 @@
6 5
1 4
B R H E R E
R R R R R R
H R E E R Y
R R R R R R
E R G E R E

View File

@ -0,0 +1,12 @@
12 10
9 1
E R B H E R G E R E H R
R R R R R R R R R R R R
E R E R E R H E R E E R
E R E R H R R E R E Y R
E R H R E R E E R H E R
R R R R R R R R R R R R
E R E E E R E E R E E R
E R R H E R E E R H E R
E R E E E R H E R E R R
H R E E E R H E R H H R

View File

@ -0,0 +1,11 @@
6 9
1 5
B R E R E E
E R R R H E
E R E R E E
G R E R H E
E R H R E E
R R R R R R
E R E R Y R
R R R R R R
E R H R E E

View File

@ -0,0 +1,9 @@
11 7
8 2
E E E R E E E R E E E
E E E R E Y E R E E E
R R R R R R R R R R R
E R H R H E H R G E R
R H E R E H H R E E R
R R R R R R R R R R R
B E E R H E E R E E H

View File

@ -0,0 +1,12 @@
13 10
10 8
E E E E H R H E G R E E E
E E E E B R H E E R E E E
E E E E E R E E E R E E E
E E E E E R H H R R H E E
E E E E E R H H E R E H E
R R R R R R R R R R R R R
E E Y E E R H E E R E E R
E E E R E R E E E R E H E
R R R R R R R R R R R R R
R E E E H R E E E R H R R

View File

@ -0,0 +1,8 @@
15 6
14 1
R R R R R R R R R R R R R R R
E E R E E Y R E E R E E E H R
E H R R E H R R R R E E E H R
E H R E E E R E E R E E E E E
H E R H H G R E E R E E E B E
R R R R R R R R R R R R R R R

View File

@ -0,0 +1,10 @@
14 8
1 7
E R E E E E E R E R E R H E
E R H E E E E R G R Y R H H
R R R R R R R R R R R R R R
E R H E E E R E E R E R E E
E R R R R R H E E R E R E E
E R H E H E E E E R E R E E
H R E H E E E B E R H R E E
R R R R R R R R R R R R R R

View File

@ -0,0 +1,11 @@
9 9
4 0
R R R R R R R R R
R E H H R E R E H
R E E H R R R E E
R R R R R H R E E
R E E E R E R E H
R R R R R R R R R
R E E Y R E R B E
R E E E R H R E E
R G E E R R R E E

View File

@ -0,0 +1,7 @@
12 5
3 1
E R E E R E E R H E R G
R R R R R R R R R R R R
H R E E R E H R E E R E
R R R R R R R R R R R R
E R E E R Y H R E B R H

View File

@ -0,0 +1,12 @@
8 10
4 0
R R R R R R R R
E H R B R G R E
R R R R R R R R
E E R E E H R E
E E R H E E R E
E H R E R R R H
E E R Y E E R E
E E R H E E R H
E E R R R R R H
E E R E E E R E

View File

@ -0,0 +1,11 @@
12 9
8 1
E H H R H E R E R H E R
R R R R R R R R R R R R
E E E R E E R H R H E R
R R R R R R R R R R R R
R G E R E E R E R E E R
R R R R R R R R R R R R
H E E R H Y R E R E E R
E R R R E E R B R R E R
E E H R E E R E R H E R

View File

@ -0,0 +1,8 @@
10 6
8 0
E B R E E R G R R E
E Y R H E R E E R E
E E R E E R H H R E
R R R R R R R R R R
E E R H E R H E R E
R R R R R R R R R R

View File

@ -0,0 +1,8 @@
15 6
0 4
R E E H E E R E B R H R H R H
R R R R R R R R R R R R R R R
R E H E E Y R E E R G E R E H
R E E E E E R E E R H E R E E
R H E E H E R E E R E E R E E
R R R R R R R R R R R R R R R

View File

@ -0,0 +1,7 @@
11 5
4 0
R R R R R R R R R R R
E E R E E H H H R E E
E H R E E E E G R E E
R R R R R R R R R R R
E E R H B E Y E R E R

View File

@ -0,0 +1,11 @@
9 9
2 2
R E E R B R E E E
R E H R H R E E E
R R R R E R H E E
R R E R E R G R E
R Y E R E R E R E
R R R R R R R R R
R E E R E R E E R
R H E R H R E H R
R R R R R R R R R

View File

@ -0,0 +1,9 @@
9 7
7 6
E E E E E R H E R
E E R E E R H E R
E E R H E R E E R
R R R R R R R R R
E G B R Y R E H R
E H E H E R E E R
R R R R R R R R R

View File

@ -0,0 +1,7 @@
7 5
1 2
R R R R R R R
E R Y G B E R
R R R R R R R
E R E E H E R
H R E E E E R

View File

@ -0,0 +1,12 @@
8 10
6 6
E E E H R H R E
R B E E R E R E
R E E E R H R H
R R R R R R R R
E H E H R E R E
Y E E E R E R E
R R R R R R R R
E H R G R E R E
R R R R R R R R
R E H E R E R E

View File

@ -0,0 +1,9 @@
13 7
7 5
R R R R R R R R R R R R R
E E H R H H E R G E R E E
R E E E E E E R E E R E E
R H E R E H E R Y E R H E
R R R R R R R R R R R R R
E R E E H E E R E H R E R
E R E E E E E R E H R E B

View File

@ -0,0 +1,8 @@
7 6
1 2
E R E R H E E
R R R R R R R
E R E R B E H
R R R R R R R
E R G R E Y R
E R H R E E R

View File

@ -0,0 +1,9 @@
13 7
3 2
R H E R E R E R E E R B E
R R R R R R R R R R R R R
R G E R E H H R E E R E R
R R R R R R R R R R R R R
R H H R E H E R E E R E E
R H E R E E Y R E H R E E
R E E R E E E R E R R E E

View File

@ -0,0 +1,8 @@
15 6
8 1
R R R R R R R R R R R R R R R
E E R E Y H R E R E E R E R H
E E R H E E R R R E H R E R B
E E R H E E R E R E G R E R E
R R R R R R R R R R R R R R R
E H R E E H R E R E E R H R E

View File

@ -15,7 +15,7 @@ def CalculateDistance(gc, object_list):
return min_distance_goal
def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
x, y = gc_moveset[-1][0], gc_moveset[-1][1]
#calculate distance to the nearest object
@ -25,11 +25,11 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
gc_moveset.append("pick_garbage")
cell = grid[min_distance_goal[0][0]][min_distance_goal[0][1]]
object_list.remove([cell,min_distance_goal[0]])
return([x, y], gc_moveset, object_list)
return([x, y], gc_moveset, object_list, cell)
#if depth exceeded, return
if(depth > 15 or len(available_movement) == 0):
return
return
#set preffered directions based on the closest object
preffered_directions = []
@ -65,4 +65,4 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
gc_moveset_next.append([x_next,y_next])
result = BestFS(grid, available_movement_next, gc_moveset_next, object_list, depth + 1)
if result!= None:
return result
return result

View File

@ -5,7 +5,6 @@ from DataModels.Container import Container
from config import GRID_WIDTH, GRID_HEIGHT
def DFS(grid, available_movement, gc_moveset, mode,depth=0):
possible_goals = []
a = gc_moveset[-1][0]
b = gc_moveset[-1][1]
@ -18,7 +17,6 @@ def DFS(grid, available_movement, gc_moveset, mode,depth=0):
if GRID_WIDTH>location[0]>=0 and GRID_HEIGHT>location[1]>=0:
cell = grid[location[0]][location[1]]
if(type(cell) == mode and cell.unvisited):
cell.unvisited = False
object_in_area = True
break

View File

@ -29,6 +29,15 @@ predictions_mapping = {
5 : "down"
}
environment_mapping = {
"E":0,
"R":1,
"H":2,
"V":3,
"Y":4,
"B":5,
"G":6
}
def parse_list(whole_result,current_x,current_y):
global COORDINATES_LIST, MOVES_LIST
COORDINATES_LIST = whole_result.copy()
@ -53,20 +62,21 @@ def generate_input(importance):
i = 1 #we'll use it to map coords to moves
input_file_content = []
for position in COORDINATES_LIST[:len(COORDINATES_LIST)-1]:
coords = check_position(position, i) #set valid gc position
#vowpal config goes here
label = moves_mapping[MOVES_LIST[i]]
input_line = str(label) + " " + str(importance) + " | "
#" " + str(importance) +
input_line = str(label) + " | "
area = get_gc_area(coords, RADIUS)
for a in area:
input_line += a + " "
i += 1
input_file_content.append(input_line)
#save to file
tag = re.findall("(map_[0-9]+|map[0-9]+_auto)", MAP_NAME)[0]
filename = "./VowpalWabbit/VowpalInputData/input_" + str(tag) + ".txt"
@ -100,7 +110,8 @@ def get_gc_area(position, radius):
for y in range(max(0, position[1] - radius), min(position[1] + radius + 1, GRID_HEIGHT)):
if([x,y] == position): #we dont need gc data here
continue
area.append("F"+str(x - upper_right_coord[0])+str(y - upper_right_coord[1])+":"+MAP_CONTENT[y][x]) #CHANGE MAP CONTENT TO THE CODE OF AN OBJECT HERE
area.append("F"+str(x - upper_right_coord[0])+str(y - upper_right_coord[1])+":"+str(environment_mapping[MAP_CONTENT[y][x]])) #CHANGE MAP CONTENT TO THE CODE OF AN OBJECT HERE
return area
def check_position(position, i):
@ -152,4 +163,4 @@ def make_move_from_prediction(prediction):
move = predictions_mapping[2]
else:
move = predictions_mapping[1]
return move
return move