Skip to content

Commit

Permalink
more than one game per simulation tested, deleted obsolet StateList,
Browse files Browse the repository at this point in the history
overall output of data on the console
  • Loading branch information
OEtzi007 authored and OEtzi007 committed Mar 4, 2014
1 parent 64cfa53 commit 3739c77
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 128 deletions.
3 changes: 3 additions & 0 deletions game/header/Counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class Counter {
int add(AI* player, int counter);
int get(AI* player) const;

Counter operator+(const Counter& rhs) const;
Counter operator-(const Counter& rhs) const;
Counter operator=(const Counter& copy);
Counter operator+=(const Counter& rhs);
Counter operator-=(const Counter& rhs);
};

#endif /* COUNTER_H_ */
26 changes: 0 additions & 26 deletions game/header/StateList.h

This file was deleted.

30 changes: 23 additions & 7 deletions game/source/Counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Counter::Counter() {
counter[i] = 0;
}

Counter::Counter(const Counter& copy){
Counter::Counter(const Counter& copy) {
counter = new int[MAX_PLAYER];
for (int i = 0; i < MAX_PLAYER; i++)
counter[i] = copy.counter[i];
Expand All @@ -32,16 +32,32 @@ int Counter::get(AI* player) const {
return counter[player->spielerfarbe];
}

Counter Counter::operator+(const Counter& rhs) const {
Counter retValue;
for (int i = 0; i < MAX_PLAYER; i++)
retValue.counter[i] = counter[i] + rhs.counter[i];
return retValue;
}

Counter Counter::operator-(const Counter& rhs) const{
Counter Counter::operator-(const Counter& rhs) const {
Counter retValue;
for(int i=0;i<MAX_PLAYER;i++)
retValue.counter[i]=counter[i]-rhs.counter[i];
for (int i = 0; i < MAX_PLAYER; i++)
retValue.counter[i] = counter[i] - rhs.counter[i];
return retValue;
}

Counter Counter::operator=(const Counter& copy){
for(int i=0;i<MAX_PLAYER;i++)
counter[i]=copy.counter[i];
Counter Counter::operator=(const Counter& copy) {
for (int i = 0; i < MAX_PLAYER; i++)
counter[i] = copy.counter[i];
return *this;
}

Counter Counter::operator+=(const Counter& rhs) {
*this = *this + rhs;
return *this;
}

Counter Counter::operator-=(const Counter& rhs) {
*this = *this - rhs;
return *this;
}
16 changes: 15 additions & 1 deletion game/source/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,23 @@ void Game::play() {
<< " has "
<< gameLogger->points.get(gameLogger->playerList[i])
<< " points!" << std::endl;
std::cout << std::endl;
++playerIterator;
}

//TODO punktevergabe
int maxpoints = 0;
int numberWinners = 0;
for (int i = 0; i < (int) gameLogger->playerList.size(); i++)
if (maxpoints < gameLogger->points.get(gameLogger->playerList[i]))
maxpoints = gameLogger->points.get(gameLogger->playerList[i]);
for (int i = 0; i < (int) gameLogger->playerList.size(); i++)
if (maxpoints == gameLogger->points.get(gameLogger->playerList[i]))
numberWinners++;
for (int i = 0; i < (int) gameLogger->playerList.size(); i++)
if (maxpoints == gameLogger->points.get(gameLogger->playerList[i]))
gameLogger->winnerPoints.add(gameLogger->playerList[i],
6 / numberWinners);
//TODO end
played = true;
}

Expand Down
1 change: 0 additions & 1 deletion game/source/Round.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ void Round::play() {
currentMove->execute(currentState);
roundLogger->moveList.push_back(currentMove);
}
currentState.aktAusgabe();
++currentPlayer;
}
PlayingOrder::iterator playerIterator = roundLogger->playingOrder.begin(
Expand Down
26 changes: 19 additions & 7 deletions game/source/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@
#include "../header/Simulation.h"

Simulation::Simulation(SimulationLogger* simulationLogger) :
simulationLogger(simulationLogger), ran(false) {}
simulationLogger(simulationLogger), ran(false) {
}

Simulation::~Simulation() {}
Simulation::~Simulation() {
}

void Simulation::run() {
assert(!ran);
for (int i = 0; i < (int) simulationLogger->gameList.size(); i++) {
std::vector<AI*> order=simulationLogger->getPlayingOrder(i);
std::vector<AI*> order = simulationLogger->getPlayingOrder(i);
PlayingOrder playingOrder(order);
GameLogger* currentGameLogger=new GameLogger(simulationLogger->playerList,
simulationLogger->board, playingOrder, order[0]);
GameLogger* currentGameLogger = new GameLogger(
simulationLogger->playerList, simulationLogger->board,
playingOrder, order[0]);
Game currentGame(currentGameLogger);
currentGame.play();
simulationLogger->gameList[i]=currentGameLogger;
simulationLogger->gamesWon += currentGameLogger->winnerPoints;
simulationLogger->gameList[i] = currentGameLogger;
}
ran=true;
//TODO ausgabe punkte
for (int i = 0; i < (int) simulationLogger->playerList.size(); i++)
std::cout << "Player " << simulationLogger->playerList[i]->spielerfarbe
<< " has won "
<< simulationLogger->gamesWon.get(
simulationLogger->playerList[i]) / (double) 6.
<< " game(s)." << std::endl;
//TODO end
ran = true;
}
50 changes: 0 additions & 50 deletions game/source/StateList.cpp

This file was deleted.

1 change: 1 addition & 0 deletions logger/header/GameLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class GameLogger {
int deadLine; /** < if points equal or lower deadLine, you lose*/

Counter points;
Counter winnerPoints;

std::vector<RoundLogger*> roundList;
};
Expand Down
13 changes: 1 addition & 12 deletions userinterface/source/spielbrett.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,8 @@ void Spielbrett::paintEvent(QPaintEvent*) {
void Spielbrett::zustandChanged(int counter) {
update();
}

void Spielbrett::drawCityChanged(bool enable) {
drawCity = enable;
update();
}
/*
QSize gameBoard::minimumSizeHint() const
{
return QSize(100,100);
}
QSize gameBoard::sizeHint() const
{
return QSize(1000,750);
}
*/
20 changes: 1 addition & 19 deletions userinterface/source/uiexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,16 @@ void UIEXEC::doTheMagic() {
window implementation
*/
board = new Board;
board->Ausgabe();
std::vector<AI*> players;
players.push_back(new testKI(P_YELLOW));
players.push_back(new testKI(P_BLUE));
players.push_back(new testKI(P_ORANGE));

SimulationLogger* simulationLogger = new SimulationLogger(players, *board, 1);
SimulationLogger* simulationLogger = new SimulationLogger(players, *board, 100);
Simulation simulation(simulationLogger);
simulation.run();

wp = new Window(simulationLogger);
wp->setWindowTitle(QObject::tr("Transamerica - Testversion - GITHUB"));
wp->show();

//wp->playAutomatically();
// sound = new QSound("sounds/train-whistle-01.wav");
// assert(sound->isAvailable());
// sound->play();

/**
call of the game algorithmus
*/

/**
connect this shit
*/
// TODO some connects
//connect(wp, SIGNAL(requestZp(int)), &(game1->stateList), SLOT(callGet(int)) );
//connect(&(game1->stateList), SIGNAL(emitGet(Zustand*)), wp, SLOT(setZp(Zustand*)));

}
5 changes: 0 additions & 5 deletions userinterface/source/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Window::Window(SimulationLogger *game) :
Slot-Implementationen
*/
void Window::setZp(State *aktuellerZustand) {
cout << "Aufruf von setZp" << endl;
aZp = aktuellerZustand;
spielbrett->update();
}
Expand Down Expand Up @@ -144,7 +143,3 @@ void Window::setsimulationp(SimulationLogger *game) {
moveSpinBox->setRange(0,
simulationp->gameList[gameCounter]->roundList[roundCounter]->moveList.size());
}

//void Window::playAutomatically(){
// for (int i=0; i<=100; i++) QTimer::singleShot(10, this , SLOT(setZustandcounter(int i)));
//}

0 comments on commit 3739c77

Please sign in to comment.