# AI Moving

## version 1 by Sebastian Rahn

Section 1.3 - Complex Chasing

[Chasing something behind a large obstacle]

Every person has a truth state called Wallrunner.
Every person has a direction called Runner_Richtung.
Follow_Runner is a thing that varies.
Follow_Goal is a thing that varies.

Follow_Counter is a number that varies.
Check_Direction_Left is a number that varies.
Check_Direction_Right is a number that varies.
Obstacle_End is a truth state that varies.
Current X-Axis is a text that varies.

To use Obstacle Course:
change Obstacle_End to false;
change Check_Direction_Left to 0;
change Check_Direction_Right to 0;
If Follow_Richtung is north [North]
begin;
If (X-Axis of Follow_Runner - 1) is 0
begin;
change Obstacle_End to true;
change Wallrunner of Follow_Runner to false;
otherwise;
pick sector Y-Axis of Follow_Runner and (X-Axis of Follow_Runner - 1) in location of Follow_Runner;
If Tmp_Picked is not Wall
begin;
change Obstacle_End to true;
change Wallrunner of Follow_Runner to false;
end if;
end if;
If Obstacle_End is false
begin;
change Tmp_Picked_Y to Y-Axis of Follow_Runner;
choose row with Letters28 of Tmp_Picked_Y in Table 200;
change tmp to Number Entry;
choose row 1 in Table_Location;
change Follow_Counter to Width Entry;
repeat with X running from 1 to Follow_Counter
begin;
If Obstacle_End is false
begin;
If (tmp - X) > 0
begin;
pick sector (tmp - X) and (X-Axis of Follow_Runner - 1) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Left by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
If (tmp + X) < Follow_Counter
begin;
pick sector (tmp + X) and (X-Axis of Follow_Runner - 1) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Right by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
end if;
end repeat;
If Check_Direction_Left > Check_Direction_Right
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to northeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to east;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left < Check_Direction_Right
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to west;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left is Check_Direction_Right
begin;
let counter be a random number between 0 and 1;
If counter is 0
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to west;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If counter is 1
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to northeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to east;
change Wallrunner of Follow_Runner to true;
end if;
end if;
end if;
end if;
end if;
If Follow_Richtung is south [South]
begin;
choose row 1 in Table_Location;
If (X-Axis of Follow_Runner + 1) > Height Entry
begin;
change Obstacle_End to true;
otherwise;
pick sector Y-Axis of Follow_Runner and (X-Axis of Follow_Runner + 1) in location of Follow_Runner;
If Tmp_Picked is not Wall
begin;
change Obstacle_End to true;
change Wallrunner of Follow_Runner to false;
end if;
end if;
If Obstacle_End is false
begin;
change Tmp_Picked_Y to Y-Axis of Follow_Runner;
choose row with Letters28 of Tmp_Picked_Y in Table 200;
change tmp to Number Entry;
choose row 1 in Table_Location;
change Follow_Counter to Width Entry;
repeat with X running from 1 to Follow_Counter
begin;
If Obstacle_End is false
begin;
If (tmp - X) > 0
begin;
pick sector (tmp - X) and (X-Axis of Follow_Runner + 1) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Left by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
If (tmp + X) < Follow_Counter
begin;
pick sector (tmp + X) and (X-Axis of Follow_Runner + 1) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Right by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
end if;
end repeat;
If Check_Direction_Left > Check_Direction_Right
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to east;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left < Check_Direction_Right
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to southwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to west;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left is Check_Direction_Right
begin;
let counter be a random number between 0 and 1;
If counter is 0
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to southwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to west;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If counter is 1
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to east;
change Wallrunner of Follow_Runner to true;
end if;
end if;
end if;
end if;
end if;
If Follow_Richtung is east [East]
begin;
change Tmp_Picked_Y to Y-Axis of Follow_Runner;
choose row with Letters28 of Tmp_Picked_Y in Table 200;
change tmp to Number Entry;
pick sector (tmp + 1) and X-Axis of Follow_Runner in location of Follow_Runner;
If Tmp_Picked is not Wall
begin;
change Obstacle_End to true;
change Wallrunner of Follow_Runner to false;
end if;
If Obstacle_End is false
begin;
choose row 1 in Table_Location;
change Follow_Counter to Height Entry;
repeat with X running from 1 to Follow_Counter
begin;
If Obstacle_End is false
begin;
If (X-Axis of Follow_Runner - X) > 0
begin;
pick sector (tmp + 1) and (X-Axis of Follow_Runner - X) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Left by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
If (X-Axis of Follow_Runner + X) < Follow_Counter
begin;
pick sector (tmp + 1) and (X-Axis of Follow_Runner + X) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Right by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
end if;
end repeat;
If Check_Direction_Left > Check_Direction_Right
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to south;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left < Check_Direction_Right
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to north;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left is Check_Direction_Right
begin;
let counter be a random number between 0 and 1;
If counter is 0
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to north;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If counter is 1
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southeast;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to south;
change Wallrunner of Follow_Runner to true;
end if;
end if;
end if;
end if;
end if;
If Follow_Richtung is west [West]
begin;
change Tmp_Picked_Y to Y-Axis of Follow_Runner;
choose row with Letters28 of Tmp_Picked_Y in Table 200;
change tmp to Number Entry;
pick sector (tmp - 1) and X-Axis of Follow_Runner in location of Follow_Runner;
If Tmp_Picked is not Wall
begin;
change Obstacle_End to true;
change Wallrunner of Follow_Runner to false;
end if;
If Obstacle_End is false
begin;
choose row 1 in Table_Location;
change Follow_Counter to Height Entry;
repeat with X running from 1 to Follow_Counter
begin;
If Obstacle_End is false
begin;
If (X-Axis of Follow_Runner - X) > 0
begin;
pick sector (tmp - 1) and (X-Axis of Follow_Runner - X) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Left by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
If (X-Axis of Follow_Runner + X) < Follow_Counter
begin;
pick sector (tmp - 1) and (X-Axis of Follow_Runner + X) in location of Follow_Runner;
If Tmp_Picked is Wall
begin;
increase Check_Direction_Right by 1;
otherwise;
change Obstacle_End to true;
end if;
end if;
end if;
end repeat;
If Check_Direction_Left > Check_Direction_Right
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to south;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left < Check_Direction_Right
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to north;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If Check_Direction_Left is Check_Direction_Right
begin;
let counter be a random number between 0 and 1;
If counter is 0
begin;
If Check_Direction_Left is 0
begin;
change tmp_Direction to northwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Left > 0
begin;
change tmp_Direction to north;
change Wallrunner of Follow_Runner to true;
end if;
end if;
If counter is 1
begin;
If Check_Direction_Right is 0
begin;
change tmp_Direction to southwest;
change Wallrunner of Follow_Runner to false;
end if;
If Check_Direction_Right > 0
begin;
change tmp_Direction to south;
change Wallrunner of Follow_Runner to true;
end if;
end if;
end if;
end if;
end if;