diff --git a/alrys/alryslib.c b/alrys/alryslib.c index 759d4eb..9d5434a 100644 --- a/alrys/alryslib.c +++ b/alrys/alryslib.c @@ -208,27 +208,27 @@ double score(double *steps, int size) { int i; double a, b, x, y, l; - double position[] = {47.5, 43.5, 0.0}; + double position[3] = {steps[0], steps[1], 0.0}; struct STATE state; - state.x = 47.5; - state.y = 43.5; + state.x = steps[0]; + state.y = steps[1]; state.a = 0; state.s = 0; state.life = 250; state.tockens = 1; - state.boat = 0; - state.dsize = 0; + state.boat = steps[2]; + state.dsize = steps[3]; state.vlast = 0; i = 0; - for(i = 0; i < size; ++i) + for(i = 4; i < size - 3; i += 4) { - x = steps[0 + i * 4]; - a = steps[1 + i * 4]; - y = steps[2 + i * 4]; - b = steps[3 + i * 4]; + x = steps[0 + i]; + a = steps[1 + i]; + y = steps[2 + i]; + b = steps[3 + i]; x += a * 1e-14; y += b * 1e-14; a = atan2(y - position[1], x - position[0]) * 180.0 / M_PI - position[2]; diff --git a/alrys/editor.py b/alrys/editor.py index 369b465..f654430 100644 --- a/alrys/editor.py +++ b/alrys/editor.py @@ -60,7 +60,7 @@ def read_steps(buffer): def write_steps(steps): size = len(steps) buffer = '\n' - buffer += 'start (x y angle boat):\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 += '\n' buffer += 'steps (x a y b):\n' @@ -74,7 +74,7 @@ def optimize(): buffer = text.get('1.0', 'end - 1c') steps = read_steps(buffer) draw_path(steps, False) - smax = state[3] + 1000 * (len(state[7]) >= 10) + smax = state[3] + 1000 * (state[9] >= 10) size = len(steps) kmax = -1 cmax = -1 @@ -85,7 +85,7 @@ def optimize(): buffer = write_steps(steps) steps = read_steps(buffer) draw_path(steps, False) - s = state[3] + 1000 * (len(state[7]) >= 10) + s = state[3] + 1000 * (state[9] >= 10) if smax < s: smax = s kmax = k @@ -119,7 +119,7 @@ def draw_coordinates(): def draw_state(): global canvas, map_h, state - score = state[3] + 1000 * (len(state[7]) >= 10) + score = state[3] + 1000 * (state[9] >= 10) t = 'score: %20.15f, life: %5.1f' % (score, state[4]) canvas.create_text(4, map_h + 20, anchor = 'nw', text = t, fill = 'black', font = 'TkFixedFont') @@ -130,11 +130,13 @@ def draw_help(): def draw_path(steps, draw = True): global state - state = [0, 0, 0, 0, 250, 1, 0, [], 0] + state = [0, 0, 0, 0, 250, 1, 0, 0, [], 0] + a1 = 0 if len(steps) >= 4: - x1, y1, a1 = steps[0:3] - state[0:3] = x1, y1, a1 - state[6] = steps[3] + x1, y1 = steps[0:2] + 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] x2 += a * 1e-14 @@ -275,26 +277,27 @@ def en_avant(l): state[3] -= d # score state[4] -= d # life state[0:2] = l[k][0:2] - if c1 == 7 and not(xr in state[7]): + if c1 == 7 and not(xr in state[8]): if state[4] >= 100: state[4] = max(state[4] - 100, 0) state[3] += 100 state[5] += 1 - state[7].append(xr) - if c1 == 6 and xr != state[8]: - if not state[6] and len(state[7]) >= 9: + state[8].append(xr) + state[9] += 1 + if c1 == 6 and xr != state[7]: + if not state[6] and state[9] >= 9: state[6] = 1 elif state[5]: state[4] = min(250, state[4] + 120) state[5] -= 1 - state[8] = xr + state[7] = xr def a_droite(a): state[2] += a coordinates = [0, 0, None] buffer = ''' -start (x y angle boat): +start (x y boat keeps): 47.500 43.500 0 0 steps (x a y b):