Debian Codegraph @

gcc/testsuite/gm2/iso/run/pass/testlarge.mod

raw
1 (* Copyright (C) 2010 Free Software Foundation, Inc. *)
2 (* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with gm2; see the file COPYING. If not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
17
18 MODULE testlarge ;
19
20 FROM STextIO IMPORT WriteString, WriteLn, WriteChar, ReadToken, SkipLine ;
21 FROM SWholeIO IMPORT WriteCard, WriteInt ;
22 FROM Strings IMPORT Length ;
23 FROM Selective IMPORT Timeval, GetTimeOfDay, GetTime, InitTime, KillTime ;
24 FROM WholeStr IMPORT StrToCard, ConvResults ;
25 FROM SYSTEM IMPORT CARDINAL8 ;
26
27 CONST
28 TwoPlayer = TRUE ;
29 FourPlayer = FALSE ;
30 BoardX = 16 ;
31 BoardY = 16 ;
32 BoardSize = BoardX * BoardY ;
33 Pieces = 19 ; (* total pieces per player on the board *)
34 PieceHeap = 4000 ; (* maximum moves we will examine per ply *)
35 MaxScore = 100000 ;
36 MinScore = -100000 ;
37 WinScore = MaxScore ;
38 LooseScore = -WinScore ;
39 Debugging = FALSE ;
40 Thinking = 10 ; (* how many seconds can the program think? *)
41 slowEvaluation = FALSE ;
42 HomeWeight = BoardX ;
43
44 TYPE
45 Squares = [0..BoardSize-1] ;
46 SoS = SET OF Squares ;
47 Colour = (Blue, Red, Green, White) ;
48
49 Board = RECORD
50 used : SoS ; (* is the square used at all? *)
51 colour: ARRAY [0..1] OF SoS ; (* if so which colour occupies the square? *)
52 pieces: ARRAY [MIN(Colour)..MAX(Colour)] OF ARRAY [1..Pieces] OF CARDINAL8 ;
53 home : ARRAY [MIN(Colour)..MAX(Colour)] OF CARDINAL ;
54 END ;
55
56
57 VAR
58 homeBase: ARRAY [MIN(Colour)..MAX(Colour)] OF SoS ;
59
60
61 (*
62 +-----------------------------------------------------------------+
63 | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
64 | |
65 | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
66 | |
67 | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
68 | |
69 | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
70 | |
71 | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
72 | |
73 | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
74 | |
75 | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
76 | |
77 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
78 | |
79 | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
80 | |
81 | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
82 | |
83 | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
84 | |
85 | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
86 |--------- |
87 | 48 49 \50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
88 | \ |
89 | 32 33 34 \35 36 37 38 39 40 41 42 43 44 45 46 47 |
90 | \ |
91 | 16 17 18 19| 20 21 22 23 24 25 26 27 28 29 30 31 |
92 | | |
93 | 0 1 2 3| 4 5 6 7 8 9 10 11 12 13 14 15 |
94 +-----------------------------------------------------------------+
95 *)
96
97
98 (*
99 stop -
100 *)
101
102 PROCEDURE stop ;
103 BEGIN
104 END stop ;
105
106
107 (*
108 Min -
109 *)
110
111 PROCEDURE Min (a, b: INTEGER) : INTEGER ;
112 BEGIN
113 IF a<b
114 THEN
115 RETURN( a )
116 ELSE
117 RETURN( b )
118 END
119 END Min ;
120
121
122 (*
123 assert -
124 *)
125
126 PROCEDURE assert (b: BOOLEAN) ;
127 BEGIN
128 IF NOT b
129 THEN
130 WriteString('assert failed') ; WriteLn ;
131 HALT
132 END
133 END assert ;
134
135
136 (*
137 isUsed - return whether a square, p, is in use on board, b.
138 *)
139
140 PROCEDURE isUsed (VAR b: Board; p: CARDINAL) : BOOLEAN ;
141 BEGIN
142 RETURN p IN b.used
143 END isUsed ;
144
145
146 (*
147 isColour - return TRUE if a square, p, is used and contains a
148 piece of colour, c.
149 *)
150
151 PROCEDURE isColour (VAR b: Board; p: CARDINAL; c: Colour) : BOOLEAN ;
152 BEGIN
153 WITH b DO
154 IF p IN used
155 THEN
156 CASE c OF
157
158 Blue: RETURN (NOT (p IN colour[0])) AND (NOT (p IN colour[1])) |
159 Red : RETURN (p IN colour[0]) AND (NOT (p IN colour[1])) |
160 Green: RETURN (NOT (p IN colour[0])) AND (p IN colour[1]) |
161 White: RETURN (p IN colour[0]) AND (p IN colour[1])
162
163 END
164 END
165 END ;
166 RETURN( FALSE )
167 END isColour ;
168
169
170 (*
171 addPiece - adds a piece, pos, of colour, c, to the board, b.
172 *)
173
174 PROCEDURE addPiece (VAR b: Board; pos: CARDINAL; c: Colour; piece: CARDINAL) ;
175 BEGIN
176 WITH b DO
177 INCL(used, pos) ;
178 CASE c OF
179
180 Blue: EXCL(colour[0], pos) ;
181 EXCL(colour[1], pos) |
182 Red : INCL(colour[0], pos) ;
183 EXCL(colour[1], pos) |
184 Green: EXCL(colour[0], pos) ;
185 INCL(colour[1], pos) |
186 White: INCL(colour[0], pos) ;
187 INCL(colour[1], pos)
188
189 END ;
190 pieces[c][piece] := pos ;
191 IF pos IN homeBase[c]
192 THEN
193 stop ;
194 INC(home[c])
195 END
196 END
197 END addPiece ;
198
199
200 (*
201 initBoard -
202 *)
203
204 PROCEDURE initBoard (VAR b: Board) ;
205 BEGIN
206 b.used := SoS {} ;
207 b.colour[0] := SoS {} ;
208 b.colour[1] := SoS {} ;
209 b.home[Blue] := 0 ;
210 b.home[Red] := 0 ;
211 b.home[Green] := 0 ;
212 b.home[White] := 0 ;
213 IF TwoPlayer OR FourPlayer
214 THEN
215 (* red *)
216 addPiece(b, 0, Red, 1) ;
217 addPiece(b, 1, Red, 2) ;
218 addPiece(b, 2, Red, 3) ;
219 addPiece(b, 3, Red, 4) ;
220 addPiece(b, 16, Red, 5) ;
221 addPiece(b, 17, Red, 6) ;
222 addPiece(b, 18, Red, 7) ;
223 addPiece(b, 19, Red, 8) ;
224 addPiece(b, 32, Red, 9) ;
225 addPiece(b, 33, Red, 10) ;
226 addPiece(b, 34, Red, 11) ;
227 addPiece(b, 48, Red, 12) ;
228 addPiece(b, 49, Red, 13) ;
229
230 homeBase[Blue] := SoS{0, 1, 2, 3,
231 16, 17, 18, 19,
232 32, 33, 34,
233 48, 49} ;
234
235 (* blue *)
236 addPiece(b, 255-0, Blue, 1) ;
237 addPiece(b, 255-1, Blue, 2) ;
238 addPiece(b, 255-2, Blue, 3) ;
239 addPiece(b, 255-3, Blue, 4) ;
240 addPiece(b, 255-16, Blue, 5) ;
241 addPiece(b, 255-17, Blue, 6) ;
242 addPiece(b, 255-18, Blue, 7) ;
243 addPiece(b, 255-19, Blue, 8) ;
244 addPiece(b, 255-32, Blue, 9) ;
245 addPiece(b, 255-33, Blue, 10) ;
246 addPiece(b, 255-34, Blue, 11) ;
247 addPiece(b, 255-48, Blue, 12) ;
248 addPiece(b, 255-49, Blue, 13) ;
249
250 homeBase[Red] := SoS{255-0, 255-1, 255-2, 255-3,
251 255-16, 255-17, 255-18, 255-19,
252 255-32, 255-33, 255-34,
253 255-48, 255-49}
254 END ;
255 IF TwoPlayer
256 THEN
257 (* red *)
258 addPiece(b, 4, Red, 14) ;
259 addPiece(b, 20, Red, 15) ;
260 addPiece(b, 35, Red, 16) ;
261 addPiece(b, 50, Red, 17) ;
262 addPiece(b, 65, Red, 18) ;
263 addPiece(b, 64, Red, 19) ;
264 homeBase[Blue] := homeBase[Blue] + SoS{4, 20, 35, 50, 65, 64} ;
265
266 (* blue *)
267 addPiece(b, 255-4, Blue, 14) ;
268 addPiece(b, 255-20, Blue, 15) ;
269 addPiece(b, 255-35, Blue, 16) ;
270 addPiece(b, 255-50, Blue, 17) ;
271 addPiece(b, 255-65, Blue, 18) ;
272 addPiece(b, 255-64, Blue, 19) ;
273
274 homeBase[Red] := homeBase[Red] + SoS{255-4, 255-20, 255-35, 255-50, 255-65, 255-64}
275 END ;
276 assert(b.home[Blue] = 0) ;
277 assert(b.home[Red] = 0) ;
278 assert(b.home[Green] = 0) ;
279 assert(b.home[White] = 0)
280 END initBoard ;
281
282
283 VAR
284 b: Board ;
285 BEGIN
286 initBoard(b)
287 END testlarge.
288 (*
289 * Local variables:
290 * compile-command: "gm2 -g -fiso testlarge.mod"
291 * End:
292 *)