Skip to content
Snippets Groups Projects
Commit 8161387d authored by Nathaniel Mattsson's avatar Nathaniel Mattsson
Browse files

Implement basic spaceshipsolver

parent 947c243e
No related branches found
No related tags found
No related merge requests found
import numpy as np
def spaceshipsolver(coordinates):
velocity=np.array([0,0])
moves=""
curr_coords = np.array([0,0])
while(coordinates):
while((curr_coords!=coordinates[0]).any()):
dist_after=coordinates[0]-curr_coords-velocity
if(dist_after[0]>0):
if(dist_after[1]>0):
moves+='9'
velocity += np.array([1,1])
elif(dist_after[1]<0):
moves+='3'
velocity += np.array([1,-1])
else:
moves+='6'
velocity += np.array([1,0])
elif(dist_after[0]<0):
if(dist_after[1]>0):
moves+='7'
velocity += np.array([-1,1])
elif(dist_after[1]<0):
moves+='1'
velocity += np.array([-1,-1])
else:
moves+='4'
velocity += np.array([-1,0])
else:
if(dist_after[1]>0):
moves+=('8')
velocity += np.array([0,1])
elif(dist_after[1]<0):
moves+=('2')
velocity += np.array([0,-1])
else:
moves+='5'
velocity += np.array([0,0])
curr_coords+=velocity
coordinates.pop(0)
return moves
def list_coordinates_to_arrays(coordinates):
return [np.array(x) for x in coordinates]
coords=input('coords:')
coords=coords.split('.')
for x in range(len(coords)):
coords[x]=coords[x].split(',')
for k in range(len(coords[x])):
coords[x][k]=int(coords[x][k])
coords=list_coordinates_to_arrays(coords)
print(spaceshipsolver(coords))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment