head	1.19;
access;
symbols
	tonic_4:1.19
	tonic_3:1.19
	tonic_2:1.19
	demo:1.19.0.2
	design_report:1.17
	oral_presentation_freeze:1.11.0.2
	DAVEG_CDP:1.9.0.2
	template_integ:1.8.0.2;
locks; strict;
comment	@ * @;


1.19
date	95.12.12.23.59.01;	author daveg;	state Exp;
branches;
next	1.18;

1.18
date	95.12.12.21.17.18;	author hartmans;	state Exp;
branches;
next	1.17;

1.17
date	95.12.11.21.09.35;	author daveg;	state Exp;
branches;
next	1.16;

1.16
date	95.12.11.07.10.41;	author hartmans;	state Exp;
branches;
next	1.15;

1.15
date	95.12.08.04.21.59;	author hartmans;	state Exp;
branches;
next	1.14;

1.14
date	95.12.03.01.18.56;	author hartmans;	state Exp;
branches;
next	1.13;

1.13
date	95.12.02.05.58.52;	author hartmans;	state Exp;
branches;
next	1.12;

1.12
date	95.12.01.23.03.04;	author hartmans;	state Exp;
branches;
next	1.11;

1.11
date	95.11.30.04.30.31;	author hartmans;	state Exp;
branches;
next	1.10;

1.10
date	95.11.28.03.31.24;	author hartmans;	state Exp;
branches;
next	1.9;

1.9
date	95.11.26.04.26.49;	author jered;	state Exp;
branches
	1.9.2.1;
next	1.8;

1.8
date	95.11.21.11.27.39;	author daveg;	state Exp;
branches;
next	1.7;

1.7
date	95.11.21.05.22.50;	author hartmans;	state Exp;
branches;
next	1.6;

1.6
date	95.11.20.08.00.41;	author hartmans;	state Exp;
branches;
next	1.5;

1.5
date	95.11.20.06.21.55;	author hartmans;	state Exp;
branches;
next	1.4;

1.4
date	95.11.20.00.52.45;	author hartmans;	state Exp;
branches;
next	1.3;

1.3
date	95.11.19.17.22.02;	author hartmans;	state Exp;
branches;
next	1.2;

1.2
date	95.11.19.04.13.46;	author hartmans;	state Exp;
branches;
next	1.1;

1.1
date	95.11.18.22.14.32;	author hartmans;	state Exp;
branches;
next	;

1.9.2.1
date	95.11.28.03.41.59;	author hartmans;	state Exp;
branches;
next	;


desc
@@


1.19
log
@finished ref_*
@
text
@// This is -*- c++ -*- code


// $Id: game.h,v 1.18 1995/12/12 21:17:18 hartmans Exp $

#ifndef __GAME_H__
#define __GAME_H__

#include <6170.h>
#include <ps5/web_node.h>

class board;
class player;
class move;

class game : public web_node {

public:

    // Overview: Dispatches data between two players and a board to
    // arbitrate a game state.  Note: once a player is assigned an
    // index, this index will remain associated with the player for
    // the rest of the game.

    // This is a heap abstraction.


    // Constructors and destructors:

    game ( board *b, player *p1, player *p2, string uri, string image_uri, bool player1_is_default);
    // Requires: p1 and p2 be players capable of playing the game
    // represented by board b, board b not be used in previous calls
    // to game::game, player p1 and p2 not be used in any other game,
    // board b not be modified by using code after this is constructed
    // Effects: Initializes a new game to be played on board b,
    // between player p1 and player p2.  If player1_is_default is
    // true, requests using the mandentory web protocol wil go to
    // player1, else they go to player 2.  The uri parameter is the
    // base URI to this game used to construct anchors in generated
    // HTML; it should end with a trailing slash. The image_uri
    // parameter is the base URI for images and static texts; it should
    // also end with a trailing slash.


    virtual ~game();
    // Effects: frees state associated with a game.  It is not
    // necessarey for game to be destructed, but if it is destructed,
    // associated state will be freed.  Requires: the players and
    // board associated with the game not be used after the game is
    // destructed.  In addition, no generators returned by the move
    // history mechanism, nor moves queried from the history mechanism
    // can be used after the game is destructed.

    // possible results of applying a move:
    enum move_result {
	ok,			// move accepted and board updated
	game_already_done,	// The move is invalid because one of the players has already won the game.
	move_invalid} ;		// Move invalid; possible penalty applied
    

    // Movement history:
    int number_moves() const;
    // Eeffects: Returns the number of moves made so far in this game.  Initially this is zero.

