X-Git-Url: https://git.ucc.asn.au/?p=progcomp2013.git;a=blobdiff_plain;f=agents%2Fc%2B%2B%2Fqchess.h;fp=agents%2Fc%2B%2B%2Fqchess.h;h=40b09f182b098ca00842e573051d1add2cceefab;hp=b2b499ad012a62e125dff267add5b62d6f123d42;hb=7518ec8d771e731d6ffbbe00b275b7e3c4b23301;hpb=8571bc0c18f4a42bd1c8f34a5a36bcd9678b3f14;ds=sidebyside diff --git a/agents/c++/qchess.h b/agents/c++/qchess.h index b2b499a..40b09f1 100644 --- a/agents/c++/qchess.h +++ b/agents/c++/qchess.h @@ -32,8 +32,6 @@ class Piece typedef enum {PAWN, BISHOP, KNIGHT, ROOK, QUEEN, KING, UNKNOWN} Type; typedef enum {WHITE=0, BLACK=1} Colour; - Piece(int x, int y, const Colour & colour, const Type & type1, const Type & type2=UNKNOWN, int type_index = -1); // constructor - Piece(const Piece & cpy); // copy constructor virtual ~Piece() {} // destructor int x; int y; // position of the piece @@ -44,6 +42,18 @@ class Piece static Type str2type(const std::string & str); static Colour str2colour(const std::string & str); + static const char * type2str(const Type & t); + + static Piece * AddPiece(std::vector & v, int x, int y, const Colour & colour, const Type & type1, const Type & type2, int type_index=-1); + + private: + friend class Board; + Piece(int x, int y, const Colour & colour, const Type & type1, const Type & type2 + , int type_index, int new_piece_index); // constructor + Piece(const Piece & cpy); // copy constructor + + int piece_index; // index of the piece in Board's pieces vector + }; @@ -70,33 +80,55 @@ class Board { public: Board(bool choose_types = false); // constructor - Board(const Board & cpy); // copy constructor + Board(Board & parent); // clones a board, copy on write virtual ~Board(); // destructor // helper; return vector of pieces given player colour std::vector & pieces(const Piece::Colour & colour) {return ((colour == Piece::WHITE) ? white : black);} + // helper; return map of unidentified 2nd types for given colour + std::map & unknown_types(const Piece::Colour & colour) + { + return ((colour == Piece::WHITE) ? white_unknown : black_unknown); + } + + int & nUnknown(const Piece::Colour & colour) + { + return ((colour == Piece::WHITE) ? white_nUnknown : black_nUnknown); + } + // helper; return king given player colour Piece * king(const Piece::Colour & colour) {return ((colour == Piece::WHITE) ? white_king : black_king);} void Update_move(int x, int y, int x2, int y2); // move a piece void Update_select(int x, int y, int index, const std::string & type); // update a selected piece + void Update_select(int x, int y, int index, const Piece::Type & t); Square & square(int x, int y) {return grid[x][y];} // get square on board - void Get_moves(Piece * p, std::vector & v); // get allowed moves for piece + void Get_moves(Piece * p, std::vector & v); // get allowed moves for piece of known type // determine if position is on the board bool Valid_position(int x, int y) {return (x >= 0 && x <= BOARD_WIDTH-1 && y >= 0 && y <= BOARD_HEIGHT-1);} + + bool IsClone() const {return parent != NULL;} + void Clone_copy(Square & s); private: Square grid[BOARD_WIDTH][BOARD_HEIGHT]; - + // All pieces for each player std::vector white; std::vector black; + // The number of pieces with each 2nd type that are still unidentified + std::map white_unknown; + std::map black_unknown; + int white_nUnknown; + int black_nUnknown; Piece * white_king; Piece * black_king; + + Board * parent; // Add a move to the vector if it is valid void Move(Piece * p, int x, int y, std::vector & v);