[Commit] rrserver boards.5c,1.2,1.3 games.5c,1.27,1.28
root
commit at keithp.com
Mon Nov 10 09:52:18 PST 2003
Committed by: root
Update of /local/src/CVS/rrserver
In directory home.keithp.com:/local/bin/rrserver
Modified Files:
boards.5c games.5c
Log Message:
Must set new turn configuration atomically to avoid smashing robots and losing them.
Add checks to make sure robots don't get lost from position_robot
Index: boards.5c
===================================================================
RCS file: /local/src/CVS/rrserver/boards.5c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- boards.5c 29 May 2003 08:15:44 -0000 1.2
+++ boards.5c 10 Nov 2003 17:52:15 -0000 1.3
@@ -25,7 +25,6 @@
autoload RR
autoload Server
autoload Shuffle
-autoload Array
extend namespace Server {
public namespace Boards {
@@ -441,15 +440,19 @@
return b;
}
+ /*
+ * Locate objects on the board, the predicate matching
+ * function is used to test whether objects should be added
+ * to the returned array
+ */
+
ObjectLoc[*] find (&Board b, bool (Object) match) {
ObjectLoc[*] ol = {};
+ int i = 0;
for (int y = 0; y < Height; y++)
for (int x = 0; x < Width; x++)
if (match (b[x,y]))
- Array::append (&ol,
- (ObjectLoc) {
- x = x, y = y, object = b[x,y]
- });
+ ol[i++] = (ObjectLoc) { x = x, y = y, object = b[x,y] };
return ol;
}
@@ -536,6 +539,8 @@
public void position_robot (&Board b, Color color, int x, int y) {
ObjectLoc ol = find_robot (&b, color);
b[ol.x, ol.y].robot = RobotOrNone.none;
+ if (b[x, y].robot != RobotOrNone.none)
+ raise invalid_robot (color);
b[x, y].robot = ol.object.robot;
}
Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- games.5c 27 Jun 2003 03:02:05 -0000 1.27
+++ games.5c 10 Nov 2003 17:52:15 -0000 1.28
@@ -352,19 +352,35 @@
return;
}
+ /*
+ * Move robots to finish positions. First, remove them from the
+ * board
+ */
Track::Loc loc = Track::new();
for (int i = 0; i < dim (g.done_robots); i++)
{
- Color color = g.done_robots[i].object.robot.robot.color;
- int x = g.done_robots[i].x;
- int y = g.done_robots[i].y;
+ Color color = g.done_robots[i].object.robot.robot.color;
+ int x = g.done_robots[i].x;
+ int y = g.done_robots[i].y;
ObjectLoc now = Boards::find_robot (&g.board, color);
+
+ g.board[now.x,now.y].robot = RobotOrNone.none;
if (now.x != x || now.y != y)
- {
Track::note (&loc, color, x, y);
- Boards::position_robot (&g.board, color, x, y);
- }
}
+
+ /*
+ * Now reposition them in the new spots
+ */
+ for (int i = 0; i < dim (g.done_robots); i++)
+ {
+ Color color = g.done_robots[i].object.robot.robot.color;
+ int x = g.done_robots[i].x;
+ int y = g.done_robots[i].y;
+
+ g.board[x,y].robot = g.done_robots[i].object.robot;
+ }
+
g.target = g.targets[0];
g.targets = (Target[dim(g.targets)-1]) { [i] = g.targets[i+1] };
g.history = (ObjectLoc[*]) {};
More information about the Commit
mailing list