-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.h
94 lines (77 loc) · 1.99 KB
/
Board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// jammon17@georgefox.edu
// Assignment 9
// 2019-04-24
#ifndef _BOARD_H
#define _BOARD_H
#include <ostream>
#include "Square.h"
// forward declarations
class Square;
/**
* Implements a Board object that contains a matrix of
* Square objects
*/
class Board {
public:
/**
* Returns a pointer to the board object
* If a board doesn't it will call the constructor
* creating a static instance of it
*
* @return square (Square*)
*/
static Board* getInstance();
/**
* Deletes the singleton instance the board freeing allocated memory
* used for Board when the game ends to prevent memory leaks
*/
static void deleteInstance();
/**
* Returns a pointer to the Square object at
* the given location in the board matrix
*
* @param rank (int)
* @param file (int)
* @return square (Square*)
*/
Square* getSquareAt(int file, int rank);
/**
* Checks if the rank is clear from
* the given Square& to the other given Square&
*
* @param from (Square&)
* @param to (Square&)
* @return true if not occupied else false
*/
bool isClearRank(Square& from, Square& to);
/**
* Checks if the file is clear from
* the given Square& to the other given Square&
*
* @param from (Square&)
* @param to (Square&)
* @return true if not occupied else false
*/
bool isClearFile(Square& from, Square& to);
/**
* Checks if the diagonal is clear from
* the given Square& to the other given Square&
*
* @param from (Square&)
* @param to (Square&)
* @return true if not occupied else false
*/
bool isClearDiagonal(Square& from, Square& to);
/**
* Displays the the entire board
*/
void display();
private:
// private attributes
static const int DIMENSION = 8;
static Board* _instance;
Square _squares[DIMENSION][DIMENSION];
// zero-argument constructor
Board();
};
#endif //_BOARD_H