sugyan / yasai

Yet Another Shogi library, for AI development
GNU General Public License v3.0
25 stars 4 forks source link

`ZobristTable::hands` is too small #20

Closed koba-e964 closed 2 years ago

koba-e964 commented 2 years ago

MAX_HAND_NUM is 18. For a position where someone has all 18 pawns in hand, this line probably causes out-of-bounds accesses. https://github.com/sugyan/yasai/blob/a7011ec7c1216bb2cf07d929c2c9722f062154f0/src/zobrist.rs#L52

sugyan commented 2 years ago

Thank you for pointing it out! I intended to calculate the key by taking xor with Table[(number of pieces) - 1] starting from 0 with no hand pieces. (Position::new calculated that way). But, in do_move, it was calculated using the number of pieces after capture, so it will be out of bounds... I fixed at #21.

koba-e964 commented 2 years ago

I intended to calculate the key by taking xor with Table[(number of pieces) - 1] starting from 0 with no hand pieces. (Position::new calculated that way).

My apologies, I completely missed that. Thank you for pointing it out, this cumulative-sum method is clearly better at computing the difference made by moves.