[Commit]
rrserver dispatch.5c,1.8,1.9 games.5c,1.8,1.9 protocol,1.17,1.18
readreq.5c,1.4,1.5 rr.5c,1.3,1.4 send.5c,1.3,1.4 server.5c,1.5,1.6
Keith Packard
commit at keithp.com
Fri May 30 15:05:11 PDT 2003
- Previous message: [Commit] rrserver games.5c,1.7,1.8 protocol,1.16,1.17
- Next message: [Commit]
rrserver clients.5c,1.3,1.4 dispatch.5c,1.9,1.10 games.5c,1.9,1.10
protocol,1.18,1.19 server.5c,1.6,1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Committed by: keithp
Update of /local/src/CVS/rrserver
In directory home.keithp.com:/tmp/cvs-serv12312
Modified Files:
dispatch.5c games.5c protocol readreq.5c rr.5c send.5c
server.5c
Log Message:
Add PASS and ABANDON handling
Index: dispatch.5c
===================================================================
RCS file: /local/src/CVS/rrserver/dispatch.5c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- dispatch.5c 30 May 2003 20:26:07 -0000 1.8
+++ dispatch.5c 30 May 2003 21:05:09 -0000 1.9
@@ -159,6 +159,13 @@
respond ("REVOKE\n");
}
+ void abandon () {
+ assert_user ();
+ assert_game ();
+ Games::abandon (&c.game.game, &c);
+ respond ("ABANDON\n");
+ }
+
void move (Color color, Direction direction) {
assert_user ();
assert_game ();
@@ -183,14 +190,15 @@
void turn () {
assert_user ();
assert_game ();
- if (Games::solved (&c.game.game))
- Games::next_turn (&c.game.game);
+ Games::next_turn (&c.game.game);
respond ("TURN\n");
}
void pass () {
assert_user ();
assert_game ();
+ Games::pass (&c.game.game, &c);
+ respond ("PASS\n");
}
void message (string text) {
@@ -259,6 +267,9 @@
break;
case REVOKE:
revoke ();
+ break;
+ case ABANDON:
+ abandon ();
break;
case MOVE m:
move (m.color, m.direction);
Index: games.5c
===================================================================
RCS file: /local/src/CVS/rrserver/games.5c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- games.5c 30 May 2003 20:32:44 -0000 1.8
+++ games.5c 30 May 2003 21:05:09 -0000 1.9
@@ -101,6 +101,16 @@
return any;
}
+ bool all_abandon (&Game g) {
+ bool all = true;
+ void abandon_set (&Client c) {
+ if (!c.abandon)
+ all = false;
+ }
+ iterate_client (&g, abandon_set, true, false);
+ return all;
+ }
+
ClientRef lowest_bidder (&Game g) {
Bid min = Bid.none;
ClientRef min_client = ClientRef.none;
@@ -184,14 +194,29 @@
break;
case GameState.Showing:
set_active (&g);
- if (g.active == ClientRef.none)
- set_state (&g, GameState.New);
break;
case GameState.Solved:
break;
}
}
+ void undo_move (&Game g)
+ {
+ ObjectLoc ol = Array::pop (&g.history);
+ Boards::position_robot (&g.board, ol.object.robot.robot.color,
+ ol.x, ol.y);
+ }
+
+ void reset_move (&Game g)
+ {
+ if (dim (g.history) > 0)
+ {
+ while (dim (g.history) > 0)
+ undo_move (&g);
+ game_send (&g, "NOTICE RESET\n");
+ }
+ }
+
/* add a client to a game */
public &Client add_client (&Game g, &Client c, bool playing) {
remove_client (&c);
@@ -199,6 +224,7 @@
c.playing = playing;
c.score = 0;
c.bid = Bid.none;
+ c.abandon = false;
Array::append (&g.clients, &c);
game_send (&g, "NOTICE %s %s\n",
playing ? "JOIN" : "WATCH",
@@ -217,12 +243,27 @@
void reset_client (&Client c) {
c.bid = Bid.none;
+ c.abandon = false;
}
iterate_client (&g, reset_client, true, false);
game_send (&g, "NOTICE TURN %C %S\n", t.color, t.shape);
}
public void next_turn (&Game g) {
+ switch (g.state) {
+ case GameState.New:
+ case GameState.Bidding:
+ if (!all_abandon (&g))
+ raise error (Error.NOTFINISHED);
+ break;
+ case GameState.Showing:
+ if (any_bids (&g))
+ raise error (Error.NOTFINISHED);
+ reset_move (&g);
+ break;
+ case GameState.Solved:
+ break;
+ }
next_target (&g);
}
@@ -276,11 +317,17 @@
raise error (Error.NOTACTIVE);
}
- void undo_move (&Game g)
- {
- ObjectLoc ol = Array::pop (&g.history);
- Boards::position_robot (&g.board, ol.object.robot.robot.color,
- ol.x, ol.y);
+ void assert_bidding (&Game g) {
+ switch (g.state) {
+ case GameState.New:
+ case GameState.Bidding:
+ break;
+ case GameState.Showing:
+ case GameState.Solved:
+ raise error (Error.NOTBIDDING);
+ break;
+ }
+
}
public void undo (&Game g, &Client c) {
@@ -294,22 +341,20 @@
public void reset (&Game g, &Client c) {
assert_active (&g, &c);
- while (dim (g.history) > 0)
- undo (&g, &c);
- game_send (&g, "NOTICE RESET\n");
+ reset_move (&g);
}
+ public void pass (&Game g, &Client c) {
+ assert_active (&g, &c);
+ reset (&g, &c);
+ c.bid = Bid.none;
+ set_active (&g);
+ }
+
public void bid (&Game g, &Client c, int number) {
- switch (g.state) {
- case GameState.New:
+ assert_bidding (&g);
+ if (g.state == GameState.New)
set_state (&g, GameState.Bidding);
- case GameState.Bidding:
- break;
- case GameState.Showing:
- case GameState.Solved:
- raise error (Error.NOTBIDDING);
- break;
- }
/*
if (c.bid != Bid.none && c.bid.number <= number)
raise error (Error.NOTLOWER);
@@ -319,11 +364,23 @@
}
public void revoke (&Game g, &Client c) {
+ assert_bidding (&g);
if (c.bid == Bid.none)
raise error (Error.NOBID);
c.bid = Bid.none;
+ game_send (&g, "NOTICE REVOKE %s\n", c.user.username);
if (!any_bids(&g))
set_state (&g, GameState.New);
+ }
+
+ public void abandon (&Game g, &Client c) {
+ assert_bidding (&g);
+ if (!c.abandon) {
+ c.abandon = true;
+ game_send (&g, "NOTICE ABANDON %s\n", c.user.username);
+ if (c.bid != Bid.none)
+ revoke (&g, &c);
+ }
}
public int count (&Game g) {
Index: protocol
===================================================================
RCS file: /local/src/CVS/rrserver/protocol,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- protocol 30 May 2003 20:32:44 -0000 1.17
+++ protocol 30 May 2003 21:05:09 -0000 1.18
@@ -213,6 +213,19 @@
Possible errors: NOTINGAME, NOTBIDDING, NOBID
+1.13. Abandon
+
+ ABANDON
+
+ ->
+
+ ABANDON
+
+ Possible errors: NOTINGAME, NOTBIDDING
+
+ Mark this user as having abandoned this turn. If all users
+ abandon, then 'TURN' can be used to move to the next turn.
+
1.13. Move
MOVE <color> <dir>
@@ -264,13 +277,13 @@
target square). The robots will start in their final positions
at the end of the first successfully demonstrated solution.
- If a solution has been demonstrated, or if all users with
- active bids have issued PASS then a TURN request from a single
- user has immediate effect. Otherwise, the server requires a
- TURN request from each active user before it will ABANDON the
- current turn.
+ TURN succeeds if one of the following is true:
- Possible errors: NOTINGAME
+ + a solution has been demonstrated
+ + all players have passed
+ + all players have abandoned the turn
+
+ Possible errors: NOTINGAME, NOTFINISHED
1.17. Pass the bid to the next lowest bidder
@@ -485,6 +498,17 @@
Possibly returned by: MOVE
+3.8. Not finished
+
+ ERROR NOTFINISHED
+
+ TURN was requested and one of:
+
+ + bidding and not all abandoned
+ + showing and not all passed
+
+ is true
+
3.8. Command
ERROR COMMAND
Index: readreq.5c
===================================================================
RCS file: /local/src/CVS/rrserver/readreq.5c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- readreq.5c 30 May 2003 20:26:07 -0000 1.4
+++ readreq.5c 30 May 2003 21:05:09 -0000 1.5
@@ -124,6 +124,9 @@
case "REVOKE":
req = Request.REVOKE;
break;
+ case "ABANDON":
+ req = Request.ABANDON;
+ break;
case "MOVE":
packet = (struct { Color color; Direction direction; }) {};
color_ (&packet);
Index: rr.5c
===================================================================
RCS file: /local/src/CVS/rrserver/rr.5c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- rr.5c 30 May 2003 20:26:07 -0000 1.3
+++ rr.5c 30 May 2003 21:05:09 -0000 1.4
@@ -103,6 +103,7 @@
int number;
} BID;
void REVOKE;
+ void ABANDON;
struct {
Color color;
Direction direction;
@@ -204,6 +205,7 @@
NOTLOWER,
NOBID,
NOTACTIVE,
+ NOTFINISHED,
NOTNUMBER,
BLOCKED,
COMMAND,
Index: send.5c
===================================================================
RCS file: /local/src/CVS/rrserver/send.5c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- send.5c 30 May 2003 20:26:07 -0000 1.3
+++ send.5c 30 May 2003 21:05:09 -0000 1.4
@@ -106,6 +106,7 @@
case Error.NOTLOWER: File::fprintf (f, "NOTLOWER"); break;
case Error.NOBID: File::fprintf (f, "NOBID"); break;
case Error.NOTACTIVE: File::fprintf (f, "NOTACTIVE"); break;
+ case Error.NOTFINISHED: File::fprintf (f, "NOTFINISHED"); break;
case Error.NOTNUMBER: File::fprintf (f, "NOTNUMBER"); break;
case Error.BLOCKED: File::fprintf (f, "BLOCKED"); break;
case Error.COMMAND: File::fprintf (f, "COMMAND"); break;
Index: server.5c
===================================================================
RCS file: /local/src/CVS/rrserver/server.5c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- server.5c 30 May 2003 20:26:07 -0000 1.5
+++ server.5c 30 May 2003 21:05:09 -0000 1.6
@@ -78,6 +78,7 @@
int score;
Bid bid;
bool playing;
+ bool abandon;
} Client;
public typedef union {
- Previous message: [Commit] rrserver games.5c,1.7,1.8 protocol,1.16,1.17
- Next message: [Commit]
rrserver clients.5c,1.3,1.4 dispatch.5c,1.9,1.10 games.5c,1.9,1.10
protocol,1.18,1.19 server.5c,1.6,1.7
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Commit
mailing list