[Commit] rrserver games.5c,1.19,1.20 protocol,1.26,1.27
Keith Packard
commit at keithp.com
Sat Jun 7 13:09:05 PDT 2003
Committed by: keithp
Update of /local/src/CVS/rrserver
In directory home.keithp.com:/tmp/cvs-serv24865
Modified Files:
games.5c protocol
Log Message:
Add NOTICE POSITION
Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- games.5c 5 Jun 2003 23:49:56 -0000 1.19
+++ games.5c 7 Jun 2003 19:09:02 -0000 1.20
@@ -29,6 +29,36 @@
autoload Server::Clients
extend namespace Server {
+ namespace Track {
+ typedef struct {
+ Color color;
+ int x, y;
+ } Pos;
+
+ public typedef Pos[*] Loc;
+
+ public void note (&Loc loc, Color color, int x, int y) {
+ for (int i = 0; i < dim (loc); i++)
+ if (loc[i].color == color) {
+ loc[i].x = x;
+ loc[i].y = y;
+ return;
+ }
+ Array::push (&loc, (Pos) {
+ color = color,
+ x = x,
+ y = y });
+ }
+
+ public Loc new () {
+ return (Pos[0]) {};
+ }
+
+ public void report (void (Color c, int x, int y) call, &Loc loc) {
+ for (int i = 0; i < dim (loc); i++)
+ call (loc[i].color, loc[i].x, loc[i].y);
+ }
+ }
public namespace Games {
/* array of all games */
public (&Game)[0] games = {};
@@ -117,6 +147,14 @@
iterate_client (&g, message_client, true, true);
}
+ void game_send_loc (&Game g, &Track::Loc loc) {
+ void report_position (Color c, int x, int y)
+ {
+ game_send (&g, "NOTICE POSITION %C %d %d\n", c, x, y);
+ }
+ Track::report (report_position, &loc);
+ }
+
/* does the given game exist? */
bool exists (string name) {
exception found (&Game g);
@@ -236,23 +274,34 @@
}
}
- void undo_move (&Game g)
+ void undo_move (&Game g, &Track::Loc loc)
{
ObjectLoc ol = Array::pop (&g.history);
Boards::position_robot (&g.board, ol.object.robot.robot.color,
ol.x, ol.y);
+ Track::note (&loc, ol.object.robot.robot.color,
+ ol.x, ol.y);
}
- void reset_move (&Game g)
+ void reset_move (&Game g, &Track::Loc loc)
{
if (dim (g.history) > 0)
{
while (dim (g.history) > 0)
- undo_move (&g);
- game_send (&g, "NOTICE RESET\n");
+ undo_move (&g, &loc);
}
}
+ void make_move (&Game g, &Track::Loc loc, Color color, Direction dir) {
+ ObjectLoc src = Boards::find_robot (&g.board, color);
+ ObjectLoc dst = Boards::move_robot (&g.board, color, dir);
+ if (src == dst)
+ raise rr_error (Error.BLOCKED);
+ Array::push (&g.history, src);
+ Track::note (&loc, color, dst.x, dst.y);
+ Boards::position_robot (&g.board, color, dst.x, dst.y);
+ }
+
void next_game (&Game g);
/* select the next target */
@@ -477,15 +526,20 @@
assert_active_or_done (&g, &c);
if (dim (g.history) > 0)
{
- undo_move (&g);
+ Track::Loc loc = Track::new ();
+ undo_move (&g, &loc);
game_send (&g, "NOTICE UNDO\n");
+ game_send_loc (&g, &loc);
}
}
public void reset (&Game g, &Client c) {
assert_playing (&g, &c);
assert_active_or_done (&g, &c);
- reset_move (&g);
+ Track::Loc loc = Track::new();
+ reset_move (&g, &loc);
+ game_send (&g, "NOTICE RESET\n");
+ game_send_loc (&g, &loc);
}
public void pass (&Game g, &Client c) {
@@ -504,13 +558,10 @@
if (g.state == GameState.SHOW &&
count (&g) >= c.bid.number)
raise rr_error (Error.TOOMANYMOVES);
- ObjectLoc src = Boards::find_robot (&g.board, color);
- ObjectLoc dst = Boards::move_robot (&g.board, color, dir);
- if (src == dst)
- raise rr_error (Error.BLOCKED);
- Array::push (&g.history, src);
- Boards::position_robot (&g.board, color, dst.x, dst.y);
+ Track::Loc loc = Track::new();
+ make_move (&g, &loc, color, dir);
game_send (&g, "NOTICE MOVE %d %C %D\n", count (&g), color, dir);
+ game_send_loc (&g, &loc);
if (g.state != GameState.DONE && Boards::solved (&g.board))
{
if (g.active != ClientRef.none)
Index: protocol
===================================================================
RCS file: /local/src/CVS/rrserver/protocol,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- protocol 31 May 2003 16:13:29 -0000 1.26
+++ protocol 7 Jun 2003 19:09:02 -0000 1.27
@@ -503,7 +503,15 @@
NOTICE RESET
- 2.2.3.5. Score (game)
+ 2.2.3.5. Position (after move/undo/reset)
+
+ NOTICE POSITION <color> <x> <y>
+
+ The indicated robot has moved to the indicated position.
+ The board is 0-based with the origin in the upper left
+ corner.
+
+ 2.2.3.6. Score (game)
NOTICE SCORE <username> <score>
More information about the Commit
mailing list