head	1.28;
access;
symbols
	tonic_4:1.28
	tonic_3:1.28
	tonic_2:1.28
	demo:1.27.0.2
	design_report:1.26
	oral_presentation_freeze:1.9.0.2
	DAVEG_CDP:1.8.0.2
	template_integ:1.7.0.2;
locks; strict;
comment	@ * @;


1.28
date	95.12.14.23.27.44;	author daveg;	state Exp;
branches;
next	1.27;

1.27
date	95.12.13.03.30.44;	author daveg;	state Exp;
branches;
next	1.26;

1.26
date	95.12.11.08.22.21;	author daveg;	state Exp;
branches;
next	1.25;

1.25
date	95.12.11.07.10.40;	author hartmans;	state Exp;
branches;
next	1.24;

1.24
date	95.12.10.05.16.13;	author hartmans;	state Exp;
branches;
next	1.23;

1.23
date	95.12.09.23.40.53;	author daveg;	state Exp;
branches;
next	1.22;

1.22
date	95.12.08.03.15.02;	author jered;	state Exp;
branches;
next	1.21;

1.21
date	95.12.04.10.33.10;	author daveg;	state Exp;
branches;
next	1.20;

1.20
date	95.12.04.05.48.19;	author daveg;	state Exp;
branches;
next	1.19;

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

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

1.17
date	95.12.03.19.58.07;	author hartmans;	state Exp;
branches;
next	1.16;

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

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

1.14
date	95.12.02.12.03.24;	author daveg;	state Exp;
branches;
next	1.13;

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

1.12
date	95.12.01.13.59.16;	author daveg;	state Exp;
branches;
next	1.11;

1.11
date	95.12.01.04.28.58;	author daveg;	state Exp;
branches;
next	1.10;

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

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

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

1.7
date	95.11.23.09.48.12;	author daveg;	state Exp;
branches;
next	1.6;

1.6
date	95.11.23.09.14.14;	author daveg;	state Exp;
branches;
next	1.5;

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

1.4
date	95.11.20.23.26.54;	author daveg;	state Exp;
branches;
next	1.3;

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

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

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


desc
@@


1.28
log
@fixed pawn promotion
@
text
@// This is -*- c++ -*- code

#ifndef __CHESS_DISPLAY_BOARD_H__
#define __CHESS_DISPLAY_BOARD_H__

#include <6170.h>
#include "board.h"
class chess_capture_move;

class chess_display_board : public board {
 
    // Overview: This class is a subtype of class board, for those
    // games played on 8x8 square board between a black and white player,
    // with chess pieces.  It's initial state is always derived from a 
    // given stream.

  public:

    enum chess_piece {
	invalid,
	none,
	pawn,
	rook,
	knight,
	bishop,
	queen,
	king
	};

    enum color {
	blank,
	black,
	white
	};
        
    enum square_t {
	normal
	};
    
    struct square {
	chess_piece piece_type;
	color piece_color;
	color square_color;
	square_t square_type;
      };
    
    struct path {
	int x1;
	int y1;
	int x2;
	int y2;
    };
            
    // Constructors and Destructors

    chess_display_board(istream &initial_format);
    // Effects: Constructs a chess_display_board that is not
    // associated with any game.  If initial_format fails to
    // meet the description stated in the Design Document, will be
    // initialized to the empty board, and calls to
    // initialized_correctly will return false.  Otherwise, the board
    // will correspond to the description in initial_format, and
    // initialized_correctly will return true.

    virtual ~chess_display_board();
    // Effects: Frees any resources associated with the chess_display_board.
    // Because garbage collection is performed, calling this
    // destructor is not strictly necessary, but if it is known that a
    // board wil not be needed, destroying it may avoid heap
    // fragmentation.

    // Methods

    virtual bool initialized_correctly() const;
    // Effects: Returns true if board was loaded successfully by
    // constructor, else returns false.

    virtual void display(extensions *ext, ostream& body, int player_num) const;

    virtual http_response *get(string request, extensions *ext);
    
    int pieces_remaining(int player_num) const;
    //Effects: If this is a valid player, returns the number of pieces
    //the given player has left, else returns -1.

