-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardGame_Classes.hpp
More file actions
174 lines (167 loc) · 4.66 KB
/
Copy pathBoardGame_Classes.hpp
File metadata and controls
174 lines (167 loc) · 4.66 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Class definition for Games
// Author: Mohammad El-Ramly
// Date: 10/10/2022
// Version: 1
#ifndef _BoardGame_CLASSES_H
#define _BoardGame_CLASSES_H
#include <bits/stdc++.h>
using namespace std;
class Board {
protected:
int n_rows, n_cols;
int n_moves = 0;
public:
char** board;
char symbol;
// Return true if move is valid and put it on board
// within board boundaries in empty cell
// Return false otherwise
virtual bool update_board (int x, int y, char symbol) = 0;
// Returns true if there is any winner
// either X or O
// Written in a complex way. DO NOT DO LIKE THIS.
virtual bool is_winner() = 0;
// Return true if all moves are done and no winner
virtual bool is_draw() = 0;
// Display the board and the pieces on it
virtual void display_board() = 0;
// Return true if game is over
virtual bool game_is_over() = 0;
};
///////////////////////////////////////////
// This class represents a player who has
// a name and a symbol to put on board
class Player {
protected:
string name;
char symbol;
public:
// Two constructors to initiate player
// Give player a symbol to use in playing
// It can be X or O or others
// Optionally, you can give him ID or order
// Like Player 1 and Player 2
Player (char symbol); // Needed for computer players
Player (int order, char symbol);
// Get desired move: x y (each between 0 and 2)
virtual void get_move(int& x, int& y);
// Give player info as a string
string to_string();
// Get symbol used by player
char get_symbol();
};
///////////////////////////////////////////
// This class represents a random computer player
// that generates random positions x y (0 to 2)
// If invalid, game manager asks to regenerate
class RandomPlayer: public Player {
protected:
int dimension;
public:
// Take a symbol and pass it to parent
RandomPlayer (char symbol, int dimension);
// Generate a random move
void get_move(int& x, int& y);
};
///////////////////////////////////////////
class GameManager {
private:
Player* players[2];
Board* boardPtr;
public:
GameManager(Board*, Player* playerPtr[2]);
void run();
// This method creates board and players
// It displays board
// While True
// For each player
// It takes a valid move as x, y pair (between 0 - 2)
// It updates board and displays otit
// If winner, declare so and end
// If draw, declare so and end
};
///////////////////////////////////////////
// This class represents a 7 x 6 board
// used in Connect_four game
class connectFour_Board:public Board{
public:
connectFour_Board ();
bool update_board (int x, int y, char mark);
void display_board();
bool is_winner();
bool is_draw();
bool game_is_over();
};
///////////////////////////////////////////
//Players to play connect-four game
class connectFour_player:public Player
{
public:
connectFour_player (int order, char symbol);
void get_move(int &x, int &y) override;
};
class New_RandomPlayer:public Player
{
private:
int dX,dY;
public:
New_RandomPlayer(char symbol,int dX,int dY);
void get_move(int &x, int &y) override;
};
class Tic_Tac_Toe_Board:public Board {
public:
Tic_Tac_Toe_Board ();
bool update_board (int x, int y, char mark);
void display_board();
bool is_winner();
bool is_draw();
bool game_is_over();
};
class GameManager_Tic_Tac_Toc {
private:
Board* boardPtr;
Player* players[2];
public:
GameManager_Tic_Tac_Toc(Board*, Player* playerPtr[2]);
void run();
};
class Tic_Tac_Toe_player:public Player
{
public:
Tic_Tac_Toe_player (int order, char symbol);
void get_move(int &x, int &y) override;
};
class PY_Board:public Board{
public:
PY_Board ();
bool update_board (int x, int y, char mark) override;
void display_board() override;
bool is_winner() override;
bool is_draw() override;
bool game_is_over() override;
};
class PY_Player:public Player{
public:
PY_Player(int order, char symbol);
void get_move(int& x, int& y);
};
class X_O_Board:public Board {
public:
X_O_Board ();
bool update_board (int x, int y, char mark);
void display_board();
bool is_winner();
bool is_draw();
bool game_is_over();
};
class ConnectFour_AI_Player:public Player
{
private:
Board *ptr;
int MinMax(int &x, int &y,bool maximize,int cnt);
bool last(int &a,int &b);
public:
ConnectFour_AI_Player(char symbol,Board*ptr);
void get_move(int &x, int &y) override;
};
#endif