-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayVisitor.cpp
34 lines (27 loc) · 950 Bytes
/
DisplayVisitor.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
#include "DisplayVisitor.h"
#include "TreeBuilder.h"
#include <iostream>
static int countChildren(GameState* apGameState)
{
int children = 0;
std::vector<GameState*>& states = apGameState->getNextStates();
std::vector<GameState*>::iterator it;
for (it = states.begin(); it != states.end(); ++it) {
children++;
}
return children;
}
void DisplayVisitor::visit(GameState* apGameState)
{
int score = apGameState->getScore();
int level = apGameState->getLevel();
int children = countChildren(apGameState);
std::cout << "GameState level:" << level << " children:" << children << " score:" << score << std::endl;
std::vector<GameState*>& states = apGameState->getNextStates();
std::vector<GameState*>::iterator it;
for (it = states.begin(); it != states.end(); ++it) {
GameState* pGameState = *it;
if (pGameState != 0)
visit(pGameState);
}
}