Using Bitboards for Move Generation in Shogi - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Using Bitboards for Move Generation in Shogi

Description:

Bitboards are not a new idea. Have been used in chess for a long time ... Hoki's optimization. Represent a bitboard with an array of three integers. typedef struct ... – PowerPoint PPT presentation

Number of Views:231
Avg rating:3.0/5.0
Slides: 24
Provided by: reijergr
Category:

less

Transcript and Presenter's Notes

Title: Using Bitboards for Move Generation in Shogi


1
Using Bitboards for Move Generation in Shogi
  • Reijer Grimbergen
  • Department of Informatics
  • Yamagata University

2
Outline
  • Why this presentation?
  • Basic bitboards
  • Attack bitboards
  • Other bitboards
  • Experimental results
  • Conclusions and future work

3
Why this presentation?
  • Bitboards are not a new idea
  • Have been used in chess for a long time
  • Bitboards are not new in shogi
  • Yamashita has explained how to use bitboards in
    shogi
  • Bonanza uses bitboards
  • Why then this presentation?
  • Yamashitas explanation is buried in his BBS
  • There are some details that can be optimized
  • I dont agree with Yamashitas conclusion
  • No concise explanation about bitboards

4
Basic bitboards
  • What are bitboards?
  • Bitboards are a binary representation of
    knowledge for all squares on the board
  • Presence of knowledge is represented by setting
    the bit for the square to 1
  • Absence of knowledge is represented by setting
    the bit for the square to 0
  • Chess programs use bitboards for expressing many
    different types of knowledge

5
Basic bitboards
  • Bitboards in chess
  • One bitboard can be represented with a 64 bit
    integer
  • Yamashitas representation
  • Represent a bitboard with three integers
  • Hokis optimization
  • Represent a bitboard with an array of three
    integers

typedef struct unsigned int bb3 BITBOARD
6
bb0
bb1
bb2
7
Basic bitboards
  • Logical operations on bitboards
  • Similar operations for OR, XOR and NOT
  • Other basic operations on bitboards
  • ClearBB setting all bits to 0
  • SetBB setting all bits to 1
  • CopyBB copying a bitboard

void AndBB(BITBOARD to, from1, from2)
to?bb0 from1?bb0 from2?bb0 to?bb1
from1?bb1 from2?bb1 to?bb2
from1?bb2 from2?bb2
8
Basic bitboards
bb0
bb1
bb2
9
Basic bitboards
  • Bitboards for position information
  • Occupied bitboard for the occupied squares
  • SentePieces bitboard for the black pieces
  • GotePieces bitboard for the white pieces
  • Bitboards for each type of piece for black and
    white
  • SenteGold has 1s for the squares with black
    golds
  • The bitboards with position information must be
    updated at every move

10
Attack bitboards
  • Non-sliding pieces
  • 81 bitboards for each piece
  • Example bitboard for black gold on 5e

11
Attack bitboards
  • Horizontal attacks
  • Pre-calculate bitboards for all possible blocking
    possibilities
  • Example
  • Block pattern of the rook on 7h (square 66)
    001010110 86
  • bb2 000000000110110000000000000 221184
  • RankAttacks6686.bb2 221184

12
Attack bitboards
  • Problem
  • BITBOARD RankAttacks81512 is a big piece of
    memory (497Kb)
  • Optimization (Hyatt)
  • Edge squares do not change the piece attack
  • BITBOARD RankAttacks81128 (124Kb)

?
13
Attack bitboards
  • Vertical attacks
  • For horizontal attacks the bits are in
    consecutive positions, so masking and shifting is
    enough
  • For vertical attacks the bits are 9 positions
    apart
  • Solution (Hyatt)
  • Rotate the board 90 degrees
  • Needs a new bitboard Occupied_rot90 that has to
    be updated at every move
  • Can be used for both rooks and lances in shogi

14
(No Transcript)
15
(No Transcript)
16
Attack bitboards
  • Diagonal attacks
  • For bishops the bits along a diagonal are not
    adjacent
  • Solution (Hyatt)
  • Use rotations of 45 degrees clockwise and 45
    degrees anti-clockwise
  • Needs new bitboards Occupied_r45 and Occupied_l45
    which must be updated at every move

17
8 7 17
6 16 26 5 15 25 35 4 14
24 34 44 3 13 23 33 43 53 2 12
22 32 42 52 62 1 11 21 31 41 51 61
71 0 10 20 30 40 50 60 70 80 9 19 29
39 49 59 69 79 18 28 38 48 58 68 78
27 37 47 57 67 77 36 46 56 66
76 45 55 65 75 54 64 74
63 73 72
0 9 1
18 10 2 27 19 11 3 36 28
20 12 4 45 37 29 21 13 5 54 46
38 30 22 14 6 63 55 47 39 31 23 15
7 72 64 56 48 40 32 24 16 8 73 65 57
49 41 33 25 17 74 66 58 50 42 34
26 75 67 59 51 43 35 76 68
60 52 44 77 69 61 53
78 70 62 79 71 80
18
(No Transcript)
19
(No Transcript)
20
Other bitboards
  • Piece promotions
  • Use bitboards that have 1s for the squares inside
    the black or white promotion zone
  • Required promotion check
  • Use bitboards to decide if a knight, lance or
    pawn must promote

21
bb0
bb1
bb2
22
Experimental results
  • Comparing bitboards with attack tables
  • Yamashita showed a 20 speed increase for a tsume
    shogi solver
  • A different test
  • Minimax search with move generation using
    bitboards and move generation using attack tables
  • Test conditions
  • Minimax search to depth 4 for 100 positions from
    two professional games
  • Evaluation function only material

23
Conclusions and Future work
  • Conclusions
  • Bitboards made move generation almost twice as
    fast
  • Bitboards make a program more transparent
  • Bitboards might be a good alternative to attack
    tables in shogi as well
  • Future work
  • Will bitboards slow down the evaluation function?
  • The Static Exchange Evaluator and pin analysis
    can be implemented efficiently with bitboards
  • Faster than using attack tables?
Write a Comment
User Comments (0)
About PowerShow.com