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.12.0.2
	DAVEG_CDP:1.10.0.4
	template_integ:1.10.0.2;
locks; strict;
comment	@ * @;


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

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

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

1.16
date	95.12.11.09.47.29;	author daveg;	state Exp;
branches;
next	1.15;

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

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

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

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

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

1.10
date	95.11.22.07.06.57;	author daveg;	state Exp;
branches;
next	1.9;

1.9
date	95.11.22.05.40.57;	author daveg;	state Exp;
branches;
next	1.8;

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

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

1.6
date	95.11.21.00.00.50;	author jered;	state Exp;
branches;
next	1.5;

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

1.4
date	95.11.19.19.49.45;	author jered;	state Exp;
branches;
next	1.3;

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

1.2
date	95.11.19.03.01.54;	author daveg;	state Exp;
branches;
next	1.1;

1.1
date	95.11.19.00.00.54;	author daveg;	state Exp;
branches;
next	;


desc
@Version 0.5 of player abstraction
@


1.19
log
@changed descriptions
@
text
@//  This is -*- c++ -*- code

#ifndef __PLAYER_H__
#define __PLAYER_H__
#include <sys/time.h>
#include <time.h>

#include <6170.h>
#include "board.h"
#include <ps5/normal_response.h>
#include <sys/types.h>
#include <time.h>

class move;
class http_response;

class player : public web_node {
    // Overview: A player is a participant in a game, played upon a board.
public:
    

    // Constructors:

    player(string name, long total_time);
    // Requires: name not be blank.
    // Checks: total_time >= 0;
    // Effects:  Creates a new player of the given name, not associated with
    // any game.
    // Player will have have up total_time seconds to complete all moves.

    // Methods:

    virtual bool is_associated() const;
    // Effects: Returns true if this board is associated with a game.

    string get_name() const;
    // Effects: Returns the name of this player.

    bool get_position (string &p) const;
    // Modifies: p
    // Effects: If this has a position, returns true and sets p to the
    // position; else p is unmodified and returns false.

    virtual void set_position (string p);
    // Modifies: this
    // Effects: If this has a position, returns true and sets p to the
    // position; else p is unmodified and returns false.

    virtual void set_name (string n);
    // Checks: name is non-empty
    // Effects: The name of the player becomesn.
    long get_time() const;
    // Effects: Returns amount of time this player has left.

    virtual void set_time(long time);
    // Modifies: this.
    // Checks: time is non-negative
    // Effects: Changes the time remaining for this player to time, expressed in miliseconds.

    virtual void display(extensions *ext, ostream &body, int point_of_view) const = 0;
    // Effects: Returns a html-formatted string describing player
    // name, position, and time remaining.  The point_of_view
    // parameter is the player from whose point of view the display
    // should be viewed.
    // Requires: point_of_view be a valid player number.


    virtual http_response *get(string request, extensions *ext); 
    // Modifies: this 
    // Effects: Modifies the field according to a TBD
    // protocol for the request.

    virtual void you_moved (move &m);
    // Modifies: this, possibly other game state
    // Effects: notifys this that it has made a move.  The clock for
    // time taken for the current move should be stopped.  Ths player will
    // consider forfeiting.

    virtual void opponent_moved (move &m, int player_num);
    //modifies: this, possibly other game state
    // Effects: This method is called by game when an opponent of this
    // player applies move m.  The player applying the move is p.
    // This player will consider forfeiting.

    virtual void state_changed(void);
    // Modifies: this or other game state
    // Effects: This method is called by game when game state changes in
    // response to a non-move event such as initialization.  This
    // player will consider forfeiting.

    virtual void consider_forfeiting();
    // Modifies: this and possibly game 
    // Effects: if time is run out, or other conditions imposed by suptypes
    // are true,  forfeits.  Else do nothing.

protected:
    virtual void start_clock();
    // Modifies: this
    // Checks: That clock was previously in stopped state.
    // Effects: starts counting time against this

    virtual void stop_clock();
    // Modifies: this, possibly game state Effects: Stops the clock of
    // this.  If the time is out, forfeits the game, else game state
    // is unchanged. It is acceptable to stop a stopped clock.

