-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (98 loc) · 3.05 KB
/
main.cpp
File metadata and controls
117 lines (98 loc) · 3.05 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// main.cpp
// connectFour
//
// Created by Matthew Green on 2/12/18.
// Copyright (c) 2018 Matthew Green. All rights reserved.
//
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "board.h"
#include "c4AI.h"
using namespace std;
#define RANDMOVES 3
int main(int argc, const char * argv[]) {
board *myBoard = new board();
c4AI *ai = new c4AI(blue, 3);
int retVal = 0, input = -1, aiPlacement = 0, redWins = 0, blueWins = 0, numMoves = 0, ffTries = 0;
vector<char> colWin;
vector<int> moves;
srand(time(NULL));
myBoard->printBoardState();
bool redFF = false, blueFF = false;
while(1)
{
//cout << "Choose col To place piece" << endl;
input = -1;
retVal = -1;
while(input == -1 || retVal == -1)
{
cin >> input;
input = input - 1;
retVal = myBoard->placePieceOnCol(input, red);
}
ai->curState.placePieceOnCol(input, red);
myBoard->printBoardState();
//see if red won
if(retVal == 10)
{
cout << "Red wins" << endl;
redWins++;
moves.push_back(numMoves);
colWin.push_back('r');
break;
}
else if(retVal == -1)
{
redFF = true;
ffTries++;
}
cout << "Blue AI is thinking" << endl;
aiPlacement = ai->chooseCol();
retVal = myBoard->placePieceOnCol(aiPlacement, blue);
ai->curState.placePieceOnCol(aiPlacement, blue);
cout << "AI placed on column: " << aiPlacement + 1 << endl;
myBoard->printBoardState();
numMoves++;
//see if blue won
if(retVal == 10)
{
cout << "Blue wins" << endl;
blueWins++;
moves.push_back(numMoves);
colWin.push_back('b');
break;
}
else if(retVal == -1)
{
blueFF = true;
ffTries++;
}
}
cout << "*******STATS*******" << endl;
int totalMoves = 0;
for(int j = 0; j < moves.size(); j++)
{
cout << "Game " << j << ": ";
if(colWin[j] == 'b')
{
cout << "Blue won in " << moves[j] << " moves" << endl;
}
else if(colWin[j] == 'r')
{
cout << "Red won in " << moves[j] << " moves" << endl;
}
else
{
cout << "Draw in " << moves[j] << " moves" << endl;
}
totalMoves += moves[j];
}
cout << "Blue Wins:\t" << blueWins << endl;
cout << "Red Wins:\t" << redWins << endl;
cout << "Total Moves:\t" << totalMoves << endl;
cout << "Average Moves:\t" << (double)totalMoves / (double)moves.size() << endl;
return 0;
}