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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/*
* AI game (sub)tree class
* Header file
*
* $Id$
*/
#ifndef GAMETREE_H
#define GAMETREE_H
#include <list.h> // MUST be prog/lib/ version!
#include "atom4.h"
struct move_t {
int x, y;
inline int operator== (move_t m) { return x==m.x && y==m.y; }
};
class gamenode; // forward decl
class gameedge {
move_t m; // move associated with this edge
gamenode *dest; // [O] NULL if not cached
public:
gameedge(move_t move) : m(move), dest(NULL) {}
~gameedge() { if (dest) delete dest; }
inline int operator== (move_t move) { return m==move; }
inline gamenode *operator*() { return dest; } // [R]()
inline move_t label() { return m; }
};
// Game node value heuristic function accumulator
// - changes = number of color changes caused by move
// - pcreated = number of propagators (ours) created
// - pdestroyed = number of propagators (enemy's) destroyed
// - cluster = cluster factor for propagators we created
// - uncluster = cluster factor for propagators we destroyed
struct hdelta {
int changes, pcreated, pdestroyed;
int cluster, uncluster; // cluster factors
inline hdelta operator-() {
hdelta neg = { -changes, -pdestroyed, -pcreated, -uncluster, -cluster };
}
};
class gamenode {
elist<gameedge> children;
elist<boardchange> splash, unsplash;
int win:1; // 1 if winning state, else 0
hdelta heu; // heuristic function accumulator
public:
gamenode();
~gamenode();
};
class gametree {
gamenode *root; // [O]
public:
gametree();
~gametree();
};
#endif //GAMETREE_H
|