-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
75 lines (66 loc) · 2.15 KB
/
player.cpp
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
////////////////////////////////////////////////////////////////////////////////
// Player Classes //
// player clases data and actions //
////////////////////////////////////////////////////////////////////////////////
#include "player.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
//PlayerHuman Constructor
PlayerHuman::PlayerHuman() {
cout << "Player Human" << endl;
}
//PlayerHuman Constructor with args (Overloading)
//string name - provided human name
//int humanPiece - Piece pattern that represents a human instance
PlayerHuman::PlayerHuman(string pName, int humanPiece) {
cout << pName << endl;
name = pName;
piecePattern = humanPiece;
cout << "Player Human " << name << endl;
}
//PlayerHuman play method
//Humans have to think their own move and provide it
//This methods overrides the pure virtual method from Player (Polimorfism)
int PlayerHuman::Play() {
int col = 0;
string scol;
cout << "Human " << GetName() << " plays..." << endl;
do {
cout << "Enter Column number [1 - 7]: ";
cin >> scol;
col = atoi(scol.c_str());
} while (col < 1 || col > 7);
return col - 1;
}
//Bot Constructor
PlayerBot::PlayerBot() {
cout << "Player Bot" << endl;
}
//bot constructor
// string name - Bot name
// int botPiece - Piece pattern that represents a bot instance
PlayerBot::PlayerBot(string pName, int botPiece) {
name = pName;
piecePattern = botPiece;
cout << "Player Bot " << name << endl;
lastCol = -1;
}
//Bot play algorithm
//Please make me smarter!!!
//This methods overrides the pure virtual method from Player (Polimorfism)
int PlayerBot::Play() {
cout << "Bot " << GetName() << " plays..." << endl;
cout << "I still don't have AI, I play very bad..." << endl;
int col = 0;
if (lastCol == -1) {
//before doing this we might analyse whether we should play defensive or offensive
col = rand() % 6;
return col;
}
else {
//Here we should try to connect the bot pieces
}
return 0;
}