    generator <move *> *move_history() const;
    // Effects: Returns a generator that produces the previous moves
    // in the game in order, starting from the initial move.
    // Requires: no moves be made while this generator is in use.

    bool get_move(int number, move *&m) const;
    // Effects: If 0 <= number < moves(), returns true and assigns the
    // numberth move from the move history to m.  Else, returns false
    // without modifying m.
    // Modifies: m

    // Observers for players and board
    int players() const {return 2;}
    // Effects: returns the number of players in the game.

     player *get_player(int num) const;
    // Checks: 0 <= num < players()
    // Effects: returns a pointer to the numth player.
    int player_index(const player *p) const;
    // Effects: returns the index of player in the game, or -1 if the player
    // is not a player of this.
    
    const board * get_board() const;
    // Effects: returns the board this game is using.

    move_result apply (move &m, int player_num);
    // Checks: 0 <= player_num < players()
    // Modifies: this, p1, p2, board
    // Effects: Checks with board to see if m is a valid move; if so,
    // m is applied to board as a move submitted by p and players are notified.  Returns a
    // result indicating successful application of the move, or a
    // reason for failure.
    //   In no event shall m be assumed to exist
    // beyond the call to apply.

    void state_changed();
    // Modifies: this
    // Effects: tell all players that the state of the game has
    // changed and that all assumptions should be rechecked; check to
    // see if a winner is present.This method should only be called by
    // board.

    virtual http_response *get(string request, extensions *ext);
    // Modifies: this, p1, p2, board
    // Effects: Dispatches the request according to the protocol
    // described in the Design Document in section \tex{\ref{p:game}}
    // The request will be handled by game, or passed off to
    // p1, p2, or board.

    
    int winner() const;
    // Effects:  Returns the player who won the game, or -1 if the game is still in progress or -2 if a tie was declared.

    void forfeit (int player_num);
// Checks: 0 <= player_num < players()
    // Modifies: this
    // Checks: player_num is a player of this game and has not yet been
    // declared winner of this game.
    // Effects: player_num forfeits the game;
    // the other player wins.

    void message(string m);
// Modifies: this
    // Effects: causes a message to be displayed during the next update.
    // Multiple old messages may be displayed; if message is called more times
    // than slots exist in the message history, old messages are lost.  If
    // message is called more than once between updates, messages may be lost.

    
    http_response *display (extensions *ext, int player_num) const;
    // Checks: 0 <= player_num < players()
    // Effects: Returns the current state of the game, including the
    // state of each player and the board as viewed from player
    // player_num's point of view.  If extensions is non-null,the
    // extra headers associated with the web request this update is a
    // response to should be included in extensions.  These requests
    // may be used to determine capabilities of the requester.
    // Requires: The state of the game not be changed until the
    // request is sent.
    
    string uri() const;
    // Effects: returns the uri to the game, ending with a trailing slash.
string uri_with_move() const;
    // Effects: returns the URI including the move number, as used in most requests in the game protocol.  This includes a trailing slash.

    string image_base() const;
    // Effects: returns the base URI to images including a trailing slash.

    http_response *ref_move(string smove, extensions *ext);
    // Effects: returns a valid representation of the current refereed game,
    // after the application of the move represented in the string.

    http_response *game::ref_display(extensions *ext);
    // Effects: returns a valid representation of the current refereed game.
    
private:

   game();
    void operator = (const game &);
    // Disable unwanted operators/constructors

    player *p1, *p2;
    board *b;
    string my_uri,image_uri;
    bool p1_is_def;		// Do protocol requests without an explicit player go to p1?

    array <move *> history;
    array <string> msgarray;	// Message; msgarray[0] is first 
    int win;
    // Abstraction function: A game represents a controlled
    // interaction between two players, a board and a move history.
    // p1 and p2 are pointers to the players, b is a pointer to the
    // board.  The move history, stores in history, is the ordered set
    // of moves played so far.  In addition, win stores the index of
    // the player who has won the game, or -1 if the game is still in
    // progress.

    // Rep invarient: p1, p2, and b satisfy their rep invarient -1 <=
    // win < players().

    
};

inline player *game::get_player (int num ) const {
    check((0 <= num) && (num < players()), "out of bounds");
    return (num==0)?p1:p2;
}


inline const board *game::get_board() const {return b;}

inline string game::uri() const {return my_uri;}

inline string game::image_base() const {return image_uri;}



#endif // __GAME_H__

@


