DIM SHARED x2b(8) AS INTEGER, y2b(8) AS INTEGER

x2b(1) = 0: y2b(1) = 1

x2b(2) = 0: y2b(2) = -1

x2b(3) = 1: y2b(3) = 0

x2b(4) = -1: y2b(4) = 0

x2b(5) = -1: y2b(5) = 1

x2b(6) = 1: y2b(6) = 1

x2b(7) = 1: y2b(7) = -1

x2b(8) = -1: y2b(8) = -1

FUNCTION try.straight% (x0 AS INTEGER, y0 AS INTEGER, x1 AS INTEGER, y1 AS INTEGER)

DIM diff AS INTEGER, cost.min AS INTEGER, x0b AS INTEGER, y0b AS INTEGER

DO

cost.min = 32767

FOR i = 1 TO 8

diff = (x1 - x0 - x2b(i)) ^ 2 + (y1 - y0 - y2b(i)) ^ 2

IF diff < cost.min THEN cost.min = diff: x0b = x0 + x2b(i): y0b = y0 + y2b(i)

NEXT i

x0 = x0b: y0 = y0b

IF x0 = x1 THEN IF y0 = y1 THEN try.straight% = 1: EXIT DO

LOOP

END FUNCTION