-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·148 lines (137 loc) · 5.59 KB
/
main.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
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
#include <iostream>
#include "includes/OthelloBitBoard.h"
#include "includes/OthelloGame.h"
#include "includes/MoveSet.h"
#include "includes/Player.h"
#include "includes/Agent.h"
#include "includes/GameTree.h"
#include "includes/MonteCarloAgent.h"
//#include "includes/Utils.h"
int main() {
//TODO agent segfaults when human error is made.
// Wouldn't be a big deal with agent vs agent, but when human plays, it should handle it.
//make player first, then the agent. agent won't know its color the other way around.
auto *moves = new MoveSet();
auto *board = new OthelloBitBoard();
auto *gametree = new GameTree(board,moves);
// auto *mcAgent = new MonteCarloAgent(gametree);
//gameplay
auto *game = new OthelloGame(board);
auto *player = new Player(game);
auto *player2 = new Player(game);
auto *agent = new Agent(game,gametree);
do{
if (game->nextMove()){
agent->decide();
}
if (game->nextMove()){
player->makeMove();
}
// if (game->nextMove()){
// player2->makeMove();
// }
}while(game->nextMove());
agent->printTreeToTxt(gametree->getRoot());
agent->printAverageTimeToFile();
//end of gameplay
//testing for monteCarlo agent
// GameTreeNode *testNode = gametree->getRoot();
// mcAgent->simulate(testNode);
// mcAgent->findWinValue();
// mcAgent->backPropagate(testNode,BLACK);
// testNode = testNode->getChild();
// int wi = testNode->getParent()->getWi();
// int ni = testNode->getParent()->getNi();
// cout<<"C wi/ni for "<<testNode->getLocation().getCol()<<testNode->getLocation().getRow()<<": "<<wi<<"/"<<ni<<endl;
// do {
// testNode = testNode->getSibling();
// mcAgent->simulate(testNode);
// mcAgent->findWinValue();
// mcAgent->backPropagate(testNode,BLACK);
// wi = testNode->getWi();
// ni = testNode->getNi();
// cout<<"C wi/ni for "<<testNode->getLocation().getCol()<<testNode->getLocation().getRow()<<": "<<wi<<"/"<<ni<<endl;
// } while (testNode->getSibling()!= nullptr);
// wi = gametree->getRoot()->getWi();
// ni = gametree->getRoot()->getNi();
// cout<<"C wi/ni for root: "<<wi<<"/"<<ni<<endl;
// if (wi>=ni/2){
// cout<<"C simulations favoring agent so far."<<endl;
// }else{
// cout<<"C simulations favoring opponent so far."<<endl;
// }
// testing for scanning a node
// gametree->scanNode(gametree->getRoot());
// gametree->scanNode(gametree->getRoot()->getChild()->getSibling()->getSibling());
// gametree->scanNode(gametree->getRoot()->getChild()->getSibling()->getSibling()->getChild());
// gametree->printTree(gametree->getRoot(),0);
// testing for adding children/siblings
// auto *gtnode = new GameTreeNode(board);
//
// gtnode->setChild(new GameTreeNode(new OthelloBitBoard(board)),
// gtnode,
// moves->getMove(63-Utils::convertToGrid('d',3)));
//
// gtnode->getChild()->setSibling(new GameTreeNode(new OthelloBitBoard(gtnode->getCurrentBoard())),
// gtnode->getChild(),
// moves->getMove(63-Utils::convertToGrid('c',4)));
//
// gtnode->getCurrentBoard()->printBoard();
// gtnode->getChild()->getCurrentBoard()->printBoard();
// gtnode->getChild()->getSibling()->getCurrentBoard()->printBoard();
// testing for bitboard
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'e', 6, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'f', 4, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'f', 3, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'f', 2, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'g', 4, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'f', 5, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'e', 2, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'd', 3, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'e', 3, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'h', 4, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'f', 1, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'c', 5, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'g', 5, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'g', 1, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'h', 1, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
// board->playPiece(WHITE, 'g', 2, false);
// board->findLegals(BLACK);
// board->printBoardWithLegalMoves();
// board->playPiece(BLACK, 'h', 2, false);
// board->findLegals(WHITE);
// board->printBoardWithLegalMoves();
return 0;
}