    virtual void associate( game *gm);
    // Modifies: this 
    // Effects: Associates this with a particular game.
    // This method should only be called by game::game or overiding subclasses, and never by
    // using code.  A player that is not associated with a particular
    // game can be used, but no web requests can be sent to it.
    // Associate will not call any non-const methods of game.

    game * get_game() const;
    // Effects returns the game this is associated with or null.
    
    friend game::game(board *b, player *p1, player *p2, string uri,
		      string image_base, bool player1_is_default);
    //friendship-extent: game::game is a friend of player so it can
    //call player::associate.  game::game shall not access other
    //private or protected methods or state of player.
    
private:

    player();
    // Disable default constructor

    void operator= (player &);
    // Disable equality operator

    string player_name;
    // The name of this player; Initialized in constructor.

    string player_position;
    // The position of this player


    long player_time;
    // The amount of time this player has left.  Initialized in constructor.

    bool clock_is_running;
    // Used to track state of clock.  Initialized in constructor to false.
    struct timeval clock_started_when;// When did the clock start

    // Rep invariant: If g is non-null, g->get_board() == this
    game *g;

};


inline string player::get_name() const {
    return player_name;
}

inline long player::get_time() const {
    player *tempplayer = (player *)this;
    if (clock_is_running) {
	tempplayer->stop_clock();
	tempplayer->start_clock();
  }
  return player_time;
}

inline game * player::get_game() const {return g;}

#endif



@


1.18
log
@Change prototypes for player::display
@
text
@d76 2
a77 1
    // time taken for the current move should be stopped.
d83 1
d88 2
a89 1
    // response to a non-move event such as initialization.
@


1.17
log
@bug fix
@
text
@d60 1
a60 1
    virtual void display(extensions *ext, ostream &body) const = 0;
d62 4
a65 1
    // name, position, and time remaining.
@


1.16
log
@bug fix
@
text
@d151 4
a154 3
  if (clock_is_running) {
      stop_clock();
      start_clock();
@


1.15
log
@Handle time get_player
@
text
@d152 3
a154 3
    stop_clock();
    start_clock()
    }
@


1.14
log
@Clear up some specs.  Add new struct for internal top_node use.
@
text
@d151 5
a155 1
    return player_time;
@


1.13
log
@Tidy up human_player,
implement machine_player::get

clarify associate specs.
@
text
@d58 1
a58 1
    // Effects: Changes the time remaining for this player to time.
@


1.12
log
@Fix bugs so it builds
@
text
@d104 2
a105 2
    // This method should only be called by game::game, and never by
    // using code.  A board that is not associated with a particular
d113 1
a113 1
		      bool player1_is_default);
@


1.11
log
@player:  Deal with clock stuff
game: fix argument bogosity
Also remove penalty stuff, add player::get_game
@
text
@d60 1
a60 1
    virtual void display(extensions *ext, ostream *body) const = 0;
d75 1
a75 1
    virtual void opponent_moved (move &m, player *p);
@


1.10
log
@a few more bug fixes
@
text
@d5 2
d49 3
a63 4
    virtual void apply_penalty(long size); 
    // Modifies: this 
    // Effect: Add penalty of given size to the overall penalty of the
    //  player.
d97 3
a99 4
    // Modifies: this, possibly game state
    // Checks: That clock was previously in a running state.
    // Effects: Stops the clock of this.  If the time is out, forfeits the
    // game, else game state is unchanged.
d109 3
d114 3
a116 3
    //friendship-extent: game::game is a friend of board so it can
    //call board::associate.  game::game shall not access other
    //private or protected methods or state of board.
d130 1
a130 1
    // The position of this player; Initialized in constructor.
a131 3
    long penalty;
    // The size of the penalty incurred by player so far;
    // Initialized to zero.
d138 1
a138 3
    
    time_t running_time;
    // Keeps track of intermediate time during moves.
d154 2
@


1.9
log
@a few minor changes in comments
@
text
@d6 1
d8 1
a8 2
#include <6170.h>
#include <ps5/web_node.h>
d13 1
d133 1
a133 1
    long time;
