Add explanation of Board.pieces
[progcomp2013.git] / agents / agent++ / qchess.h
1 /**
2  * agent++ : A Sample agent for UCC::Progcomp2013
3  * @file qchess.h
4  * @purpose Declarations for game related classes; Piece, Square, Board
5  */
6
7 #ifndef _QCHESS_H
8 #define _QCHESS_H
9
10
11 // board height and width (don't change!)
12 #define BOARD_HEIGHT 8
13 #define BOARD_WIDTH 8
14
15 #include <string>
16 #include <vector>
17 #include <map>
18 #include <cstdlib>
19 #include <iostream>
20
21 /**
22  * @class Piece
23  * @purpose Represent a quantum chess piece
24  */
25 class Piece
26 {
27         public:
28                 Piece(int x, int y, const std::string & new_colour, const std::string & type1 = "unknown", const std::string & type2 = "unknown", int new_type_index = -1); // constructor
29                 Piece(const Piece & cpy); // copy constructor
30                 virtual ~Piece() {} // destructor
31
32                 int x; int y; // position of the piece
33                 std::string colour; // colour of the piece
34                 int type_index; // indicates state the piece is in; 0, 1, or -1 (unknown)
35                 std::string types[2]; // states of the piece
36                 std::string current_type; // current state of the piece
37                 
38
39 };
40
41 /**
42  * @class Square
43  * @purpose Represent a Square on the board; not necessarily occupied
44  */
45 class Square
46 {
47         public:
48                 Square() : x(-1), y(-1), piece(NULL) {} // constructor
49                 Square(int new_x, int new_y, Piece * new_piece = NULL) : x(new_x), y(new_y), piece(new_piece) {} //UNUSED
50                 Square(const Square & cpy) : x(cpy.x), y(cpy.y), piece(cpy.piece) {} // copy constructor (UNUSED)
51                 virtual ~Square() {} //destructor
52                 int x;  int y; // position of the square
53                 Piece * piece; // Piece that is in the Square (NULL if unoccupied)
54 };
55
56 /**
57  * @class Board
58  * @purpose Represent a quantum chess board
59  */
60 class Board
61 {
62         public:
63                 Board(bool choose_types = false); // constructor
64                 Board(const Board & cpy); // copy constructor
65                 virtual ~Board(); // destructor
66
67
68                 // helper; return vector of pieces given player colour
69                 std::vector<Piece*> & pieces(const std::string & colour) {return ((colour == "white") ? white : black);}        
70                 // helper; return king given player colour      
71                 Piece * king(const std::string & colour) {return ((colour == "white") ? white_king : black_king);}
72                 
73                 void Update_move(int x, int y, int x2, int y2); // move a piece
74                 void Update_select(int x, int y, int index, const std::string & type); // update a selected piece
75         
76                 Square & square(int x, int y) {return grid[x][y];} // get square on board
77
78                 void Get_moves(Piece * p, std::vector<Square*> & v); // get allowed moves for piece
79
80                 // determine if position is on the board
81                 bool Valid_position(int x, int y) {return (x >= 0 && x <= BOARD_WIDTH-1 && y >= 0 && y <= BOARD_HEIGHT-1);}
82
83         private:
84                 Square grid[BOARD_WIDTH][BOARD_HEIGHT];
85
86         
87                 std::vector<Piece*> white;
88                 std::vector<Piece*> black;
89                 Piece * white_king;
90                 Piece * black_king;
91
92                 // Add a move to the vector if it is valid
93                 void Move(Piece * p, int x, int y, std::vector<Square*> & v);
94
95                 // Add all valid moves in a direction, stopping at the first invalid move
96                 void Scan(Piece * p, int vx, int vy, std::vector<Square*> & v);
97 };
98
99 #endif //_QCHESS_H
100
101 //EOF

UCC git Repository :: git.ucc.asn.au