head	1.14;
access;
symbols
	tonic_4:1.14
	tonic_3:1.14
	tonic_2:1.14
	demo:1.14.0.2
	design_report:1.13;
locks; strict;
comment	@ * @;


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

1.13
date	95.12.11.20.27.17;	author rgmisra;	state Exp;
branches;
next	1.12;

1.12
date	95.12.11.19.54.15;	author rgmisra;	state Exp;
branches;
next	1.11;

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

1.10
date	95.12.11.11.20.02;	author jered;	state Exp;
branches;
next	1.9;

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

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

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

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

1.5
date	95.12.08.03.14.39;	author jered;	state Exp;
branches;
next	1.4;

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

1.3
date	95.12.06.04.53.40;	author jered;	state Exp;
branches;
next	1.2;

1.2
date	95.12.05.09.46.17;	author jered;	state Exp;
branches;
next	1.1;

1.1
date	95.12.04.04.59.50;	author jered;	state Exp;
branches;
next	;


desc
@@


1.14
log
@Don't display the board if it isn't your turn.
@
text
@#include <6170.h>
#include <game.h>
#include <chess_display_board.h>
#include <ctype.h>

static char sq_to_char(chess_display_board::square csq) {
  char ret;

  switch (csq.piece_type) {
  case chess_display_board::none:
    ret='_';
    break;

  case chess_display_board::pawn:
    ret='p';
    break;

  case chess_display_board::rook:
    ret='r';
    break;

  case chess_display_board::knight:
    ret='n';
    break;

  case chess_display_board::bishop:
    ret='b';
    break;

  case chess_display_board::queen:
    ret='q';
    break;

  case chess_display_board::king:
    ret='k';
    break;

  case chess_display_board::invalid:
  default:
    ret='*';
  }

  if (csq.piece_color == chess_display_board::white) 
    ret = toupper(ret);

  return ret;
}

static string sq_to_img(chess_display_board::square csq) {
  string ret;

  if (csq.piece_color == chess_display_board::white)
    ret = "w";
  else ret = "b";

  if (csq.square_color == chess_display_board::white)
   ret= ret.append('w');
  else ret=ret.append('b');

  switch (csq.piece_type) {
  case chess_display_board::none:
    ret = ret+"blank";
    break;

  case chess_display_board::pawn:
    ret = ret+"pawn";
    break;

  case chess_display_board::rook:
    ret = ret+"rook";
    break;

  case chess_display_board::knight:
    ret = ret+"knight";
    break;

  case chess_display_board::bishop:
    ret = ret+"bishop";
    break;

  case chess_display_board::queen:
    ret = ret+"queen";
    break;

  case chess_display_board::king:
    ret = ret+"king";
    break;

  case chess_display_board::invalid:
  default:
    ret = ret+"ACK! YOU WANT WHAT?";
  }

  ret = ret+".gif";
  return ret;
}

void chess_display_board::display(extensions *ext, ostream& body,
				  int player_num) const {
// Piece images are called:
// [s]<w|b><w|b><pawn|rook|knight|bishop|king|queen>.gif
//  1   2    3                   4
//  1: s if selected
//  2: piece color
//  3: square color
//  4: piece type

  square csq;
  
  check(is_associated(),"Board is not associated");
  
  switch (get_game()->winner()) {
  case -1:
      body << "<H2> It is now ";
      if (current_player())
	  body << " black's turn. </H2><P>";
      else body << "white's turn. </H2><P>";
      break;
  case -2:
      body <<"<h2> The game is a draw.</h2>";
      break;
  case 0:
      body <<"<h2> White has won.</h2>";
      break;
  case 1:
      body <<"<h2> Black has won.</h2>";
      break;
  default:
      check(false,"Impossible game winner");
  }
  
  for (int i=7; i>=0; i--) {       // Loop the rows
    body << i+1;
    for (int j=0; j<=7; j++) {     // Loop the columns
      csq=fetch(i,j);
      if (square_selected && (player_num == current_player())) {
	body << "<A HREF=\"" << get_game()->uri_with_move() 
	  << "board/dest?player=" << player_num  << "&square=" 
	  << (char)('a'+j) << i+1 << "\">";
	if ((sel_row == i) && (sel_col == j)) 
	  body << "<IMG BORDER=0 SRC=\"" << get_game()->image_base() << "s" <<
	    sq_to_img(csq) << "\" ALT=\"*" << sq_to_char(csq) << "*\">";
	else
	  body << "<IMG BORDER=0 SRC=\"" << get_game()->image_base() <<
	    sq_to_img(csq) << "\" ALT=\"_" << sq_to_char(csq) << "_\">";
	body << "</A>";
      } else {
	  if (player_num == current_player()) {
	      body << "<A HREF=\"" << get_game()->uri_with_move() 
	  << "board/select?player=" << player_num << "&square=" 
	  << (char)('a'+j) << i+1 << "\">";
	body << "<IMG BORDER=0 SRC=\"" << get_game()->image_base() <<
	  sq_to_img(csq) << "\" ALT=\"_" << sq_to_char(csq) << "_\">";
	body << "</A>";
	  }
	  else 	body << "<IMG BORDER=0 SRC=\"" << get_game()->image_base() <<
	  sq_to_img(csq) << "\" ALT=\"_" << sq_to_char(csq) << "_\">";
      }
    }
    body << "<BR>" << endl;
  }
  body << "<P>";

  if (player_num == current_player()) {// Do form here.
      body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri_with_move() 
	   << "board/move\">" << endl;
      body << "<INPUT TYPE=HIDDEN NAME=\"player\" VALUE=\"" << player_num
	   << "\">" << endl;
      body << "Move From: ";
      if (square_selected)
	  body << "<INPUT NAME=\"from\" VALUE=\"" << (char)('a'+sel_col) << sel_row+1
	       << "\">" << endl;
      else body << "<INPUT NAME=\"from\">" <<endl;

      body << "<BR> Move To: <INPUT NAME=\"to\"><BR>" << endl;
      body << "<INPUT TYPE=SUBMIT VALUE=\"Move\">" << endl;
      body << "</FORM> \n";
}
  body << "<hr>";
  body << "<h2>Save Current Game</h2>";
  body << "<form method=\"get\" action=\"" << get_game()->uri_with_move()
       << "board/save\"> \n";
  body << "<br>\n";
  body << "File name: <input name=\"file\">\n";
  body << "<br>\n";
  body << "<input type=submit value=\"Save Game\">\n";
  body << "</form>\n";

  body << "<HR> <ADDRESS>6.170-team1@@mit.edu</ADDRESS>";

}
@


