# AI Moving

## version 1 by Sebastian Rahn

**Section 2 - Calculating Distance**

Distance_Done is a truth state that varies.

Stepscounter is a number that varies.

To calculate minimum Distance between (Start - a thing) and (Finish - a thing):

If location of Start is location of Finish

begin;

Change Stepscounter to 0;

Change Distance_Done to false;

If Start is not connected with Finish

begin;

If Start is straight of Finish

begin;

If Start is below of Finish

begin;

Change Stepscounter to X-Axis of Start;

decrease Stepscounter by X-Axis of Finish;

decrease Stepscounter by 1;

end if;

If Start is above of Finish

begin;

Change Stepscounter to X-Axis of Finish - 1;

decrease Stepscounter by X-Axis of Start;

end if;

Change Distance_Done to true;

end if;

If Distance_Done is false

begin;

If Start is on a sector right of Finish

begin;

If Start is below of Finish

begin;

Change Stepscounter to X-Axis of Start;

decrease Stepscounter by X-Axis of Finish;

decrease Stepscounter by 1;

end if;

If Start is above of Finish

begin;

Change Stepscounter to X-Axis of Finish - 1;

decrease Stepscounter by X-Axis of Start;

end if;

Change Distance_Done to true;

end if;

end if;

If Distance_Done is false

begin;

If Start is on a sector left of Finish

begin;

If Start is below of Finish

begin;

Change Stepscounter to X-Axis of Start;

decrease Stepscounter by X-Axis of Finish;

decrease Stepscounter by 1;

end if;

If Start is above of Finish

begin;

Change Stepscounter to X-Axis of Finish - 1;

decrease Stepscounter by X-Axis of Start;

end if;

Change Distance_Done to true;

end if;

end if;

If Distance_Done is false

begin;

If Start is indirect neighbour of Finish

begin;

choose row with Letters28 of Y-Axis of Start in Table 200;

Change tmp to Number Entry;

choose row with Letters28 of Y-Axis of Finish in Table 200;

If tmp > Number Entry

begin;

Change Stepscounter to tmp;

decrease Stepscounter by Number Entry;

decrease Stepscounter by 1;

end if;

If tmp < Number Entry

begin;

Change Stepscounter to (Number Entry - 1);

decrease Stepscounter by tmp;

end if;

Change Distance_Done to true;

end if;

end if;

If Distance_Done is false

begin;

If Start is left of Finish

begin;

choose row with Letters28 of Y-Axis of Start in Table 200;

Change tmp to Number Entry;

choose row with Letters28 of Y-Axis of Finish in Table 200;

If Start is above of Finish

begin;

Change tmp_X to X-Axis of Finish;

Decrease tmp_X by X-Axis of Start;

Change tmp to (Number Entry - tmp);

If tmp > tmp_X, change Stepscounter to (tmp - 1);

If tmp < tmp_X, change Stepscounter to (tmp_X - 1);

If tmp is tmp_X, change Stepscounter to (tmp_X - 1);

end if;

If Start is below of Finish

begin;

Change tmp_X to X-Axis of Start;

Decrease tmp_X by X-Axis of Finish;

Change tmp to (Number Entry - tmp);

If tmp > tmp_X, change Stepscounter to (tmp - 1);

If tmp < tmp_X, change Stepscounter to (tmp_X - 1);

If tmp is tmp_X, change Stepscounter to (tmp_X - 1);

end if;

Change Distance_Done to true;

end if;

end if;

If Start is right of Finish

begin;

choose row with Letters28 of Y-Axis of Finish in Table 200;

Change tmp to Number Entry;

choose row with Letters28 of Y-Axis of Start in Table 200;

If Start is above of Finish

begin;

Change tmp_X to X-Axis of Finish;

Decrease tmp_X by X-Axis of Start;

Change tmp to (Number Entry - tmp);

If tmp > tmp_X, change Stepscounter to (tmp - 1);

If tmp < tmp_X, change Stepscounter to (tmp_X - 1);

If tmp is tmp_X, change Stepscounter to (tmp_X - 1);

end if;

If Start is below of Finish

begin;

Change tmp_X to X-Axis of Start;

Decrease tmp_X by X-Axis of Finish;

Change tmp to (Number Entry - tmp);

If tmp > tmp_X, change Stepscounter to (tmp - 1);

If tmp < tmp_X, change Stepscounter to (tmp_X - 1);

If tmp is tmp_X, change Stepscounter to (tmp_X - 1);

end if;

end if;

otherwise;

Change Stepscounter to 0;

end if;

end if.

AI Moving ends here.