|
Revision 1, 1.9 kB
(checked in by pantley2, 4 years ago)
|
GGPA code from the good old days of SIGART
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
#include "GameWorld.h" |
|---|
| 11 |
#include "TestTools.h" |
|---|
| 12 |
#include "QLearner.h" |
|---|
| 13 |
#include <fstream> |
|---|
| 14 |
#include <sstream> |
|---|
| 15 |
#include <stdlib.h> |
|---|
| 16 |
#include "string.h" |
|---|
| 17 |
using namespace std; |
|---|
| 18 |
|
|---|
| 19 |
int main(){ |
|---|
| 20 |
cout << "Test tic tac toes rules ..." << endl; |
|---|
| 21 |
|
|---|
| 22 |
string matchID = "123"; |
|---|
| 23 |
string role = "xplayer"; |
|---|
| 24 |
double startClock = 30; |
|---|
| 25 |
double playClock = 30; |
|---|
| 26 |
string request; |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
string ruleFile = "TicTacToe.rul"; |
|---|
| 30 |
|
|---|
| 31 |
ifstream ruleStream(ruleFile.c_str()); |
|---|
| 32 |
if (!ruleStream.is_open()) { |
|---|
| 33 |
cerr << "Could not open file " << ruleFile << endl; |
|---|
| 34 |
exit(1); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
string rules = ""; |
|---|
| 39 |
string line; |
|---|
| 40 |
while (!getline(ruleStream, line).eof()) { |
|---|
| 41 |
|
|---|
| 42 |
rules = rules +" " + line; |
|---|
| 43 |
|
|---|
| 44 |
} |
|---|
| 45 |
rules = rules + " "+line; |
|---|
| 46 |
|
|---|
| 47 |
ruleStream.close(); |
|---|
| 48 |
|
|---|
| 49 |
ostringstream stream1; |
|---|
| 50 |
|
|---|
| 51 |
stream1 << "(START " << matchID << " " << role << " (" << rules |
|---|
| 52 |
<< ") " << startClock |
|---|
| 53 |
<< " " << playClock << ")"; |
|---|
| 54 |
|
|---|
| 55 |
request = stream1.str(); |
|---|
| 56 |
GameWorld world(request); |
|---|
| 57 |
world.output(); |
|---|
| 58 |
GameWorld* pointer =&world; |
|---|
| 59 |
QLearner learnPlease(pointer); |
|---|
| 60 |
|
|---|
| 61 |
cout << endl << "Updating" << endl; |
|---|
| 62 |
vector<string> roles = world.getRoles(); |
|---|
| 63 |
vector<Action*> actions(roles.size()); |
|---|
| 64 |
|
|---|
| 65 |
for (unsigned int roleIndex = 0; roleIndex < roles.size(); roleIndex++) { |
|---|
| 66 |
vector<Action*> legalMoves = world.getLegalMoves(roles[roleIndex]); |
|---|
| 67 |
cout << roles[roleIndex] << endl; |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
learnPlease.learn(30); |
|---|
| 75 |
cout<<"finish"<<endl; |
|---|
| 76 |
return 0; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|