This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalgorithm_fastest.py
90 lines (77 loc) · 2.44 KB
/
algorithm_fastest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
import state
import commands
from coord import Coord, diff, UP, DOWN, LEFT, RIGHT, FORWARD, BACK
import sys
import math
from algorithm import *
pts = None
minPt = 0
def next_best_point(st):
global pts
global minPt
if pts is None:
pts = list(st.matrix.to_fill())
j = None
while st.matrix[pts[minPt]].is_full() or not st.matrix[pts[minPt]].is_model():
minPt += 1
for i in range(minPt, len(pts)):
if st.matrix[pts[i]].is_void() and st.matrix[pts[i]].is_model() and st.matrix.would_be_grounded(pts[i]):
j = i
break
if j is None:
return None
return pts[j]
zcoords = []
def closest_best_point(st):
bot = st.bots[0]
global zcoords
print("closest best pt")
if len(zcoords) == 0:
zcoords = st.matrix.fill_next(bot.pos + DOWN)
zcoords.reverse()
pt = zcoords.pop()
print("pt ofund")
return pt
def fill_neighbours(st, bot):
pts = [
bot.pos + DOWN + LEFT,
bot.pos + DOWN + RIGHT,
bot.pos + DOWN + FORWARD,
bot.pos + DOWN + BACK
]
for pt in pts:
if st.matrix.is_valid_point(pt) and st.matrix.would_be_grounded(pt) and st.matrix[pt].is_void() and st.matrix[pt].is_model():
bot.fill(pt - bot.pos)
def shortest_path_algo(st):
bot = st.bots[0]
bot.smove(UP)
pts = list(st.matrix.keys())
minPt = 0
while not st.is_model_finished():
pt = next_best_point(st)
for a in pt.adjacent(st.R):
# print(a)
if st.matrix[a].is_void():
path = shortest_path(st, st.bots[0], a)
# print(path)
if path is not None:
compress(st, st.bots[0], path)
# print(st.bots[0].pos)
bot.fill(pt - st.bots[0].pos)
# fill_neighbours(st, st.bots[0])
break
# print("done")
# break
if __name__ == '__main__':
problem = int(sys.argv[1])
st = state.State.create(problem=problem)
shortest_path_algo(st)
back_to_base(st, st.bots[0])
st.bots[0].halt()
st.step()
print( st )
print( 'energy: {}, default: {}, score: {:0.3f}/{:0.3f}'.format( st.energy, st.default_energy, st.score, st.score_max ) )
data = commands.export_nbt( st.trace )
with open("submission/LA"+str(problem).zfill(3)+".nbt", "wb") as file:
file.write(data)