OOP A3 Board Games 35
a Board Game Project Made by Students at Cairo FCAI
Loading...
Searching...
No Matches
Numerical_Board.h
Go to the documentation of this file.
1#pragma once
2#include "BoardGame_Classes.h"
3
4class Numerical_Board : public Board<int> {
5public:
7 for (auto& r : board) fill(r.begin(), r.end(), 0);
8 }
9
10 bool update_board(Move<int>* m) override {
11 int x = m->get_x(), y = m->get_y(), val = m->get_symbol();
12 if (x < 0 || x >= 3 || y < 0 || y >= 3 || board[x][y] != 0)
13 return false;
14 board[x][y] = val;
15 return true;
16 }
17
18 bool is_win(Player<int>* p) override {
19 for (int i = 0; i < 3; i++) {
20 if (board[i][0] + board[i][1] + board[i][2] == 15) return true;
21 if (board[0][i] + board[1][i] + board[2][i] == 15) return true;
22 }
23 if (board[0][0] + board[1][1] + board[2][2] == 15) return true;
24 if (board[0][2] + board[1][1] + board[2][0] == 15) return true;
25 return false;
26 }
27
28 bool is_draw(Player<int>* p) override {
29 for (auto& r : board)
30 for (int c : r)
31 if (c == 0) return false;
32 return !is_win(p);
33 }
34
35 bool is_lose(Player<int>* p) override { return false; }
36
37 bool game_is_over(Player<int>* p) override {
38 return is_win(p) || is_draw(p);
39 }
40};
Board(int rows, int columns)
Definition BoardGame_Classes.h:51
vector< vector< int > > board
Definition BoardGame_Classes.h:44
Represents a single move in a board game.
Definition BoardGame_Classes.h:100
T get_symbol() const
Get the move symbol.
Definition BoardGame_Classes.h:116
int get_y() const
Get column index.
Definition BoardGame_Classes.h:113
int get_x() const
Get row index.
Definition BoardGame_Classes.h:110
bool is_lose(Player< int > *p) override
Check if a player has lost.
Definition Numerical_Board.h:35
bool game_is_over(Player< int > *p) override
Check if the game is over.
Definition Numerical_Board.h:37
Numerical_Board()
Definition Numerical_Board.h:6
bool is_draw(Player< int > *p) override
Check if the game ended in a draw.
Definition Numerical_Board.h:28
bool is_win(Player< int > *p) override
Check if a player has won.
Definition Numerical_Board.h:18
bool update_board(Move< int > *m) override
Update the board with a new move.
Definition Numerical_Board.h:10
Base template for all players (human or AI).
Definition BoardGame_Classes.h:126