    virtual int starting_pieces() const;
    // Effects: Returns the total number of pieces that were available
    // at the beginning of the game.

    void place_piece(int x, int y, chess_piece piece, 
			     color piece_color);
    // Modifies: this
    // Checks: 0 <= x,y <= 7, the square at the given coordinates
    // has chess piece none.
    // Effects: Sets the square at the given coordinates to contain
    // the pice with given properties.

    void remove_piece(int x, int y);
    // Modifies: this
    // Checks: 0 <= x,y <= 7, the square at the given coordinates does
    // not have chess piece none.
    // Effects: Sets the square at the given coordinates to have chess
    // piece none.

    void move_piece(int x1, int y1, int x2, int y2, bool promotion);
    // Modifies: this
    // Checks: 0 <= x1,y2,x2,y2 <= 7, the square at the coordinates
    // x1,y1 does not have chess piece none.
    // Effects: Modifies the square at coordinates x1, y1 to be empty,
    // and fills the square at coordinates x2,y2 with the piece
    // previously in the first square.

    square fetch(int y, int x) const;
    // Checks: 0 <= x,y <= 7
    // Effects: Returns the square at the given coordinates.

    void save(ostream &out) const;
    // Effects: Saves the state of this board to the given stream.
    // The output format is as specified in the problem set.

    static typeinfo_t typeinfo;

    virtual void * force (typeinfo_t &t);
    // Effects: Returns this, if t equals typeinfo, else returns a
    // NULL pointer.

    square operator()(int y, int x) const;
    // Effects: returns the requested square of this board

    int current_player() const;
    // Effects: returns the player number of the player who whose turn it currently is.
    
  protected:

    void clone_part (chess_display_board &b) const;

    square ctosquare(char ch) const;
    // Checks: character corresponds to a chess piece.
    // Effects: returns a chess_piece with the piece_type and
    // piece_color corresponding to the given character (none for no
    // color) and the other field unspecified.

    char squaretoc(square sq) const;
    // Effects: Returns a char corresponding to the chess piece on the
    // given square, lower case for black, upper for white.

    bool move_validity(int player_num, path &p, chess_piece piece_taken) const;
    // Effects: Returns true if the given piece on the indicated starting 
    // square could move the path given according to chess rules and
    // take the piece indicated, else returns false.

    void update();
    // Modifies: this
    // Effects: Notifies board that the change in state was responded to.

    bool state_changed() const;
    // Effects: Returns true if board has changed since last call to
    // update, else returns false.
    
    void set_initialization_success(bool success);
    // Modifies: this
    // Effects: Sets initialization_success to the given value.

    chess_display_board();
    // Effects: Creates a new blank chess_display_board

  private:

    virtual void set_square(int x, int y, color square_color, square_t type);
    // Modifies: this
    // Checks:  0 <= x,y <= 7
    // Effects: Sets the square at the given coordinates to have the
    // given properties.

    chess_display_board(const chess_display_board &);
    void operator= (chess_display_board &);

    bool brd_state_changed;
    int white_pieces;
    int black_pieces;
    int total_pieces;
    int player_turn;
        
    typedef array<square> column;
    array<column> brd;
    bool initialization_success;
    bool square_selected;	// true if a square is currently selected; false otherwise.
    int sel_col, sel_row;	// Row and column of selected square.
    
    // Abstraction function: The squres of brd are the squares of the
    // chess board this represents.
  
    // Rep invariant: There are no invalid pieces on the board.
    // brd has dimensions 8x8.
};

inline bool chess_display_board::initialized_correctly() const {
    return initialization_success;
}

inline chess_display_board::square chess_display_board::fetch(int y, int x) const {
    return brd[y][x];
}

inline chess_display_board::square chess_display_board::operator()(int y, int x) const {
    return brd[y][x];
}

inline void chess_display_board::update(){
    brd_state_changed = false;
}

inline bool chess_display_board::state_changed() const {
    return brd_state_changed;
}
bool parse_square(string sq, int &row, int &col);
// Modifies: col, row 
// Effects: returns true and sets col and row to
// the correct values if sq is in the form letter digit, else returns
// false.

inline int chess_display_board::current_player() const {return player_turn;}

inline int chess_display_board::starting_pieces() const {
    return total_pieces;
}

