diff options
author | Guido MartÃnez <mtzguido@gmail.com> | 2014-03-31 01:20:48 (GMT) |
---|---|---|
committer | Guido MartÃnez <mtzguido@gmail.com> | 2014-03-31 01:20:48 (GMT) |
commit | d6da06f656fc1574b12ef72377476056e3e673a0 (patch) | |
tree | c6c2f9e6d2ebd037d4c68a622c5240d630414de2 /ztable.c | |
parent | edc37102fbe0236f2039cae9ebc739a4a134b3fd (diff) | |
download | ice-d6da06f656fc1574b12ef72377476056e3e673a0.zip ice-d6da06f656fc1574b12ef72377476056e3e673a0.tar.gz ice-d6da06f656fc1574b12ef72377476056e3e673a0.tar.bz2 |
Threefold rule y muchas optimizaciones
Diffstat (limited to 'ztable.c')
-rw-r--r-- | ztable.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/ztable.c b/ztable.c new file mode 100644 index 0000000..315e3ae --- /dev/null +++ b/ztable.c @@ -0,0 +1,74 @@ +#include "ztable.h" +#include <stdlib.h> +#include <assert.h> + +int n_collision = 0; + +struct bucket * ztable[CFG_ZTABLE_SIZE]; + +void mark(game g) { + int idx = g->zobrist % CFG_ZTABLE_SIZE; + + struct bucket *p = ztable[idx]; + + while (p && !equalGame(g, p->g)) { + n_collision++; + p = p->next; + } + + if (p) { + p->n++; + } else { + p = malloc(sizeof *p); + p->g = copyGame(g); + p->n = 1; + p->next = ztable[idx]; + ztable[idx] = p; + } +} + +void unmark(game g) { + int idx = g->zobrist % CFG_ZTABLE_SIZE; + + struct bucket *p = ztable[idx]; + + assert(p); + if (equalGame(p->g, g)) { + p->n--; + + if (p->n == 0) { + struct bucket *t = p->next; + freeGame(p->g); + free(p); + ztable[idx] = t; + } + } else { + while (p->next && !equalGame(g, p->next->g)) + p = p->next; + + assert(p->next); + + p->next->n--; + if (p->next->n == 0) { + struct bucket *t = p->next->next; + freeGame(p->next->g); + free(p->next); + p->next = t; + } + } +} + +int reps(game g) { + int idx = g->zobrist % CFG_ZTABLE_SIZE; + + struct bucket *p = ztable[idx]; + + while (p && !equalGame(g, p->g)) + p = p->next; + + if (p) + return p->n; + else + return 0; +} + |