1.18
log
@* game: implement message
@
text
@d4 1
a4 1
// $Id: game.h,v 1.17 1995/12/11 21:09:35 daveg Exp $
d153 3
a155 2
    http_response *ref_game(extensions *ext);
    // Effects: returns a valid representation of the current refereed game.
@


1.17
log
@it compiles
@
text
@d4 1
a4 1
// $Id: game.h,v 1.16 1995/12/11 07:10:41 hartmans Exp $
d171 1
@


1.16
log
@Update save method prototype.
Add method to game.
@
text
@d4 1
a4 1
// $Id: game.h,v 1.15 1995/12/08 04:21:59 hartmans Exp $
d152 6
@


1.15
log
@Fix spec for uri_with_move
@
text
@d4 1
a4 1
// $Id: game.h,v 1.14 1995/12/03 01:18:56 hartmans Exp $
d144 1
a144 1

@


1.14
log
@Include changes to support:
* New syntax for game::game
* New constructor for chess_capture_move that takes chess_display_board instead of piece_taken
* parse_square
@
text
@d4 1
a4 1
// $Id: game.h,v 1.13 1995/12/02 05:58:52 hartmans Exp $
d148 1
a148 1
    // Effects: returns the URI including the move number, as used in most requests in the game protocol.
@


1.13
log
@Fix errors bringing in David's changes.
@
text
@d4 1
a4 1
// $Id: game.h,v 1.12 1995/12/01 23:03:04 hartmans Exp $
d30 1
a30 1
    game ( board *b, player *p1, player *p2, string uri, bool player1_is_default);
d38 1
a38 1
    // player1, else they go to player 2.  The uri paramemter is the
d40 3
a42 1
    // HTML; it should en with a trailing slash.
d150 3
d161 1
a161 1
    string my_uri;
d189 2
@


1.12
log
@Integrate Antichess boarrd from DAVEG_CPD
@
text
@d4 1
a4 1
// $Id: game.h,v 1.11 1995/11/30 04:30:31 hartmans Exp $
d61 1
a61 1
    // Effects: Returns the number of moves made so far in this game.  Initially this iz zero.
@


1.11
log
@player:  Deal with clock stuff
game: fix argument bogosity
Also remove penalty stuff, add player::get_game
@
text
@a2 1
// $Id: game.h,v 1.10 1995/11/28 03:31:24 hartmans Exp $
d4 2
a80 1

@


1.10
log
@Change players to be indexes, add a few new methods.
@
text
@d3 1
a3 1
// $Id: game.h,v 1.9 1995/11/26 04:26:49 jered Exp $
d19 5
a23 1
    // Overview: Dispatches data between two players and a board  to arbitrate a game state.
d80 1
d157 1
a157 1
    bool p1_is_first;
@


1.9
log
@Check-in take 4! I think I killed the lockfiles.
Linux-AFS SUCKS!
@
text
@d3 1
a3 1
// $Id: game.h,v 1.8 1995/11/21 11:27:39 daveg Exp $
d76 3
d83 2
a84 1
    move_result apply (move &m, player *p);
a85 1
    // Checks: p == p1 or p == p2
d103 1
a103 1
    // described in the Design Document
d108 2
a109 2
    player *winner() const;
    // Effects:  Returns the player who won the game, or null if the game is still in progress.
d111 2
a112 1
    void forfeit (player *p);
d114 1
a114 1
    // Checks: p is a player of this game and has not yet been
d116 1
a116 1
    // Effects: p forfeits the game;
d118 1
d127 2
a128 1
    http_response *display (extensions *ext) const;
d130 7
a136 6
    // state of each player and the board.  If extensions is
    // non-null,the extra headers associated with the web request this
    // update is a response to should be included in extensions.
    // These requests may be used to determine capabilities of the
    // requester.
    // Requires:  The state of the game not be changed until the request is sent.
d140 2
@


1.9.2.1
log
@Merge in most of my changes so diff is cleaner
@
text
@d3 1
a3 1
// $Id: game.h,v 1.10 1995/11/28 03:31:24 hartmans Exp $
a75 3
    int player_index(const player *p) const;
    // Effects: returns the index of player in the game, or -1 if the player
    // is not a player of this.
d80 1
a80 2
    move_result apply (move &m, int player_num);
    // Checks: 0 <= player_num < players()
d82 1
d100 1
a100 1
    // described in the Design Document in section \tex{\ref{p:game}}
d105 2
a106 2
    int winner() const;
    // Effects:  Returns the player who won the game, or -1 if the game is still in progress or -2 if a tie was declared.
d108 1
a108 2
    void forfeit (int player_num);
// Checks: 0 <= player_num < players()
d110 1
a110 1
    // Checks: player_num is a player of this game and has not yet been