#endif

bool stomove(string s, chess_capture_move &m, const chess_display_board *b);
// Modifies: m
// Effects: If s is of the format 
// <letter[a-h]><number[1-8]>-<letter[a-h]><number[1-8]>, returns true
// and sets m to the corresponding move on the given board, else
// returns false. Will not call any non-const methods on b.
@


1.27
log
@bug fix
@
text
@d105 1
a105 1
    void move_piece(int x1, int y1, int x2, int y2);
@


1.26
log
@added starting_pieces
@
text
@d230 1
a230 1
bool stomove(string s, chess_capture_move &m, board *b);
@


1.25
log
@Update save method prototype.
Add method to game.
@
text
@d86 4
d181 1
d223 5
@


1.24
log
@Fix prototype sort of.
@
text
@d113 3
a115 2
    void save(ostream out) const;
    // Effects: Saves the state of this board to the given filename.
@


1.23
log
@added stomove
@
text
@d8 1
d219 1
a219 1
bool stomove(string s, move &m, board &b);
@


1.22
log
@Fixed row/col swaps a display off-by-ones
@
text
@d210 2
a211 1
// Modifies: col, row Effects: returns true and sets col and row to
d218 6
@


1.21
log
@bug fixes
@
text
@d209 1
a209 1
bool parse_square(string sq, int &col, int &row);
@


1.20
log
@bug fixes
@
text
@d141 4
a144 3
    bool move_validity(int player_num, chess_piece piece, color c, path &p) const;
    // Effects: Returns true if the given piece of the given color could
    // move the path given according to chess rules, else returns false.
@


1.19
log
@bug fixes
@
text
@d127 1
d129 1
a129 1
  protected:
d157 3
a167 1
    chess_display_board();
a187 3

inline chess_display_board::~chess_display_board() {
}
@


1.18
log
@Board selection stuff
@
text
@d140 1
a140 1
    bool move_validity(chess_piece piece, color c, path &p) const;
@


1.17
log
@Rearrange constructors for chess_capture_move,
provide method to find out who has active turn
@
text
@d176 3
a178 1

@


1.16
log
@minor details
@
text
@d124 4
d211 1
@


1.15
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
@d108 1
a108 1
    square fetch(int x, int y) const;
d148 6
a159 6
    void set_initialization_success(bool success);
    // Modifies: this
    // Effects: Sets initialization_success to the given value.

  private:

d167 2
a168 1
    
a172 2
    // This AF and RI are temporary.

