Using functions from other classes and printing

Hello guys. I have an excercise and I need some help. I am asked to play a game that has a number of players and a number of heaps inserted by the user. Each heap has some coins. The players takes some coins from one heap and if he wants puts some of them in an other. They call it specker game. Dont know if you have heard about it. The excercise has 3 parts which is actually building classes and it is checked by a grader which is made by our teacher. Grader puts a main() and test cases. Here are the parts
1:
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
1 class Move {
2 public:
3 // Take sc coins from heap sh and put tc coins to heap th.
4 Move(int sh, int sc, int th, int tc);
5
6 int getSource() const;
7 int getSourceCoins() const;
8 int getTarget() const;
9 int getTargetCoins() const;
10
11 friend ostream & operator << (ostream &out, const Move &move);
12 };

1 class State {
2 public:
3 // State with h heaps, where the i-th heap starts with c[i] coins.
4 State(int h, const int c[]);
5 ~State();
6
7 void next(const Move &move) throw(logic_error);
8 bool winning() const;
9
10 int getHeaps() const;
11 int getCoins(int h) const throw(logic_error);
12
13 friend ostream & operator << (ostream &out, const State &state);
14 };

2:
1
2
3
4
5
6
7
8
9
10
1 class Player {
2 public:
3 Player(const string &n);
4 virtual ~Player();
5
6 virtual const string & getType() const = 0;
7 virtual Move play(const State &s) = 0;
8
9 friend ostream & operator << (ostream &out, const Player &player);
10 };

in the second part we use inheritance to create types of players. I have built part 1 and part 2 and they are correct. My problem is with part 3:

1
2
3
4
5
6
7
8
9
1 class Game {
2 public:
3 Game(int heaps, int players);
4 ~Game();
5
6 void addHeap(int coins) throw(logic_error);
7 void addPlayer(Player *player) throw(logic_error);
8 void play(ostream &out) throw(logic_error);
9 };


I have this far by now
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
class Game {
	 public:
		
		 Game(int heaps, int players) {
			 heapsNum = heaps;
			 playersNum = players;
			 c[heapsNum] = 0;
			 p[playersNum] = 0;
			 pTop = 0;
			 hTop = 0;
		 }
		
		 ~Game() {
			 delete[]c;
			 delete[]p;
		 }
		 
		 void addHeap(int coins) throw(logic_error) {
			 if(coins < 0) throw logic_error("Λάθος αριθμός νομισμάτων")
			 else {
				 
				 c[hTop] = coins;
				 ++hTop;
			 }
		 }
		 
		 void addPlayer(Player *player) throw(logic_error){
			 
			 p[pTop] = player;
			 ++pTop;
		 
		 void play(ostream &out) throw(logic_error){
			
		
private: 
	int heapsNum, playersNum, hTop, pTop;
	*c;
	Player **p;
};

In the instructions says that addHeap and addPlayer adds coins to the heaps and players one by one. My question is: How can i use some of the functions that i have created from the other parts and print the State, Move etc
Topic archived. No new replies allowed.