1.13
log
@added a /form tag
@
text
@d136 1
a136 1
      if (square_selected) {
d148 2
a149 1
	body << "<A HREF=\"" << get_game()->uri_with_move() 
d155 3
d164 10
a173 14
// Do form here.
  body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri_with_move() 
    << "board/move\">" << endl;
  body << "<INPUT TYPE=HIDDEN NAME=\"player\" VALUE=\"" << player_num
    << "\">" << endl;
  body << "Move From: ";
  if (square_selected)
    body << "<INPUT NAME=\"from\" VALUE=\"" << (char)('a'+sel_col) << sel_row+1
      << "\">" << endl;
  else body << "<INPUT NAME=\"from\">" <<endl;

  body << "<BR> Move To: <INPUT NAME=\"to\"><BR>" << endl;
  body << "<INPUT TYPE=SUBMIT VALUE=\"Move\">" << endl;
  body << "</FORM> \n";
d175 4
@


1.12
log
@save stuff...
@
text
@d183 1
@


1.11
log
@More display modifications.
@
text
@d173 13
a185 5
  body << "</FORM> <BR> <FORM METHOD=\"GET\" ACTION=\"";
  body << get_game()->uri_with_move() << "board/save\">" << endl;
  body << "Filename: <INPUT NAME=\"file\">" << endl;
  body << "<INPUT TYPE=SUBMIT VALUE=\"Save\">" << endl;
  body << "</FORM><HR>";
@


1.10
log
@A working breadth-first searcher
@
text
@d173 5
a177 1
  body << "</FORM> <HR> <ADDRESS>6.170-team1@@mit.edu</ADDRESS>";
@


1.9
log
@bug fix
@
text
@d141 1
a141 1
	  body << "<IMG SRC=\"" << get_game()->image_base() << "s" <<
d144 1
a144 1
	  body << "<IMG SRC=\"" << get_game()->image_base() <<
d151 1
a151 1
	body << "<IMG SRC=\"" << get_game()->image_base() <<
@


1.8
log
@Miscenllany
@
text
@d110 2
a111 2


@


1.7
log
@Fix display of winner et al.
@
text
@d145 1
a145 1
	    sq_to_img(csq) << "\" ALT=\" " << sq_to_char(csq) << " \">";
d152 1
a152 1
	  sq_to_img(csq) << "\" ALT=\" " << sq_to_char(csq) << " \">";
@


1.6
log
@Many piddly things. Read the Changelogs.
@
text
@d111 20
a130 5
//FIXME
  body << "<H2> It is now ";
  if (player_num)
    body << " black's turn. </H2><P>";
  else body << "white's turn. </H2><P>";
@


1.5
log
@Fixed row/col swaps a display off-by-ones
@
text
@d147 1
a147 1
    << "move\">" << endl;
@


1.4
log
@More display updates
@
text
@d110 2
d118 1
a118 1
    body << i;
d124 1
a124 1
	  << (char)('a'+j) << i << "\">";
d135 1
a135 1
	  << (char)('a'+j) << i << "\">";
d152 1
a152 1
    body << "<INPUT NAME=\"from\" VALUE=\"" << (char)('a'+sel_col) << sel_row
@


1.3
log
@Fixed some missing double-quotes in HTML.
@
text
@d120 3
a122 2
	body << "<A HREF=\"" << get_game()->uri() << "board/dest?player="  
	  << player_num  << "&square=" << (char)('a'+j) << i << "\">";
d131 3
a133 2
	body << "<A HREF=\"" << get_game()->uri() << "board/select?player="  
	  << player_num << "&square=" << (char)('a'+j) << i << "\">";
d144 1
a144 1
  body << "<FORM METHOD=\"GET\" ACTION=\"" << get_game()->uri() 
d154 2
a155 1
  body << "<BR> Move To: <INPUT NAME=\"to\">" << endl;
@


1.2
log
@Some chess_display_board::display cleanup.
@
text
@d121 1
a121 1
	  << player_num  << "&square=" << (char)('a'+j) << i << ">";
d131 1
a131 1
	  << player_num << "&square=" << (char)('a'+j) << i << ">";
@


1.1
log
@Added chess_display.C; implemented chess_display_board::display
@
text
@d57 2
a58 2
    ret.append('w');
  else ret.append('b');
d121 1
a121 1
	  << player_num  << "&square=" << ('a'+j) << i << ">";
d131 1
a131 1
	  << player_num << "&square=" << ('a'+j) << i << ">";
d148 1
a148 1
    body << "<INPUT NAME=\"from\" VALUE=\"" << ('a'+sel_col) << sel_row
@