d112 1
a112 1
    // Effects: player_num forfeits the game;
a113 1

d122 1
a122 2
    http_response *display (extensions *ext, int player_num) const;
    // Checks: 0 <= player_num < players()
d124 6
a129 7
    // state of each player and the board as viewed from player
    // player_num's point of view.  If extensions is non-null,the
    // extra headers associated with the web request this update is a
    // response to should be included in extensions.  These requests
    // may be used to determine capabilities of the requester.
    // Requires: The state of the game not be changed until the
    // request is sent.
a132 2
string uri_with_move() const;
    // Effects: returns the URI including the move number, as used in most requests in the game protocol.
@


1.8
log
@removed reference to non-existant document section
@
text
@d3 1
a3 1
// $Id: game.h,v 1.7 1995/11/21 05:22:50 hartmans Exp $
d82 1
a82 1
//checks: p == p1 or p == p2
d162 1
a162 1
    check((0 <= num < players()), "out of bounds");
@


1.7
log
@Lots of fixes to make stuff compile
@
text
@d3 1
a3 1
// $Id: game.h,v 1.6 1995/11/20 08:00:41 hartmans Exp $
d100 2
a101 2
    // described in section \tex{\ref{gameproto}} in the design
    // notes. The request will be handled by game, or passed off to
@


1.6
log
@Added methods to deal with forfeiting to player,
virtualized methods the machine might wish to overide.
@
text
@d3 1
a3 1
// $Id: game.h,v 1.5 1995/11/20 06:21:55 hartmans Exp $
d6 1
a6 1
#defin __GAME_H__
d26 10
a35 7
    // Requires: p1 and p2 be players capable of playing the game represented by board b,
    // board b not be used in previous calls to game::game,
    // player p1 and p2 not be used in any other game, board b not be
    // modified by using code after this is constructed
    // Effects:  Initializes a new game to be played on board b, between player
    // p1 and player p2.    If player1_is_default is true, requests  using
    // the mandentory web protocol wil go to player1, else they go to player 2.
d73 1
a73 1
    int player *get_player(in num) const;
d77 1
a77 1
    board * get_board() const;
d80 1
a80 1
    move_result apply_move (move &m, player *p);
@


1.5
log
@Change game to potentially support more than two players.
@
text
@d3 1
a3 1
// $Id: game.h,v 1.4 1995/11/20 00:52:45 hartmans Exp $
d87 7
@


1.4
log
@Support and changes for game
@
text
@d3 1
a3 1
// $Id: game.h,v 1.3 1995/11/19 17:22:02 hartmans Exp $
d28 2
a29 1
    // player p1 and p2 not be used in any other game.
d67 2
a68 5
    player *player1() const;
    // Effects: Returns the first player in the game.

    player *player2() const;
    // Effects: returns the second player.
d70 3
d98 6
d136 1
a136 1

d141 3
a143 1
    // of moves played so far.
d145 2
a146 1
    // Rep invarient: p1, p2, and b satisfy their rep invarient.
d151 4
a155 5
inline int game::number_moves() { return history.length();}

inline player * game::player1() const {return p1;}

inline player *game::player2() const { return p2;}
d157 1
a157 1
inline board *game::get_board() const {return b;}
@


1.3
log
@player.h: random cleanup, optionalize postion, take time arugment to set_time
board.h: add force method, random cleanup
@
text
@d3 1
a3 1
// $Id: game.h,v 1.2 1995/11/19 04:13:46 hartmans Exp $
d37 5
a41 1
    // associated state will be freed.
d54 1
a54 1
    generator <move> *move_history() const;
d59 1
a59 1
    bool get_move(int number, move &m);
d78 1
d83 2
a84 1
    // Checks: p is either p1 or p2
d116 22
d141 13
@


1.2
log
@Add preliminary board abstraction.
Update game to work with board.
@
text
@d3 1
a3 1
// $Id: game.h,v 1.1 1995/11/18 22:14:32 hartmans Exp $
d9 1
a9 1
#include <web_node.h>
@


1.1
log
@Original attempt at class game.
@
text
@d3 1
a3 1
// $Id$
d20 1
d23 1
a23 1
    // Constructors:
d25 1
a25 1
    game ( board *b, player *p1, player *p2, bool player1_is_default);
d32 7
d72 1
a72 1
    move_result apply_move (move &m);
d75 1
a75 1
    // m is applied to board and players are notified.  Returns a
d78 1
a79 1

d88 1
a88 1
    player *winning_player() const;
d108 3
@
