626 lines
12 KiB
Plaintext
626 lines
12 KiB
Plaintext
!Folgende Änderung sind notwendig, damit das Programm läuft
|
|
!(maximale Anzahl der Operationen)
|
|
!TAM.Machine
|
|
!Zeile 59: new Instruction[1024] -> new Instruction[2048]
|
|
!Zeile 66: PB = 1024, -> PB = 2048,
|
|
!Zeile 67: PT = 1052; -> PT = 2076;
|
|
|
|
!Roboter-Simulation
|
|
!in dem Programm wird ein Roboter simuliert, der Hütchen aufstellen und wegnehmen kann
|
|
!Wände / Hindernisse werden durch x markiert und können nicht überlaufen werden
|
|
!Ein Hütchen wird durch o markiert
|
|
!Der Roboter wird durch R markiert
|
|
!Steht der Roboter auf einem Hütchen, wird das mit B markiert
|
|
|
|
!Dieser Teil dient nur als Beispiel, dass ohne Benutzereingaben "durchläuft".
|
|
!weiter unten kann "session" auf einen anderen Wert gestellt werden, um so ein anderes Beispiel zu betrachten.
|
|
|
|
|
|
let
|
|
|
|
!Deklaration der Variable errorOccurred
|
|
var errorOccurred : Boolean;
|
|
|
|
!Gibt den Fehler mit der Kennung x aus
|
|
proc printError (x : Integer) ~
|
|
begin
|
|
if (x = 0) !World too small
|
|
then begin
|
|
put('W'); put('o'); put('r'); put('l'); put('d'); put(' ');
|
|
put('t'); put('o'); put('o'); put(' ');
|
|
put('s'); put('m'); put('a'); put('l'); put('l');
|
|
end
|
|
else if (x = 1) !World too big
|
|
then begin
|
|
put('W'); put('o'); put('r'); put('l'); put('d'); put(' ');
|
|
put('t'); put('o'); put('o'); put(' ');
|
|
put('b'); put('i'); put('g');
|
|
end
|
|
else if (x = 2) !Koord. out of World
|
|
then begin
|
|
put('K'); put('o'); put('o'); put('r'); put('d'); put(' ');
|
|
put('o'); put('u'); put('t'); put(' ');
|
|
put('o'); put('f'); put(' ');
|
|
put('W'); put('o'); put('r'); put('l'); put('d');
|
|
end
|
|
else if (x = 3) !Koord. in Wall
|
|
then begin
|
|
put('K'); put('o'); put('o'); put('r'); put('d'); put(' ');
|
|
put('i'); put('n'); put(' ');
|
|
put('W'); put('a'); put('l'); put('l');
|
|
end
|
|
else if (x = 4) !Error(s) occurred EXITING!!
|
|
then begin
|
|
put('E'); put('r'); put('r'); put('o'); put('r'); put(' ');
|
|
put('o'); put('c'); put('c'); put('u'); put('r'); put('r'); put('e'); put('d'); put(' ');
|
|
put('E'); put('X'); put('I'); put('T'); put('I'); put('N'); put('G');
|
|
end
|
|
else if (x = 5) !Wrong Direction
|
|
then begin
|
|
put('W'); put('r'); put('o'); put('n'); put('g'); put(' ');
|
|
put('D'); put('i'); put('r'); put('e'); put('c'); put('t'); put('i'); put('o'); put('n');
|
|
end
|
|
else if (x = 6) !Unknown Command
|
|
then begin
|
|
put('U'); put('n'); put('k'); put('n'); put('o'); put('w'); put('n'); put(' ');
|
|
put('C'); put('o'); put('m'); put('m'); put('a'); put('n'); put('d');
|
|
end
|
|
else if (x = 7) !No Cone at curr. Pos.
|
|
then begin
|
|
put('N'); put('o'); put(' ');
|
|
put('C'); put('o'); put('n'); put('e'); put(' ');
|
|
put('a'); put('t'); put(' ');
|
|
put('c'); put('u'); put('r'); put('r'); put(' ');
|
|
put('P'); put('o'); put('s');
|
|
end
|
|
else
|
|
begin
|
|
end;
|
|
|
|
put('!');
|
|
puteol();
|
|
errorOccurred := true;
|
|
end;
|
|
|
|
|
|
!Deklaration des Typs World
|
|
type Row ~ record
|
|
y : array 16 of Char,
|
|
length : Integer
|
|
end;
|
|
type World ~ record
|
|
x : array 16 of Row,
|
|
length : Integer
|
|
end;
|
|
|
|
!Deklaration des Typs Robot
|
|
type Robot ~ record
|
|
cones : Integer,
|
|
x : Integer,
|
|
y : Integer
|
|
end;
|
|
|
|
|
|
!Deklaration der benötigten Variablen
|
|
var size : Integer;
|
|
var world : World;
|
|
var robot : Robot;
|
|
var befehl : Char;
|
|
var counter : Integer;
|
|
var inX : Integer;
|
|
var inY : Integer;
|
|
var session : Integer;
|
|
|
|
!Initialisierung der Welt
|
|
!Am Rand werden Mauern / Hindernisse gesetzt
|
|
proc initWorld () ~
|
|
let
|
|
var x : Integer;
|
|
var y : Integer
|
|
in begin
|
|
x := 0;
|
|
while (x < size) do
|
|
begin
|
|
y := 0;
|
|
while (y < size) do
|
|
begin
|
|
if((x = (size - 1)) \/ (x = 0) \/ (y = (size - 1)) \/ (y = 0))
|
|
then
|
|
world.x[x].y[y] := 'x'
|
|
else
|
|
world.x[x].y[y] := ' ';
|
|
y := y + 1;
|
|
end;
|
|
x := x + 1;
|
|
end;
|
|
end;
|
|
|
|
!Initialisierung des Roboters
|
|
!Die Position des Roboters wird mit 1/1 initialisiert
|
|
proc initRobot () ~
|
|
begin
|
|
robot.cones := 0;
|
|
robot.x := 1;
|
|
robot.y := 1;
|
|
end;
|
|
|
|
!Ausgabe der Welt
|
|
!Roboter: R
|
|
!Wand / Hinderniss: x
|
|
!Hütchen: o
|
|
!Roboter + Hütchen: B
|
|
proc printWorld () ~
|
|
let
|
|
var x : Integer;
|
|
var y : Integer
|
|
in begin
|
|
x := 0;
|
|
while(x < size) do
|
|
begin
|
|
y := 0;
|
|
while(y < size) do
|
|
begin
|
|
if ((robot.x = x) /\ (robot.y = y))
|
|
then
|
|
if (world.x[x].y[y] = 'o')
|
|
then
|
|
put('B')
|
|
else
|
|
put('R')
|
|
else
|
|
put(world.x[x].y[y]);
|
|
put(' ');
|
|
y := y + 1;
|
|
end;
|
|
puteol();
|
|
x := x + 1;
|
|
end;
|
|
puteol();
|
|
end;
|
|
|
|
!Setze ein Hütchen
|
|
proc putCone (x : Integer, y : Integer) ~
|
|
begin
|
|
if((x >= size) \/ (x <= 0) \/ (y >= size) \/ (y <= 0))
|
|
then
|
|
printError(2)
|
|
else
|
|
if(world.x[x].y[y] = 'x')
|
|
then
|
|
printError(3)
|
|
else
|
|
world.x[x].y[y] := 'o';
|
|
end;
|
|
|
|
!Setze Wand / Hinderniss
|
|
proc putWall (x : Integer, y : Integer) ~
|
|
begin
|
|
if((x >= (size - 1)) \/ (x <= 0) \/ (y >= (size - 1)) \/ (y <= 0))
|
|
then
|
|
printError(2)
|
|
else
|
|
world.x[x].y[y] := 'x';
|
|
end;
|
|
|
|
!Roboter setzt ein Hütchen an seiner Position
|
|
proc putConeRobot () ~
|
|
begin
|
|
world.x[robot.x].y[robot.y] := 'o';
|
|
! put('R'); put('o'); put('b'); put('o'); put('t'); put(':'); put(' ');
|
|
put('S'); put('e'); put('t'); put(' '); put('C');
|
|
put('o'); put('n'); put('e'); put(' ');
|
|
put('a');put('t');put(' ');putint(robot.x);put('/');putint(robot.y);puteol();
|
|
end;
|
|
|
|
!Roboter nimmt ein Hütchen an seiner Position auf
|
|
proc pickUpCone () ~
|
|
begin
|
|
if(world.x[robot.x].y[robot.y] = 'o')
|
|
then
|
|
begin
|
|
world.x[robot.x].y[robot.y] := ' ';
|
|
! put('R');put('o');put('b');put('o');put('t');put(':');put(' ');
|
|
put('P');put('i');put('c');put('k');put(' ');put('u');put('p');put(' ');put('C');put('o');put('n');put('e');put(' ');
|
|
put('a');put('t');put(' ');putint(robot.x);put('/');putint(robot.y);puteol();
|
|
end
|
|
else
|
|
printError(7);
|
|
end;
|
|
|
|
!Bewege Roboter
|
|
proc moveRobot (c : Char) ~
|
|
let
|
|
var newX : Integer;
|
|
var newY : Integer
|
|
in begin
|
|
newX := robot.x;
|
|
newY := robot.y;
|
|
if (c = 'w')
|
|
then
|
|
newX := newX - 1
|
|
else if (c = 's')
|
|
then
|
|
newX := newX + 1
|
|
else if (c = 'a')
|
|
then
|
|
newY := newY - 1
|
|
else if (c = 'd')
|
|
then
|
|
newY := newY + 1
|
|
else
|
|
begin
|
|
printError(5)
|
|
end;
|
|
if(world.x[newX].y[newY] = 'x')
|
|
then
|
|
printError(3)
|
|
else
|
|
begin
|
|
robot.x := newX;
|
|
robot.y := newY;
|
|
! put('R');put('o');put('b');put('o');put('t');put(':');put(' ');
|
|
put('M'); put('o'); put('v'); put('e'); put(':'); put(' '); put(c);
|
|
put(' ');put('t');put('o');put(' ');putint(robot.x);put('/'); putint(robot.y); puteol()
|
|
end;
|
|
end
|
|
|
|
in begin
|
|
|
|
session := 1; !bisher belegte Beispiel sind session = 0 und session = 1
|
|
|
|
if (session = 0)
|
|
then begin
|
|
!Beispiel-Simulation 1
|
|
put('B'); put('s'); put('p'); put('.'); put('1'); puteol(); puteol();
|
|
size := 16;
|
|
initWorld();
|
|
initRobot();
|
|
printWorld();
|
|
|
|
putWall(2,2);
|
|
printWorld();
|
|
putWall(3,3);
|
|
printWorld();
|
|
putWall(4,4);
|
|
printWorld();
|
|
putWall(5,5);
|
|
printWorld();
|
|
putWall(6,6);
|
|
printWorld();
|
|
putWall(7,7);
|
|
printWorld();
|
|
putWall(8,8);
|
|
printWorld();
|
|
putWall(9,9);
|
|
printWorld();
|
|
putWall(10,10);
|
|
printWorld();
|
|
putWall(11,11);
|
|
printWorld();
|
|
putWall(12,12);
|
|
printWorld();
|
|
putWall(13,13);
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
|
|
end
|
|
else if (session = 1)
|
|
then begin
|
|
!Beispiel-Simulation 2
|
|
put('B'); put('s'); put('p'); put('.'); put('2'); puteol(); puteol();
|
|
size := 10;
|
|
initWorld();
|
|
initRobot();
|
|
printWorld();
|
|
|
|
putWall(2,2);
|
|
printWorld();
|
|
putWall(2,3);
|
|
printWorld();
|
|
putWall(3,3);
|
|
printWorld();
|
|
putWall(4,3);
|
|
printWorld();
|
|
putWall(4,4);
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
putConeRobot();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('a');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('w');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('s');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
moveRobot('d');
|
|
printWorld();
|
|
pickUpCone();
|
|
printWorld();
|
|
|
|
|
|
end
|
|
else if(session = 2)
|
|
then begin
|
|
!Beispiel-Simulation 3
|
|
put('B'); put('s'); put('p'); put('.'); put('3'); puteol(); puteol();
|
|
size := 16;
|
|
initWorld();
|
|
initRobot();
|
|
printWorld();
|
|
|
|
|
|
end
|
|
else begin
|
|
!Beispiel-Simulation 4
|
|
put('B'); put('s'); put('p'); put('.'); put('4'); puteol(); puteol();
|
|
size := 16;
|
|
initWorld();
|
|
initRobot();
|
|
printWorld();
|
|
|
|
end;
|
|
end |