d148 1
a148 1
inline player::get_name() {
d152 2
a153 2
long player::get_time() const {
    return time;
@


1.8
log
@changed paramter names in a couple methods
@
text
@d9 2
@


1.7
log
@Lots of fixes to make stuff compile
@
text
@d21 1
d89 1
d94 1
d98 1
a98 1
    virtual void associate( game *g);
d133 6
d141 1
d144 9
d154 3
@


1.6
log
@Revised player to associate with a board, other piddly changes.
@
text
@d14 2
d132 1
a132 1
}
@


1.5
log
@Added methods to deal with forfeiting to player,
virtualized methods the machine might wish to overide.
@
text
@d4 1
a4 1
#defin __PLAYER_H__
a12 1
    
a14 1

d19 2
a20 1
    // Effects:  Creates a new player of the given name.
d25 3
d31 1
a31 1
     bool get_position (string &p) const;
d36 6
a41 1
    virtual long get_time() const;
a43 4
    virtual void display(extensions *ext, ostream *body) const;
    // Effects: Returns a html-formatted string describing player
    // name, position, and time remaining.

d49 4
d55 2
a56 1
    // Effect: Add penalty of given size to the overall penalty of the player.
d76 1
a76 1
    // // response to a non-move event such as initialization.
d79 4
a82 3
    // Modifies: this and possibly game // Effects: if time is run out, or
    // other conditions imposed by suptypes are true,  forfeits.  Else
    //  do nothing.
d92 14
d107 1
a107 1
  private:
d110 1
a110 1
    // Disable default constructor;
d113 1
a113 1
    // Disable equality operator;
d128 2
a132 3



@


1.4
log
@Fixed some speeling and fill errors, virtualized evaluate, and changed
display routines to use ostreams. (And changed get_info to display)
@
text
@d29 1
a29 1
    bool get_position (string &p) const;
d34 1
a34 1
    long get_time() const;
d37 1
a37 1
    void display(extensions *ext, ostream *body) const;
d41 1
a41 1
    void set_time(long time);
d46 1
a46 1
    void apply_penalty(long size); 
d55 29
@


1.3
log
@player.h: random cleanup, optionalize postion, take time arugment to set_time
board.h: add force method, random cleanup
@
text
@d29 1
a29 1
    bool geet_position (string &p) const;
d31 2
a32 1
    // Effects: If this has a position, returns true and sets p to the position; else p is unmodified and returns false.
d37 1
a37 1
    string get_info() const;
d41 1
a41 1
    void set_time( long time);
d46 8
a53 6
    void apply_penalty(long size); // Modifies: this // Effect: Add
    penalty of given size to the overall penalty of the player.

    virtual http_response *get(string request, extensions *ext); //
    Modifies: this // Effects: Modifies the field according to a TBD
    protocol for the request.
a76 1

@


1.2
log
@Updates on player abstraction, from discussion about interfaces.
@
text
@d8 1
a8 1
#include <web_server.h>
d19 1
a19 1
    player(string name, string position, long total_time);
d21 1
a21 1
    // Effects:  Creates a new player of the given name and position.
d29 3
a31 2
    string get_position() const;
    // Effects: Returns the position of this player.
d40 1
a40 1
    void set_time();
d42 2
a43 1
    // Effects: Changes the time remaining for this player.
d45 6
a50 7
    void apply_penalty(long size);
    // Modifies: this
    // Effect: Add penalty of given size to the overall penalty of the player.
    
    virtual http_response *get(string request, extensions *ext);
    // Modifies: this
    // Effects: Modifies the field according to a TBD protocol for the request.
@


1.1
log
@Version 0.5 of player abstraction.
@
text
@d8 1
d12 1
a12 1
class player {
d19 1
a19 1
    player(string name, game *g);
d21 2
a22 2
    // Effects:  Creates a new player of the given name, and associated
    // with the given game.
d27 1
a27 1
    // Effects: Returns the name of this player
d29 2
a30 2
    game *get_game() const;
    // Effects: Returns the game this player is associated with.  
d32 2
a33 2
    long get_score() const;
    // Effects: Returns the score of this player.
d35 8
a45 3

    move make_move();
    // Effects: Returns a moved, based upon the val
d47 3
d56 2
a57 2
    long score;
    // The score of this player.  Initialized to 0;
d59 6
d66 1
a66 1
    // The size of the penalty incurred by player so far.
d68 3
@
