Page 1 of 1

Material Hash table vs Material Table ?

Posted: Fri May 25, 2018 1:24 pm
by MahmoudUthman
is it better to use a (9∗3∗3∗3∗2)2=4862=236,196 Material table or a normal material hash table ?

Re: Material Hash table vs Material Table ?

Posted: Sat May 26, 2018 6:51 am
by Dann Corbit
Gull uses this formula for sizing:
  • #define MatWQ 1
    #define MatBQ 3
    #define MatWR (3 * 3)
    #define MatBR (3 * 3 * 3)
    #define MatWL (3 * 3 * 3 * 3)
    #define MatBL (3 * 3 * 3 * 3 * 2)
    #define MatWD (3 * 3 * 3 * 3 * 2 * 2)
    #define MatBD (3 * 3 * 3 * 3 * 2 * 2 * 2)
    #define MatWN (3 * 3 * 3 * 3 * 2 * 2 * 2 * 2)
    #define MatBN (3 * 3 * 3 * 3 * 2 * 2 * 2 * 2 * 3)
    #define MatWP (3 * 3 * 3 * 3 * 2 * 2 * 2 * 2 * 3 * 3)
    #define MatBP (3 * 3 * 3 * 3 * 2 * 2 * 2 * 2 * 3 * 3 * 9)
    #define TotalMat ((2*(MatWQ+MatBQ)+MatWL+MatBL+MatWD+MatBD+2*(MatWR+MatBR+MatWN+MatBN)+8*(MatWP+MatBP)) + 1)
    and a flag for unusual material.

    int get_mat_index(int wq, int bq, int wr, int br, int wl, int bl, int wd, int bd, int wn, int bn, int wp, int bp) {
    if (wq > 2 || bq > 2 || wr > 2 || br > 2 || wl > 1 || bl > 1 || wd > 1 || bd > 1 || wn > 2 || bn > 2 || wp > 8 || bp > 8) return -1;
    return wp*MatWP + bp*MatBP + wn*MatWN + bn*MatBN + wl*MatWL + bl*MatBL + wd*MatWD + bd*MatBD + wr*MatWR + br*MatBR + wq*MatWQ + bq*MatBQ;
    }

    int conj_mat_index(int index, int * conj_symm, int * conj_ld, int * conj_ld_symm) {
    int wq = index % 3; index /= 3;
    int bq = index % 3; index /= 3;
    int wr = index % 3; index /= 3;
    int br = index % 3; index /= 3;
    int wl = index % 2; index /= 2;
    int bl = index % 2; index /= 2;
    int wd = index % 2; index /= 2;
    int bd = index % 2; index /= 2;
    int wn = index % 3; index /= 3;
    int bn = index % 3; index /= 3;
    int wp = index % 9; index /= 9;
    int bp = index;
    *conj_symm = -1;
    *conj_ld = -1;
    *conj_ld_symm = -1;
    if (wq != bq || wr != br || wl != bd || wd != bl || wn != bn || wp != bp) {
    *conj_symm = get_mat_index(bq, wq, br, wr, bd, wd, bl, wl, bn, wn, bp, wp);
    if (wl != wd || bl != bd) {
    *conj_ld = get_mat_index(wq, bq, wr, br, wd, bd, wl, bl, wn, bn, wp, bp);
    *conj_ld_symm = get_mat_index(bq, wq, br, wr, bl, wl, bd, wd, bn, wn, bp, wp);
    }
    }
    return *conj_symm;
    }
For the material imbalance table, there are some programs that calculate it from first principles, there are some programs that use statistics generated from data, and there are some programs that do not even use a material imbalance table.

As you can see, gull uses a static table that is not a hash table.

Stockfish, on the other hand, uses a material imbalance hash table. See the file material.cpp

Both approaches obviously work very well.

Re: Material Hash table vs Material Table ?

Posted: Sun May 27, 2018 10:25 am
by hgm
It should not matter much (unless you have an unusually large number of piece types, in which case the table would become unwieldly large). The hit rate on even a modestly sized material hash table should be > 99%, so that the effort for calculating the material bonus on the fly when you have a miss has negligible impact on speed.

Re: Material Hash table vs Material Table ?

Posted: Thu Jan 03, 2019 3:01 pm
by xr_a_y
May I ask what the conj_mat_index function is used for ?