-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaceStack.pas
107 lines (80 loc) · 2.73 KB
/
PlaceStack.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(*
Copyright (C) 2024 Jeffrey Getzin.
Licensed under the GNU General Public License v3.0 with additional terms.
See the LICENSE file in the repository root for details.
*)
Module Place_Stack;
{ This module keeps track of where the party has been by pushing the place onto a hybrid stack-queue }
Type
Horizontal_Type = 0..20;
Vertical_Type = 0..19;
Place_Ptr = ^Place_Node;
Place_Node = Record
PosX,PosY: Horizontal_Type;
PosZ: Vertical_Type;
Next: Place_Ptr;
End;
Place_Stack = Record
Front: Place_Ptr;
Length: Integer;
End;
(*******************************************************************************)
[Global]Function Empty_Stack (Stack: Place_Stack): Boolean;
{ This function returns TRUE if there are no nodes on the STACK, and FALSE
otherwise }
Begin { Empty Stack }
Empty_Stack:=(Stack.Front=Nil) or (Stack.Length=0);
End; { Empty Stack }
(*******************************************************************************)
[Global]Procedure Init_Stack (Var Stack: Place_Stack);
Begin { Init Stack }
Stack.Front:=Nil; Stack.Length:=0;
End; { Init Stack }
(*******************************************************************************)
[Global]Procedure Remove_Nodes (Var Stack: Place_Stack);
{ This procedure will remove all the nodes from the STACK, and delete them, returning
an empty STACK. }
Var
Temp: Place_Ptr;
Begin { Remove Node }
While Not Empty_Stack(Stack) do
Begin
Temp:=Stack.Front;
Stack.Front:=Stack.Front^.Next;
Dispose(Temp);
End;
Stack.Front:=Nil;
Stack.Length:=0;
End; { Remove Nodes }
(*******************************************************************************)
[Global]Procedure Insert_Place (PosX,PosY: Horizontal_Type; PosZ: Vertical_Type; Var Stack: Place_Stack);
Var
Temp: Place_Ptr;
Begin
New(Temp);
Temp^.PosX:=PosX; Temp^.PosY:=PosY; Temp^.PosZ:=PosZ;
Temp^.Next:=Stack.Front;
Stack.Front:=Temp;
Stack.Length:=Stack.Length + 1;
End;
(*******************************************************************************)
[Global]Procedure POP (Var PosX,PosY: Horizontal_Type; Var PosZ: Vertical_Type; Var Stack: Place_Stack);
Var
Temp: Place_Ptr;
Begin
If Not Empty_Stack(Stack) then
Begin
PosX:=Stack.Front^.PosX; PosY:=Stack.Front^.PosY;
PosZ:=Stack.Front^.PosZ;
Temp:=Stack.Front;
Stack.Front:=Stack.Front^.Next;
Dispose(Temp);
Stack.Length:=Stack.Length-1;
End
Else
Begin
Stack.Length:=0;
PosX:=0; PosY:=0; PosZ:=0;
End;
End;
End.