| OOP A3 Board Games 35 a Board Game Project Made by Students at Cairo FCAI

Loading...
Searching...
No Matches
SUSUI.h
Go to the documentation of this file.
1#pragma once
2#include "BoardGame_Classes.h"
3#include <iostream>
4 using namespace std;
5
6 class SUSUI : public UI<char> {
7 public:
8
9
10 //SUSUI() : UI<char>(3) {}
11 SUSUI() : UI<char>("SUS Game", 3) {} //constructo
12 Move<char>* get_move(Player<char>* p) override {
13 int x, y;
14 //Added Computer Log
15 if (p->get_type() == PlayerType::COMPUTER) {
16 // Computer move logic
17 srand(static_cast<unsigned int>(time(0)));
18 auto board_matrix = p->get_board_ptr()->get_board_matrix();
19 do {
20 x = rand() % 3;
21 y = rand() % 3;
22 } while (board_matrix[x][y] != ' ');
23 cout << "\nComputer played at (" << x << "," << y << ")\n";
24 return new Move<char>(x, y, p->get_symbol());
25 }
26 else {
27 // Human move
28 cout << p->get_name() << " (" << p->get_symbol() << ") enter x y (0-2): ";
29 cin >> x >> y;
30 return new Move<char>(x, y, p->get_symbol());
31 }
32 }
33
34
35
36 // Added BY AO
37 Player<char>* create_player(string& name, char symbol, PlayerType type) override {
38 cout << "Creating " << (type == PlayerType::HUMAN ? "human" : "computer")
39 << " player: " << name << " (" << symbol << ")\n";
40 return new Player<char>(name, symbol, type);
41 }
42
43 void display_message(string s) {
44 cout << s << endl;
45 }
46};
47
48
BoardGame_Classes.h
PlayerType
PlayerType
Represents the type of player in the game.
Definition BoardGame_Classes.h:24
PlayerType::HUMAN
@ HUMAN
A human player.
Definition BoardGame_Classes.h:25
PlayerType::COMPUTER
@ COMPUTER
A computer-controlled player.
Definition BoardGame_Classes.h:26
Move
Represents a single move in a board game.
Definition BoardGame_Classes.h:100
Player
Base template for all players (human or AI).
Definition BoardGame_Classes.h:126
Player::get_type
PlayerType get_type() const
Get player type (e.g., 'H' or 'C').
Definition BoardGame_Classes.h:147
Player::get_board_ptr
Board< T > * get_board_ptr() const
Get a pointer to the game board.
Definition BoardGame_Classes.h:153
Player::get_name
string get_name() const
Get the player's name.
Definition BoardGame_Classes.h:144
Player::get_symbol
T get_symbol() const
Get the player's symbol.
Definition BoardGame_Classes.h:150
SUSUI::SUSUI
SUSUI()
Definition SUSUI.h:11
SUSUI::create_player
Player< char > * create_player(string &name, char symbol, PlayerType type) override
Create a player object based on input name, symbol, and type.
Definition SUSUI.h:37
SUSUI::get_move
Move< char > * get_move(Player< char > *p) override
Ask the user (or AI) to make a move.
Definition SUSUI.h:12
SUSUI::display_message
void display_message(string s)
Definition SUSUI.h:43
UI< char >::UI
UI(string message, int cell_display_width)
Definition BoardGame_Classes.h:196