head	1.18;
access;
symbols
	tonic_4:1.18
	tonic_3:1.18
	tonic_2:1.18
	demo:1.18.0.2
	design_report:1.17;
locks; strict;
comment	@ * @;


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

1.17
date	95.12.11.19.28.03;	author jered;	state Exp;
branches;
next	1.16;

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

1.15
date	95.12.11.18.28.35;	author jered;	state Exp;
branches;
next	1.14;

1.14
date	95.12.11.15.26.22;	author rgmisra;	state Exp;
branches;
next	1.13;

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

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

1.11
date	95.12.10.01.19.38;	author jered;	state Exp;
branches;
next	1.10;

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

1.9
date	95.12.08.04.04.18;	author jered;	state Exp;
branches;
next	1.8;

1.8
date	95.12.07.23.24.19;	author jered;	state Exp;
branches;
next	1.7;

1.7
date	95.12.07.22.41.59;	author jered;	state Exp;
branches;
next	1.6;

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

1.5
date	95.12.04.05.49.01;	author daveg;	state Exp;
branches;
next	1.4;

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

1.3
date	95.12.03.09.29.39;	author daveg;	state Exp;
branches;
next	1.2;

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

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


desc
@@


1.18
log
@Update players so they don't display stuff that isn't needed when the other person displays them.
@
text
@//  This is -*- c++ -*- code

#include <6170.h>
#include <human_player.h>
#include <ps5/error_response.h>
#include <ps5/url_ops.h>
#include <top_node.h>

human_player::human_player(string name, long total_time, top_node *tnode, 
			   bool start_detached) :player(name,total_time) {
    top = tnode;
    attached = !start_detached;
    my_index = -1;      
}


void human_player::detach(){
    stop_clock();
    top->add_to_detached(get_game(), my_index);
    attached = false;
}

void human_player::attach(string name){
    top->remove_from_detached(get_game());
    attached=true;
    set_name(name);
}

void human_player::display(extensions *ext, ostream &body, int pov) const {
  string tpos;

  body << "<H3>" << get_name();
  if (get_position(tpos)) 
    body << "(" << tpos << ")";
  body << ": Time remaining(ms): " << get_time();
  if (pov == my_index) {
      body<< "<FORM METHOD=\"GET\" "
    << "ACTION=\"" << get_game()->uri_with_move() << "player/" << my_index
    << "/set_time\">";
  body << "<INPUT NAME=\"msecs\" VALUE=\"" << get_time() << "\">";
  body << "<INPUT TYPE=SUBMIT VALUE=\"Set Time\"></FORM>"<<endl;
  }
  body<<"</H3><P>" << endl;
  if (pov == my_index ) {
      body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri_with_move() 
    << "player/" << my_index << "/set_name\">" << endl;
  body << "Name: ";
  body << "<INPUT NAME=\"name\" VALUE=\"" << get_name() << "\">" << endl;
  body << "<INPUT TYPE=SUBMIT VALUE=\"Change Name\"><BR>";
  body << "</FORM>";
  }
  
  if (!get_game()->get_board()->valid_move_available(my_index) && (pov == my_index)) {
    body << "<A HREF=\"" << get_game()->uri() << "display?player=" 
      << my_index << "\">";
    body << "Can I move yet?" <<  "</A><BR>" << endl;
  }
  if (pov == my_index) {
      body << "<A HREF=\"" << get_game()->uri_with_move() << "player/" 
    << my_index << "/detach\">";
  body << "Detach from this Game" << "</A>" << endl;
  body << "<br>\n";
  body << "<a href=\"" << get_game()->uri_with_move() << "player/"
       << my_index << "/forfeit\">Forfeit game</a>\n";
  }
  body << "<HR>" << endl;
}

void human_player::you_moved(move &m) {
  player::you_moved(m);
  if (attached&&get_game()->get_board()->valid_move_available(my_index)) {
    start_clock();
  } 
}

void human_player::opponent_moved (move &m, int p) {
  player::opponent_moved(m,p);
  if (attached&&get_game()->get_board()->valid_move_available(my_index)) {
    start_clock();
  } 
}

void human_player::state_changed(void) {
  player::state_changed();
  consider_forfeiting();
  if (attached&&get_game()->get_board()->valid_move_available(my_index)) {
    start_clock();
  }
}

void human_player::associate(game *g) {
    player::associate(g);
    my_index = get_game()->player_index(this);
    if (!attached)
      top->add_to_detached(get_game(), my_index);
}


http_response *human_player::get (string request, extensions *ext)
{
    if (!is_associated)
	return new error_response(http_response::INTERNAL_ERROR, "Shouldn't be able to call unassociated player.");
    string first;
    if (!unescape_uri(first_component(request), first))
	return new error_response(http_response::BAD_REQUEST, "Unable to escape decode supplied URI.");
    if ( first == "attach") {
	if (attached)
	    return new error_response(http_response::BAD_REQUEST, "Unable to attach an already attached player.");
	else {
	    map <string, string> *q = parse_query(extract_query(request));
	    if (q->contains("name")){
		attach(q->fetch("name"));
if (get_game()->get_board()->valid_move_available(my_index))
    start_clock();
		return get_game()->display(ext, my_index);
	    }
	    else return new error_response(http_response::BAD_REQUEST, "A request to attach must include a name.");
	}
    }
    else if (first == "detach") {
	if (attached) {
	    stop_clock();
	    detach();
	    return top->get("welcome", ext);
	}
	else return new error_response (http_response::BAD_REQUEST, "No, you can't detach a detached player; sorry.");
    }
    else if (first == "forfeit") {
	if ( get_game()->winner() == my_index) {
	    get_game()->message(get_name()+" tried to forfeit after winning!");
	    return get_game()->display(ext, my_index);
	} else {
	    get_game()->message(get_name() + "forfeits");
	    get_game()->forfeit(my_index);
	    return top->get("welcome", ext);
	}
    }
    
    return player::get(request,ext);
}



