-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame3.h
More file actions
101 lines (84 loc) · 2.4 KB
/
Copy pathGame3.h
File metadata and controls
101 lines (84 loc) · 2.4 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
// Header of Game3
// Author: Shahd Mohamed Ahmed
// ID : 20220533
// section : S22
// Date: 17/12/2023
// Version: 1
#ifndef INCLUDE_GAME3_H
#define INCLUDE_GAME3_H
#include<bits/stdc++.h>
using namespace std;
class Board3 {
protected:
int n_rows, n_cols;
char** board;
int n_moves = 0;
public:
// Return true if move is valid and put it on board
// within board boundaries in empty cell
// Return false otherwise
virtual bool update_board3 (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_winner3() = 0;
// Return true if all moves are done and no winner
virtual bool is_draw3() = 0;
// Display the board and the pieces on it
virtual void display_board3() = 0;
// Return true if game is over
virtual bool game_is_over3() = 0;
};
// Inherit from class Board
class Game3_X_O_Board: public Board3 {
public:
Game3_X_O_Board ();
bool update_board3 (int x, int y, char mark);
void display_board3();
bool is_winner3();
bool is_draw3();
bool game_is_over3();
};
class Player3 {
protected:
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
Player3 (char symbol); // Needed for computer players
//Player (int order, char symbol);
// Get desired move: x y (each between 0 and 2)
// Virtual (can change for other player types)
virtual void get_move(int& x, int& y);
// Get symbol used by player
char get_symbol();
};
class RandomPlayer3: public Player3 {
protected:
int dimension;
public:
// Take a symbol and pass it to parent
RandomPlayer3 (char symbol, int dimension);
// Generate a random move
void get_move(int& x, int& y);
};
class GameManager3 {
protected:
Board3* boardPtr;
Player3* players[2];
public:
GameManager3(Board3*, Player3* 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
};
#endif //INCLUDE_GAME3_H