-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.h
More file actions
65 lines (45 loc) · 2.7 KB
/
Board.h
File metadata and controls
65 lines (45 loc) · 2.7 KB
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
#ifndef BOARD_H
#define BOARD_H
#include "Side.h"
class Board
{
public:
Board(int nHoles, int nInitialBeansPerHole);
//Construct a Board with the indicated number of holes per side (not counting the pot) and initial number of beans per hole.
//If nHoles is not positive, act as if it were 1; if nInitialBeansPerHole is negative, act as if it were 0.
Board(const Board& copy);
~Board(); //destructor
//assignment operator
Board& operator=(const Board& rhs);
int holes() const;
//Return the number of holes on a side (not counting the pot).
int beans(Side s, int hole) const;
//Return the number of beans in the indicated hole or pot, or −1 if the hole number is invalid.
int beansInPlay(Side s) const;
//Return the total number of beans in all the holes on the indicated side, not counting the beans in the pot.
int totalBeans() const;
//Return the total number of beans in the game, including any in the pots.
bool sow(Side s, int hole, Side& endSide, int& endHole);
//If the hole indicated by (s,hole) is empty or invalid or a pot, this function returns false without changing anything.
//Otherwise, it will return true after sowing the beans: the beans are removed from hole (s,hole) and sown counterclockwise, including s's pot if encountered, but skipping s's opponent's pot.
//The parameters endSide and endHole are set to the side and hole where the last bean was placed.
//(This function does not make captures or multiple turns; different Kalah variants have different rules about these issues, so dealing with them should not be the responsibility of the Board class.)
bool moveToPot(Side s, int hole, Side potOwner);
//If the indicated hole is invalid or a pot, return false without changing anything.
//Otherwise, move all the beans in hole (s,hole) into the pot belonging to potOwner and return true.
bool setBeans(Side s, int hole, int beans);
//If the indicated hole is invalid or beans is negative, this function returns false without changing anything.
//Otherwise, it will return true after setting the number of beans in the indicated hole or pot to the value of the third parameter.
//(This may change what beansInPlay and totalBeans return if they are called later.)
//This function exists solely so that we and you can more easily test your program:
//None of your code that implements the member functions of any class is allowed to call this function directly or indirectly.
//(We'll show an example of its use below.)
private:
int m_holes_side; //not inclusive of pot
int m_total_holes; //not inclusive of pot
int num_beans_north;
int num_beans_south;
int* grid0;
int* grid1;
};
#endif // !BOARD_H