d187 1
a187 1
inline chess_display_board::square chess_display_board::fetch(int x, int y) const {
@


1.14
log
@added save and squaretoc methods
@
text
@d203 4
@


1.13
log
@Indicate  that chess_display_board implements get
@
text
@d112 3
d131 4
@


1.12
log
@finished evaluate
@
text
@d77 1
a77 1
    virtual void display(extensions *ext, ostream& body) const;
d79 2
@


1.11
log
@cleanup
@
text
@d131 8
d155 1
d158 1
a158 1

d187 7
@


1.10
log
@changed stuff
@
text
@d79 5
a83 1
    virtual void place_piece(int x, int y, chess_piece piece, 
d91 1
a91 1
    virtual void remove_piece(int x, int y);
d98 1
a98 1
    virtual void move_piece(int x1, int y1, int x2, int y2);
d106 1
a106 1
    virtual square fetch(int x, int y) const;
d147 3
d162 3
@


1.9
log
@updated to match board changes
@
text
@d30 1
d46 7
d97 1
a97 2
    // x1,y1 does not have chess piece none, and that the square at
    // the coordinates x2, y2 has chess piece none.
a101 9
    virtual chess_piece capture_piece(int x1, int y1, int x2, int y2);
    // Modifies: this
    // Checks: 0 <= x1,y2,x2,y2 <= 7, the squares at the coordinatess
    // x1,y1 and x2,y2 do not have chess piece none.
    // Effects: Modifies the square at coordinates x1, y1 to be empty,
    // and fills the square at coordinates x2,y2 with the piece
    // previously in the first square.  Returns the type of piece that
    // previously filled the square at coordinates x2,y2.

d112 3
d120 2
a121 2
    // piece_color corresponding to the given character, and the other
    // two fields unspecified.
d124 1
a124 1
    // Effects: Returns true if the given piece of given color could
d133 3
a135 3
    typedef array<square> column;
    array<column> brd;
    bool initialization_success;
d143 5
a147 1
    // This AF and RI are bullshit for now, will do later.  Dave
d161 1
a161 1
    return brd[y-1][x-1];
d164 5
d170 1
@


1.8
log
@added capture_piece
@
text
@d65 1
a65 1
    bool initialized_correctly() const;
a68 8
    virtual bool is_legal_move(move &m, const player *p) const = 0; 
    // Effects: return true if m is a move compatible with this type
    // of board and player p applying m to this board in the current
    // state would be legal, else return false. If this is not
    // associated with a game, the return value is undefined, but this
    // shall remain in a well-defined state.  This method does not
    // expect m to exist after the call.

a69 3
    // Effects: Returns a html representation of this.  The headers in
    // extensions (if it is non-null) can be used to determine the
    // capabilities of the web client.
d108 2
d111 2
d118 7
a124 4
    // Effects: returns a chess_piece corresponding to the given
    // character.  

  private:
d132 6
a140 4

    typedef array<square> column;
    array<column> brd;
    bool initialization_success;
@


1.7
log
@minor bug fix
@
text
@d101 1
a101 1
    // the coordinates x2, y2 
d105 9
@


1.6
log
@bug fixes
@
text
@d148 1
a148 1
inline chess_display_board::square chess_display_board::fetch(int x, int y) {
@


1.5
log
@Added test_board.C, and Changelog, Updated TODO.
Modified game.C.
@
text
@d6 1
a6 1
#include <6.170.h>
d19 1
d82 1
a82 1
    virtual void place_piece(int x, int y, piece_type piece, 
d110 9
d130 3
a132 2
    
    array<array<square> > brd;
d134 9
a142 2
        
}
d148 2
a149 2
inline square chess_display_board::fetch(int x, int y) {
    return brd[y][x];
@


1.4
log
@cleaned up comments
@
text
@d76 1
a76 1
    virtual void display(extensions *ext, ostream *body) const;
@


1.3
log
@Added remove_piece, checks functions, general clean up
@
text
@a61 1

d122 6
a127 1
    
d131 1
a131 1
    return brd[x][y];
@


1.2
log
@Renamed SQUARE to square (it's not a macro...), and fixed some bogosities
with things that are not possible to do.
@
text
@d19 1
d65 1
a65 1
   bool initialized_correctly() const;
d70 6
a81 5
    virtual void set_square(int x, int y, color square_color, square_t type);
    // Modifies: this
    // Effects: Sets the square at the given coordinates to have the
    // given properties.

d85 2
d90 7
d99 3
d107 1
d110 1
d112 5
a116 2

  private:
@


1.1
log
@Version 0.9 of Chess Display Board abstraction
@
text
@d12 3
a14 2
    // games played on 8x8 square board.  It's initial state is always
    // derived from a given stream.
d25 1
a25 1
	}
d30 1
a30 1
	}
d34 1
a34 1
    }
d36 1
a36 1
    struct SQUARE {
d41 1
a41 1
    }
d64 1
a64 10
    virtual bool is_legal_move(move &m, const player *p) const = 0;
    // Effects: return true if m is a move compatible with this type
    // of board and player p applying m to this board in the current
    // state would be legal, else return false. If this is not
    // associated with a game, the return value is undefined, but this
    // shall remain in a well-defined state.  This method does not
    // expect m to exist after the call.


    bool initialized_correctly() const;
d68 2
d89 1
a89 1
    // and moves fills the square at coordinates x2,y2 with the piece
d92 1
a92 1
    virtual SQUARE fetch(int x, int y) const;
a94 3
    virtual SQUARE operator[] (int x, int y) const;
    // Effects: Returns the square at the given coordinates.
    
d103 1
a103 1
    array<array<SQUARE> > brd;
d107 1
a107 1
inline SQUARE chess_display_board::fetch(int x, int y) {
a109 5

inline SQUARE chess_display_board::operator[int x, int y]{
    return chess_display_board::fetch(x, y);
}

@
