| 1 |
(* Copyright (C) 2014 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 simplelarge ; |
| 19 |
|
| 20 |
FROM STextIO IMPORT WriteString, WriteLn, WriteChar, ReadToken, SkipLine ; |
| 21 |
FROM SWholeIO IMPORT WriteCard, WriteInt ; |
| 22 |
FROM WholeStr IMPORT StrToCard, ConvResults ; |
| 23 |
FROM SYSTEM IMPORT CARDINAL8 ; |
| 24 |
FROM libc IMPORT printf ; |
| 25 |
|
| 26 |
CONST |
| 27 |
BoardX = 16 ; |
| 28 |
BoardY = 16 ; |
| 29 |
BoardSize = BoardX * BoardY ; |
| 30 |
|
| 31 |
TYPE |
| 32 |
Squares = [0..BoardSize-1] ; |
| 33 |
SoS = SET OF Squares ; |
| 34 |
Colour = (Blue, Red, Green, White) ; |
| 35 |
|
| 36 |
VAR |
| 37 |
homeBase: ARRAY [MIN(Colour)..MAX(Colour)] OF SoS ; |
| 38 |
|
| 39 |
|
| 40 |
PROCEDURE dumpSet (c: Colour) ; |
| 41 |
VAR |
| 42 |
n: CARDINAL ; |
| 43 |
BEGIN |
| 44 |
printf ("inside dumpSet (%d)\n", ORD(c)) ; |
| 45 |
printf (" : 0 2 4 6 8 a c e \n") ; |
| 46 |
FOR n := MIN(Squares) TO MAX(Squares) DO |
| 47 |
IF n MOD 16 = 0 |
| 48 |
THEN |
| 49 |
printf ("\nrow %2d: ", n DIV 16) |
| 50 |
END ; |
| 51 |
IF n IN homeBase[c] |
| 52 |
THEN |
| 53 |
printf ("1") |
| 54 |
ELSE |
| 55 |
printf ("0") |
| 56 |
END |
| 57 |
END ; |
| 58 |
printf ("\n") |
| 59 |
END dumpSet ; |
| 60 |
|
| 61 |
|
| 62 |
(* |
| 63 |
assert - |
| 64 |
*) |
| 65 |
|
| 66 |
PROCEDURE assert (b: BOOLEAN) ; |
| 67 |
BEGIN |
| 68 |
IF NOT b |
| 69 |
THEN |
| 70 |
WriteString('assert failed') ; WriteLn ; |
| 71 |
HALT |
| 72 |
END |
| 73 |
END assert ; |
| 74 |
|
| 75 |
|
| 76 |
BEGIN |
| 77 |
homeBase[Red] := SoS {} ; |
| 78 |
dumpSet(Red) ; |
| 79 |
homeBase[Blue] := SoS {0, 1, 2, 3, |
| 80 |
16, 17, 18, 19, |
| 81 |
32, 33, 34, |
| 82 |
48, 49} ; |
| 83 |
|
| 84 |
dumpSet(Blue) ; |
| 85 |
|
| 86 |
assert (0 IN homeBase[Blue]) ; |
| 87 |
assert (1 IN homeBase[Blue]) ; |
| 88 |
assert (2 IN homeBase[Blue]) ; |
| 89 |
assert (3 IN homeBase[Blue]) ; |
| 90 |
|
| 91 |
(* |
| 92 |
homeBase[Red] := SoS {255-0, 255-1, 255-2, 255-3, |
| 93 |
255-16, 255-17, 255-18, 255-19, |
| 94 |
255-32, 255-33, 255-34, |
| 95 |
255-48, 255-49} ; |
| 96 |
*) |
| 97 |
|
| 98 |
homeBase[Blue] := homeBase[Blue] + SoS {4, 20, 35, 50, 65, 64} ; |
| 99 |
dumpSet(Blue) ; |
| 100 |
dumpSet(Red) ; |
| 101 |
assert (homeBase[Red] = SoS {}) ; |
| 102 |
|
| 103 |
(* |
| 104 |
homeBase[Red] := homeBase[Red] + SoS {255-4, 255-20, 255-35, 255-50, 255-65, 255-64} ; |
| 105 |
*) |
| 106 |
|
| 107 |
assert (0 IN homeBase[Blue]) ; |
| 108 |
assert (1 IN homeBase[Blue]) ; |
| 109 |
assert (2 IN homeBase[Blue]) ; |
| 110 |
assert (3 IN homeBase[Blue]) ; |
| 111 |
assert (4 IN homeBase[Blue]) ; |
| 112 |
assert (NOT (5 IN homeBase[Blue])) ; |
| 113 |
assert (NOT (6 IN homeBase[Blue])) ; |
| 114 |
|
| 115 |
assert (homeBase[Red] = SoS {}) |
| 116 |
END simplelarge. |
| 117 |
(* |
| 118 |
* Local variables: |
| 119 |
* compile-command: "gm2 -g -fiso simplelarge.mod" |
| 120 |
* End: |
| 121 |
*) |