Skip to content

Commit

Permalink
Add an option to make the rave scores scale from 2 down to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Timo Ewalds committed Mar 5, 2010
1 parent 158f1c9 commit 7149ea6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 30 deletions.
55 changes: 53 additions & 2 deletions player.h
Expand Up @@ -86,10 +86,60 @@ class Player {
}
};

struct RaveMoveList {
vector<MoveScore> list;

RaveMoveList(int s = 0){
list.reserve(s);
}

void add(const Move & move){
list.push_back(move);
}
void clear(){
list.clear();
}
int size() const {
return list.size();
}
const MoveScore & operator[](int i) const {
return list[i];
}
//remove the moves that were played by the loser
//sort in y,x order
void clean(bool first, bool scale){
unsigned int i = 0, j = 1;
float base, factor;

if(!first){
i++;
j++;
}
if(scale){
base = 2;
factor = 4.0/list.size();
}else{
base = 1;
factor = 0;
}

while(j < list.size()){
list[i] = list[j];
list[i].score = base - i*scale;
i++;
j += 2;
}

list.resize(i);
sort(list.begin(), list.end());
}
};

public:

float explore; //greater than one favours exploration, smaller than one favours exploitation
float ravefactor; //big numbers favour rave scores, small ignore it
bool ravescale; //scale rave numbers from 2 down to 0 in decreasing order of move recency instead of always 1
float prooftime; //fraction of time spent in proof number search, looking for a provable win and losses to avoid
int proofscore; //how many virtual rollouts to assign based on the proof number search values
bool rolloutpattern; //play the response to a virtual connection threat in rollouts
Expand All @@ -110,6 +160,7 @@ class Player {

explore = 1;
ravefactor = 10;
ravescale = true;
prooftime = 0.2;
proofscore = 2;
rolloutpattern = true;
Expand All @@ -122,8 +173,8 @@ class Player {
void play_uct(const Board & board, double time, int memlimit);

protected:
int walk_tree(Board & board, Node * node, vector<Move> & movelist, int depth);
int rand_game(Board & board, vector<Move> & movelist, Move move, int depth);
int walk_tree(Board & board, Node * node, RaveMoveList & movelist, int depth);
int rand_game(Board & board, RaveMoveList & movelist, Move move, int depth);
bool check_pattern(const Board & board, Move & move);
};

Expand Down
37 changes: 9 additions & 28 deletions playeruct.cpp
Expand Up @@ -46,8 +46,7 @@ void Player::play_uct(const Board & board, double time, int memlimit){
solver.reset();
}

vector<Move> movelist;
movelist.reserve(board.movesremain());
RaveMoveList movelist(board.movesremain());
while(!timeout){
runs++;
Board copy = board;
Expand Down Expand Up @@ -77,7 +76,7 @@ void Player::play_uct(const Board & board, double time, int memlimit){
time_used = (double)runtime/1000;
}

int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int depth){
int Player::walk_tree(Board & board, Node * node, RaveMoveList & movelist, int depth){
int result, won = -1;

node->visits++;
Expand Down Expand Up @@ -110,7 +109,7 @@ int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int d
//recurse on the chosen child
Node * child = & node->children[maxi];
board.move(child->move);
movelist.push_back(child->move);
movelist.add(child->move);
result = - walk_tree(board, child, movelist, depth+1);

//update the rave scores
Expand All @@ -119,7 +118,7 @@ int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int d
unsigned int m = 0, c = 0;
while(m < movelist.size() && c < node->numchildren){
if(movelist[m] == node->children[c].move){
node->children[c].rave += 1;
node->children[c].rave += movelist[m].score;
m++;
}
c++;
Expand All @@ -135,28 +134,10 @@ int Player::walk_tree(Board & board, Node * node, vector<Move> & movelist, int d
won = rand_game(board, movelist, node->move, depth);

if(ravefactor > 0){
//remove the moves that were played by the loser
//sort in y,x order

if(won == 0){
if(won == 0)
movelist.clear();
}else{
unsigned int i = 0, j = 1;

if((won == board.toplay()) == (depth % 2 == 0)){
i++;
j++;
}

while(j < movelist.size()){
movelist[i] = movelist[j];
i++;
j += 2;
}

movelist.resize(i);
sort(movelist.begin(), movelist.end());
}
else
movelist.clean(((won == board.toplay()) == (depth % 2 == 0)), ravescale);
}
}else{
//create children
Expand Down Expand Up @@ -251,7 +232,7 @@ bool Player::check_pattern(const Board & board, Move & move){
}

//play a random game starting from a board state, and return the results of who won
int Player::rand_game(Board & board, vector<Move> & movelist, Move move, int depth){
int Player::rand_game(Board & board, RaveMoveList & movelist, Move move, int depth){
int won;

while((won = board.won()) < 0){
Expand All @@ -263,7 +244,7 @@ int Player::rand_game(Board & board, vector<Move> & movelist, Move move, int dep
}

board.move(move);
movelist.push_back(move);
movelist.add(move);
depth++;
}

Expand Down

0 comments on commit 7149ea6

Please sign in to comment.