4
* Copyright © 2003 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
26
public typedef enum { Red, Yellow, Green, Blue, Whirl } Color;
27
public typedef enum { Triangle, Square, Octagon, Circle, Whirl } Shape;
28
public typedef enum { North, East, South, West } Direction;
30
public const int Width = 16;
31
public const int Height = 16;
32
public const int Port = 5252;
34
public typedef struct {
39
public typedef union {
44
public typedef struct {
50
public typedef union {
55
public typedef struct {
56
bool left, right, below, above;
59
public typedef struct {
66
NEW, /* no bids yet */
67
BID, /* some bids, timer running */
68
SHOW, /* timer expired, waiting for solution */
69
DONE /* turn done (solved, or bailed) */
72
public typedef Object[Width,Height] Board;
74
public TargetOrNone active_target(&Board board) {
75
for (int y = 0; y < Height; y++)
76
for (int x = 0; x < Width; x++)
77
union switch (board[x,y].target) {
80
return (TargetOrNone.target) t;
85
return TargetOrNone.none;
88
public void set_target(&Board board, Target target) {
89
for (int y = 0; y < Height; y++)
90
for (int x = 0; x < Width; x++)
91
union switch (board[x,y].target) {
93
board[x,y].target.target.active = t == target;
100
public RobotOrNone active_robot(&Board board) {
101
for (int y = 0; y < Height; y++)
102
for (int x = 0; x < Width; x++)
103
union switch (board[x,y].robot) {
106
return (RobotOrNone.robot) r;
111
return RobotOrNone.none;
114
public void set_robot(&Board board, Robot robot) {
115
for (int y = 0; y < Height; y++)
116
for (int x = 0; x < Width; x++)
117
union switch (board[x,y].robot) {
119
board[x,y].robot.robot.active = r == robot;
126
public typedef enum {
151
public exception rr_error (Error e);
153
public Color color (string w) {
155
case 'r': case 'R': return Color.Red;
156
case 'y': case 'Y': return Color.Yellow;
157
case 'g': case 'G': return Color.Green;
158
case 'b': case 'B': return Color.Blue;
159
case 'w': case 'W': return Color.Whirl;
160
default: raise rr_error (Error.NOTCOLOR);
164
public bool boolean (string w) {
166
case 't': case 'T': case 'y': case 'Y': case '1':
168
case 'f': case 'F': case 'n': case 'N': case '0':
171
raise rr_error(Error.NOTBOOL);
175
public Shape shape (string w) {
177
case 't': case 'T': return Shape.Triangle;
178
case 's': case 'S': return Shape.Square;
179
case 'o': case 'O': return Shape.Octagon;
180
case 'c': case 'C': return Shape.Circle;
181
case 'w': case 'W': return Shape.Whirl;
182
default: raise rr_error (Error.NOTSHAPE);
186
public Direction direction (string w) {
188
case 'n': case 'N': return Direction.North;
189
case 'e': case 'E': return Direction.East;
190
case 's': case 'S': return Direction.South;
191
case 'w': case 'W': return Direction.West;
192
default: raise rr_error (Error.NOTDIRECTION);
196
public GameState game_state(string w) {
198
case 'n': case 'N': return GameState.NEW;
199
case 'b': case 'B': return GameState.BID;
200
case 's': case 'S': return GameState.SHOW;
201
case 'd': case 'D': return GameState.DONE;
202
default: raise rr_error (Error.NOTGAMESTATE);