Skip to content

Commit

Permalink
Factor the stats out into a separate file, display some better stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Ewalds committed Feb 28, 2010
1 parent 9c6bd75 commit 0aa0c76
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
42 changes: 42 additions & 0 deletions depthstats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

#ifndef _DEPTHSTATS_H_
#define _DEPTHSTATS_H_

#include <stdint.h>
#include <cmath>
#include <string>
#include "string.h"
using namespace std;

struct DepthStats {
uint32_t mindepth, maxdepth, num;
uint64_t sumdepth, sumdepthsq;

DepthStats(){
num = 0;
mindepth = 1000000000;
maxdepth = 0;
sumdepth = 0;
sumdepthsq = 0;
}
void add(int depth){
num++;
if(mindepth > depth) mindepth = depth;
if(maxdepth < depth) maxdepth = depth;
sumdepth += depth;
sumdepthsq += depth*depth;
}

int avg(){
return sumdepth/num;
}
double std_dev(){
return sqrt((double)sumdepthsq/num - ((double)sumdepth/num)*((double)sumdepth/num));
}
string to_s(){
return "avg=" + to_str(avg()) +", std-dev=" + to_str(std_dev()) + ", min=" + to_str(mindepth) + ", max=" + to_str(maxdepth) + ", num=" + to_str(num);
}
};

#endif

15 changes: 2 additions & 13 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "board.h"
#include "time.h"
#include "timer.h"
#include "depthstats.h"
#include <stdint.h>
#include <cmath>

Expand Down Expand Up @@ -60,7 +61,7 @@ class Player {

public:
int runs;
uint64_t mindepth, maxdepth, sumdepth, sumdepthsq;
DepthStats treelen, gamelen;
int conflicts;
uint64_t nodes;
Move bestmove;
Expand All @@ -71,11 +72,6 @@ class Player {
Player() {
runs = 0;

mindepth = 10000;
maxdepth = 0;
sumdepth = 0;
sumdepthsq = 0;

conflicts = 0;
nodes = 0;
bestmove = Move(-2,-2);
Expand All @@ -95,13 +91,6 @@ class Player {
protected:
int walk_tree(Board & board, Node * node, vector<Move> & movelist, int depth);
int rand_game(Board & board, vector<Move> & movelist, int depth);

void update_depths(int depth){
if(mindepth > depth) mindepth = depth;
if(maxdepth < depth) maxdepth = depth;
sumdepth += depth;
sumdepthsq += depth*depth;
}
};

#endif
Expand Down
16 changes: 10 additions & 6 deletions playeruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ void Player::play_uct(const Board & board, double time, uint64_t memlimit){

bestmove = root.children[maxi].move;

string stats = "Finished " + to_str(runs) + " runs in " + to_str(time_msec() - starttime) + " msec\n";
stats += "Rollout depths: min " + to_str(mindepth) + ", max: " + to_str(maxdepth) + ", avg: " + to_str(sumdepth/runs);
stats += ", std dev: " + to_str(sqrt((double)sumdepthsq/runs - ((double)sumdepth/runs)*((double)sumdepth/runs))) + "\n";
int runtime = time_msec() - starttime;

string stats = "Finished " + to_str(runs) + " runs in " + to_str(runtime) + " msec\n";
stats += "Game length: " + gamelen.to_s() + "\n";
stats += "Tree depth: " + treelen.to_s() + "\n";
stats += "Move Score: " + to_str(root.children[maxi].winrate()/2) + "\n";
fprintf(stderr, "%s", stats.c_str());

time_used = (double)(time_msec() - starttime)/1000;
time_used = (double)runtime/1000;
}

int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int depth){
Expand Down Expand Up @@ -90,9 +93,10 @@ int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int d
}
}else if((won = board.won()) >= 0){
//already done
update_depths(depth);
treelen.add(depth);
}else if(node->visits <= minvisitschildren || nodesremain <= 0){
//do random game on this node
treelen.add(depth);
won = rand_game(board, movelist, depth);

if(ravefactor > 0){
Expand Down Expand Up @@ -154,7 +158,7 @@ int Player::rand_game(Board & board, vector<Move> & movelist, int depth){
depth++;
}

update_depths(depth);
gamelen.add(depth);

return won;
}
Expand Down

0 comments on commit 0aa0c76

Please sign in to comment.