rusthashmapminimaxbtreemap

btreemap vs hashmap for transposition table


I have created a minimax algorithm that uses alpha beta pruning and a transposition table to speed up the search. I am currently using a hashmap that uses the board state as the key and saves the score as the value. (the game is tic tac toe on a 5x5 board)

The issue with this is hashing is slow and using the entire board state as the key eats up a lot of memory. Board state is represented by a 2d array of enums with 3 possible types: Blank, X, and O. I would like to use my own hash (probably zobrist) as the key and not save the board state at all, but a hashmap would take my key and hash it again. I have considered using the btree map which treats a key as unique, but the access time is log(n) instead of O(1). I also don't care at all about the order of the keys so a btree doesn't really seem to fit here.

so my question is, which data structure would be ideal here? should I use a hashmap even though it hashes my keys a second time?


Solution

  • I've been doing something similar, and here's what I ended up with, adapted to your case:

    All of this is to be taken with a grain of salt. In my case, it helped to speed up the search, but you'll have to test your case separately.