@


1.17
log
@More display modifications.
@
text
@d29 1
a29 1
void human_player::display(extensions *ext, ostream &body) const {
d35 3
a37 1
  body << ": Time remaining(ms): " << get_time() << "<FORM METHOD=\"GET\" "
d41 5
a45 2
  body << "<INPUT TYPE=SUBMIT VALUE=\"Set Time\"></FORM></H3><P>" << endl;
  body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri_with_move() 
d51 3
a53 1
  if (!get_game()->get_board()->valid_move_available(my_index)) {
d58 2
a59 1
  body << "<A HREF=\"" << get_game()->uri_with_move() << "player/" 
d65 1
@


1.16
log
@Timing fixes, mainly for human_player
@
text
@d46 5
a50 3
  body << "<A HREF=\"" << get_game()->uri() << "display?player=" 
    << my_index << "\">";
  body << "Can I move yet?" <<  "</A><BR>" << endl;
@


1.15
log
@Bug fix.
@
text
@d60 1
a60 1
  if (get_game()->get_board()->valid_move_available(my_index)) {
d67 1
a67 1
  if (get_game()->get_board()->valid_move_available(my_index)) {
d75 1
a75 1
  if (get_game()->get_board()->valid_move_available(my_index)) {
@


1.14
log
@forfeit link added
@
text
@d13 1
a13 1
    my_index = -1;
d46 3
d83 2
@


1.13
log
@Support forfeit request
@
text
@d49 3
@


1.12
log
@* Add templates for rs6k;
this may break everything else.

* Fix can_go in player

* Fix set time.
@
text
@d105 1
a105 1
	    return new normal_response(false); // fixme
d109 11
@


1.11
log
@New machine player.
@
text
@d37 2
a38 2
    << "/set_time_left\">";
  body << "<INPUT NAME=\"time\" VALUE=\"" << get_time() << "\">";
@


1.10
log
@Implement set_time and set (set?can_go=foo)
Fix error in detach handling.


l
@
text
@d35 5
a39 5
  body << ": Time remaining(ms): " << get_time() << "</H3><P>" << endl;
  body << "<A HREF=\"" << get_game()->uri_with_move() << "player/" 
    << my_index << "/detach\">";
  body << "Detach from this Game" << "</A>" << endl;

d42 1
a42 1
  body << "Name:: ";
d46 3
@


1.9
log
@Many piddly things. Read the Changelogs.
@
text
@d99 1
a99 1
	if (!attached) {
@


1.8
log
@More display updates
@
text
@d41 1
a41 1
    << "set_name\">" << endl;
@


1.7
log
@Lots of display fixes and changes.
@
text
@d36 2
a37 2
  body << "<A HREF=\"" << get_game()->uri() << "player/" << my_index 
      << "/detach\">";
d40 1
a40 1
  body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri() 
d43 2
a44 2
  body << "<INPUT NAME=\"name\" VALUE=\"" << get_name() 
      << "\">" << endl;
@


1.6
log
@Improvements to machine_player and human_player display methods.
(More work to do on machine_player, will do after skating.)

Noted lots of warnings about passing strings in ...'s, is this going
to be a problem?
@
text
@d32 1
a32 1
  body << "<H2>" << get_name();
d35 1
a35 1
  body << " Time remaining (us): " << get_time() << "</H2><P>" << endl;
d50 4
a53 4
    stop_clock();
    if (get_game()->get_board()->valid_move_available(my_index)) {
	start_clock();
    } 
d57 4
a60 4
    stop_clock();
    if (get_game()->get_board()->valid_move_available(my_index)) {
	start_clock();
    } 
d64 5
a68 5
    stop_clock();
    consider_forfeiting();
    if (get_game()->get_board()->valid_move_available(my_index)) {
	start_clock();
    }
@


1.5
log
@bug fixes
@
text
@d30 17
a46 5
    string position;
    if (!get_position(position))
	position = "nothing";
    body << get_name() << " is playing " << position <<" and has "
	 << get_time() <<"\n";
@


1.4
log
@Fix timing in player,
add get to human_player,
fix error in game::apply
@
text
@d7 1
d26 1
d40 1
a40 1
	start_clocnk();
d68 1
a68 1
	return new error_response(http_response::SERVER_ERROR, "Shouldn't be able to call unassociated player.");
d81 1
a81 1
		return get_game->display(ext, my_index);
d88 3
a90 3
	    stop_clock()
		detach();
	    return normal_response(false); // fixme
d94 1
a94 1
    else return player::get(request,ext);
@


1.3
log
@minor fixes
@
text
@d3 1
d5 2
d62 34
@


1.2
log
@Tidy up human_player,
implement machine_player::get
@
text
@d14 1
d16 1
a16 1
attached = false;
a18 1

d25 5
a29 1
    body << "Hello!  This is "<< get_name() << ", a human player\n";
d33 1
a33 1
    stop_clock();n
d40 1
a41 1
	stop_clock();
d47 1
a47 2
	stop_clock();

@


1.1
log
@created file
@
text
@d12 1
a12 1
// Needs to be finished
d15 1
d18 2
a19 2
// Needs to be finished
void human_player::attach(string name, game *gm){
d21 1
a21 1
    associate(gm);
d29 1
a29 1
    stop_clock();
d31 1
a31 1
	start_clock();
d37 1
d43 2
d55 2
@
