update text format in editor.py

This commit is contained in:
Pavel 2021-10-20 09:25:23 +02:00
parent dba5f26264
commit 4a8e0372d9
1 changed files with 24 additions and 15 deletions

View File

@ -58,14 +58,17 @@ def read_steps(buffer):
return steps
def write_steps(steps):
size = len(steps)
buffer = '\n'
buffer += 'start (x y boat keeps):\n'
buffer += '%7.3f %6.3f %g %d\n' % (steps[0], steps[1], steps[2], steps[3])
buffer += 'state (boat donjons):\n'
buffer += '%d %d\n' % (steps[0], steps[1])
buffer += '\n'
buffer += 'start (x a y b):\n'
buffer += '%7.3f %2d %6.3f %2d\n' % (steps[2], steps[3], steps[4], steps[5])
buffer += '\n'
buffer += 'steps (x a y b):\n'
for k in range(1, size // 4):
x2, a, y2, b = steps[k * 4:(k + 1) * 4]
size = len(steps)
for k in range(6, size - 3, 4):
x2, a, y2, b = steps[k:k + 4]
buffer += '%7.3f %2d %6.3f %2d\n' % (x2, a, y2, b)
return buffer
@ -75,10 +78,10 @@ def optimize():
steps = read_steps(buffer)
draw_path(steps, False)
smax = state[3] + 1000 * (state[9] >= 10)
size = len(steps)
kmax = -1
cmax = -1
for k in range(4, size, 2):
size = len(steps)
for k in range(6, size, 2):
backup = steps[k]
for v in [-0.03, -0.02, -0.01, 0.01, 0.02, 0.03]:
steps[k] = backup + v
@ -132,13 +135,16 @@ def draw_path(steps, draw = True):
global state
state = [0, 0, 0, 0, 250, 1, 0, 0, [], 0]
a1 = 0
if len(steps) >= 4:
x1, y1 = steps[0:2]
size = len(steps)
if size >= 6:
state[6] = steps[0]
state[9] = steps[1]
x1, a, y1, b = steps[2:6]
x1 += a * 1e-14
y1 += b * 1e-14
state[0:2] = x1, y1
state[6] = steps[2]
state[9] = steps[3]
for k in range(1, len(steps) // 4):
x2, a, y2, b = steps[k * 4:(k + 1) * 4]
for k in range(6, size - 3, 4):
x2, a, y2, b = steps[k:k + 4]
x2 += a * 1e-14
y2 += b * 1e-14
da = atan2(y2 - y1, x2 - x1) * 180.0 / pi - a1
@ -293,8 +299,11 @@ def a_droite(a): state[2] += a
coordinates = [0, 0, None]
buffer = '''
start (x y boat keeps):
47.500 43.500 0 0
state (boat donjons):
0 0
start (x a y b):
47.500 0 43.500 0
steps (x a y b):
49.500 0 43.500 0