2 * agent++ : A Sample agent for UCC::Progcomp2013
4 * @purpose Declarations for game related classes; Piece, Square, Board
11 // board height and width (don't change!)
12 #define BOARD_HEIGHT 8
22 #include <cstdio> // for vfprintf... for the Exception
26 * @purpose Represent a quantum chess piece
32 typedef enum {PAWN, BISHOP, KNIGHT, ROOK, QUEEN, KING, UNKNOWN} Type;
33 typedef enum {WHITE=0, BLACK=1} Colour;
35 Piece(int x, int y, const Colour & colour, const Type & type1, const Type & type2=UNKNOWN, int type_index = -1); // constructor
36 Piece(const Piece & cpy); // copy constructor
37 virtual ~Piece() {} // destructor
39 int x; int y; // position of the piece
40 Colour colour; // colour of the piece
41 int type_index; // indicates state the piece is in; 0, 1, or -1 (unknown)
42 Type types[2]; // states of the piece
43 Type current_type; // current state of the piece
45 static Type str2type(const std::string & str);
46 static Colour str2colour(const std::string & str);
52 * @purpose Represent a Square on the board; not necessarily occupied
57 Square() : x(-1), y(-1), piece(NULL) {} // constructor
58 Square(int new_x, int new_y, Piece * new_piece = NULL) : x(new_x), y(new_y), piece(new_piece) {} //UNUSED
59 Square(const Square & cpy) : x(cpy.x), y(cpy.y), piece(cpy.piece) {} // copy constructor (UNUSED)
60 virtual ~Square() {} //destructor
61 int x; int y; // position of the square
62 Piece * piece; // Piece that is in the Square (NULL if unoccupied)
67 * @purpose Represent a quantum chess board
72 Board(bool choose_types = false); // constructor
73 Board(const Board & cpy); // copy constructor
74 virtual ~Board(); // destructor
77 // helper; return vector of pieces given player colour
78 std::vector<Piece*> & pieces(const Piece::Colour & colour) {return ((colour == Piece::WHITE) ? white : black);}
79 // helper; return king given player colour
80 Piece * king(const Piece::Colour & colour) {return ((colour == Piece::WHITE) ? white_king : black_king);}
82 void Update_move(int x, int y, int x2, int y2); // move a piece
83 void Update_select(int x, int y, int index, const std::string & type); // update a selected piece
85 Square & square(int x, int y) {return grid[x][y];} // get square on board
87 void Get_moves(Piece * p, std::vector<Square*> & v); // get allowed moves for piece
89 // determine if position is on the board
90 bool Valid_position(int x, int y) {return (x >= 0 && x <= BOARD_WIDTH-1 && y >= 0 && y <= BOARD_HEIGHT-1);}
93 Square grid[BOARD_WIDTH][BOARD_HEIGHT];
96 std::vector<Piece*> white;
97 std::vector<Piece*> black;
101 // Add a move to the vector if it is valid
102 void Move(Piece * p, int x, int y, std::vector<Square*> & v);
104 // Add all valid moves in a direction, stopping at the first invalid move
105 void Scan(Piece * p, int vx, int vy, std::vector<Square*> & v);
110 * @purpose The only exception.
115 Exception(const char * funct, const char * fmt, ...)
117 fprintf(stderr, "Exception in %s - ", funct);
120 vfprintf(stderr, fmt, va);
122 fprintf(stderr, "\n");