Commit f858eab8 authored by Julian Rudolf's avatar Julian Rudolf
Browse files

Merge remote-tracking branch 'origin/dev'

# Conflicts:
#	Shield/graph_from_map.py
parents fb4a3002 a25135e6
Game/data/SnakeHeadBot_30x30.png

1.1 KB | W: | H:

Game/data/SnakeHeadBot_30x30.png

10.8 KB | W: | H:

Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
Game/data/SnakeHeadBot_30x30.png
  • 2-up
  • Swipe
  • Onion skin
Game/data/SnakeHeadRed_30x30.png

1.01 KB | W: | H:

Game/data/SnakeHeadRed_30x30.png

6.9 KB | W: | H:

Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
Game/data/SnakeHeadRed_30x30.png
  • 2-up
  • Swipe
  • Onion skin
This diff is collapsed.
...@@ -89,12 +89,12 @@ ...@@ -89,12 +89,12 @@
# "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]], # "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
# "angle": 'up'}] # "angle": 'up'}]
start3 = [{"pos": [[5,6],[5,5],[5,4],[5,3],[5,2],[5,1],[4,1],[3,1],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7]], start3 = [{"pos": [[5,6],[5,5],[5,4],[5,3],[5,2],[5,1],[4,1],[3,1],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12]],
"vel": [[1,0],[1,0],[1,0],[1,0],[1,0],[0,1],[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]], "vel": [[1,0],[1,0],[1,0],[1,0],[1,0],[0,1],[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
"angle": 'right'}, "angle": 'right'},
{"pos": [[24,1],[25,1],[26,1],[27,1],[27,2],[27,3],[27,4],[27,5],[27,6],[27,7],[27,8],[27,9],[27,10],[27,11],[27,12]], {"pos": [[24,1],[25,1],[26,1],[27,1],[27,2],[27,3],[27,4],[27,5],[27,6],[27,7],[27,8],[27,9],[27,10],[27,11],[27,12],[27,13],[27,14],[27,15],[27,16],[27,17]],
"vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]], "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
"angle": 'up'}] "angle": 'up'}]
map3 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1], map3 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],
...@@ -161,12 +161,12 @@ map3 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1], ...@@ -161,12 +161,12 @@ map3 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1],
# [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]] # [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]
start5 = [{"pos": [[6,1],[5,1],[4,1],[3,1],[3,2],[3,3],[3,4],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[3,9],[3,10]], start5 = [{"pos": [[6,1],[5,1],[4,1],[3,1],[3,2],[3,3],[3,4],[2,4],[2,5],[2,6],[2,7],[2,8],[2,9],[3,9],[3,10],[4,10],[4,11],[4,12],[4,13],[5,13]],
"vel": [[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[0,-1],[-1,0],[0,-1]], "vel": [[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[0,-1],[-1,0],[0,-1],[-1,0],[0,-1],[0,-1],[0,-1],[-1,0]],
"angle": 'right'}, "angle": 'right'},
{"pos": [[25,15],[25,16],[25,17],[25,18],[25,19],[25,20],[25,21],[25,22],[25,23],[25,24],[25,25],[25,26],[25,27],[25,28],[24,28]], {"pos": [[25,15],[25,16],[25,17],[25,18],[25,19],[25,20],[25,21],[25,22],[25,23],[25,24],[25,25],[25,26],[25,27],[25,28],[24,28],[24,28],[23,28],[22,28],[21,28],[20,28]],
"vel": [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[0,1],[0,1]], "vel": [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[0,1],[0,1],[0,1],[0,1],[0,1],[0,1],[0,1]],
"angle": 'left'}] "angle": 'left'}]
map5 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], map5 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
...@@ -208,12 +208,12 @@ map5 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], ...@@ -208,12 +208,12 @@ map5 = [[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
# "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]], # "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],
# "angle": 'right'}] # "angle": 'right'}]
start6 = [{"pos": [[6,5],[5,5],[4,5],[3,5],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20],[2,21],[2,22],[2,23],[2,24],[2,25],[2,26],[2,27],[2,28],[2,29],[2,0]], start6 = [{"pos": [[6,5],[5,5],[4,5],[3,5],[2,5],[2,6],[2,7],[2,8],[2,9],[2,10],[2,11],[2,12],[2,13],[2,14],[2,15],[2,16],[2,17],[2,18],[2,19],[2,20]],#[2,21],[2,22],[2,23],[2,24],[2,25],[2,26],[2,27],[2,28],[2,29],[2,0]],
"vel": [[0,1],[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]], "vel": [[0,1],[0,1],[0,1],[0,1],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],#[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]],
"angle": 'right'}, "angle": 'right'},
{"pos": [[21,25],[22,25],[23,25],[24,25],[25,25],[25,24],[25,23],[25,22],[25,21],[25,20],[25,19],[25,18],[25,17],[25,16],[25,15],[25,14],[25,13],[25,12],[25,11],[25,10],[25,9],[25,8],[25,7],[25,6],[25,5],[25,4],[25,3],[25,2],[25,1],[25,1]], {"pos": [[21,25],[22,25],[23,25],[24,25],[25,25],[25,24],[25,23],[25,22],[25,21],[25,20],[25,19],[25,18],[25,17],[25,16],[25,15],[25,14],[25,13],[25,12],[25,11],[25,10]],#[25,9],[25,8],[25,7],[25,6],[25,5],[25,4],[25,3],[25,2],[25,1],[25,1]],
"vel": [[0,-1],[0,-1],[0,-1],[0,-1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]], "vel": [[0,-1],[0,-1],[0,-1],[0,-1],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],#[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]],
"angle": 'right'}] "angle": 'right'}]
map6 = [[1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1], map6 = [[1,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1,0,1,1,1,1],
...@@ -290,7 +290,7 @@ start8 = [{"pos": [[4,13],[3,13],[2,13],[1,13]], ...@@ -290,7 +290,7 @@ start8 = [{"pos": [[4,13],[3,13],[2,13],[1,13]],
"vel": [[0,1],[0,1],[0,1],[0,1]], "vel": [[0,1],[0,1],[0,1],[0,1]],
"angle": 'down'}, "angle": 'down'},
{"pos": [[25,13],[26,13],[27,13],[28,13]], {"pos": [[26,13],[27,13],[28,13],[29,13]],
"vel": [[0,-1],[0,-1],[0,-1],[0,-1]], "vel": [[0,-1],[0,-1],[0,-1],[0,-1]],
"angle": 'up'}] "angle": 'up'}]
...@@ -306,7 +306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1,1,1,1,1,1,1,1], ...@@ -316,6 +315,7 @@ map8 = [[1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
......
...@@ -22,7 +22,7 @@ import maps ...@@ -22,7 +22,7 @@ import maps
snake_length = 15 snake_length = 15
# save location # save location
save_file = 'maps/map3.pickle' save_file = '../Shield/maps/map3.pickle'
# map to convert # map to convert
map = np.array(maps.map3) map = np.array(maps.map3)
...@@ -274,8 +274,8 @@ def graph_from_map(map): ...@@ -274,8 +274,8 @@ def graph_from_map(map):
nodes_map = wrap_around_edges(nodes_map) nodes_map = wrap_around_edges(nodes_map)
print('map') #print('map')
print(nodes_map) #print(nodes_map)
# add edges to the corresponding nodes # add edges to the corresponding nodes
for i in range(len(nodes_map)): for i in range(len(nodes_map)):
...@@ -291,9 +291,9 @@ def graph_from_map(map): ...@@ -291,9 +291,9 @@ def graph_from_map(map):
if j < len(nodes_map[i]) - 1 and nodes_map[i][j + 1] < 0: if j < len(nodes_map[i]) - 1 and nodes_map[i][j + 1] < 0:
nodes[current_node - 2].add_edge(nodes_map[i][j + 1]) nodes[current_node - 2].add_edge(nodes_map[i][j + 1])
print('nodes') #print('nodes')
for n in nodes: #for n in nodes:
print(str(n.node_number) + ": " + str(n.get_edges())) #print(str(n.node_number) + ": " + str(n.get_edges()))
return nodes_map, nodes return nodes_map, nodes
...@@ -315,43 +315,53 @@ def networkx_from_graph(graph): ...@@ -315,43 +315,53 @@ def networkx_from_graph(graph):
edges[e] = ([n.node_number], np.sum(nodes_map == e)) edges[e] = ([n.node_number], np.sum(nodes_map == e))
else: else:
edges[e][0].append(n.node_number) edges[e][0].append(n.node_number)
print('edges') #print('edges')
print(edges) #print(edges)
for k, e in edges.items(): for k, e in edges.items():
nx_graph.add_edge(e[0][0], e[0][1], weight=e[1] + 1) nx_graph.add_edge(e[0][0], e[0][1], weight=e[1] + 1)
return nx_graph, edges return nx_graph, edges
# get map with nodes and edges def generate_graph(length, new_map, path):
graph = graph_from_map(map) global snake_length
# get networkx graph and edges global map
nx_graph, edges = networkx_from_graph(graph) global save_file
snake_length = length
# compute all shortest paths with length of snake map = np.array(new_map)
paths = dict(nx.all_pairs_dijkstra_path(nx_graph, cutoff=snake_length, weight='weight')) save_file = path
# find longest path with length of snake # get map with nodes and edges
max = 0 graph = graph_from_map(map)
for d1 in paths.values(): # get networkx graph and edges
for d2 in d1.values(): nx_graph, edges = networkx_from_graph(graph)
max = len(d2) if len(d2) > max else max
# compute all shortest paths with length of snake
# draw network paths = dict(nx.all_pairs_dijkstra_path(nx_graph, cutoff=snake_length, weight='weight'))
plt.plot() # find longest path with length of snake
# networkx can't really draw multigraphs max = 0
nx.draw_spectral(nx_graph, with_labels=True, font_weight='bold', connectionstyle='arc3, rad = 0.1') for d1 in paths.values():
labels = nx.get_edge_attributes(nx_graph, 'weight') for d2 in d1.values():
plt.show() max = len(d2) if len(d2) > max else max
# get amount of nodes and edges # draw network
node_name_max = len(nx_graph.nodes) + 1 plt.plot()
edge_name_max = 0 # networkx can't really draw multigraphs
for edge_name in edges.keys(): nx.draw_spectral(nx_graph, with_labels=True, font_weight='bold', connectionstyle='arc3, rad = 0.1')
if edge_name < edge_name_max: labels = nx.get_edge_attributes(nx_graph, 'weight')
edge_name_max = edge_name #plt.show()
# get maximum edge length # get amount of nodes and edges
dist_max = int(sorted(nx_graph.edges(data=True), key=lambda x: x[2]['weight'], reverse=True)[0][2]['weight']) - 1 node_name_max = len(nx_graph.nodes) + 1
edge_name_max = 0
# save all infos in file for edge_name in edges.keys():
pickle.dump((graph[0], edges, max, node_name_max, edge_name_max, dist_max), open(save_file, 'wb')) if edge_name < edge_name_max:
# nx.write_gpickle(nx_graph, 'graph1.pickle') edge_name_max = edge_name
# get maximum edge length
dist_max = int(sorted(nx_graph.edges(data=True), key=lambda x: x[2]['weight'], reverse=True)[0][2]['weight']) - 1
# save all infos in file
pickle.dump((graph[0], edges, max, node_name_max, edge_name_max, dist_max), open(save_file, 'wb'))
# nx.write_gpickle(nx_graph, 'graph1.pickle')
print("Finished creating graph")
No preview for this file type
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment