c sc 483 chess and ai: computation and cognition
TRANSCRIPT
C SC 483Chess and AI: Computation
and CognitionLecture 5
September 24th
Task 2
• Your Goal:by next time– have the bitboard
system up andrunning
– to show:– e.g. click on a piece,
highlight its possiblemoves (graphically)
– or equivalent
Rotated BitboardsLast time we discussed therank and file attacks
• computed using a lookuptable for the rank
• file case reduces to the rankcase if we maintain 90degree rotated bitboards
• Good Reference(from lecture 3, slide 34):
– http://www.cis.uab.edu/hyatt/bitmaps.html
1 11 1 1
rank returns 11101100
10 1 1 1 0 0 0
lsb
msb
byte 8 byte 1
hex
0he
x 1
hex
14he
x 15
Rotated Bitboards• Sliding pieces:
– queen: either diagonal– bishop: either diagonal
• Key idea:– make diagonals consecutive
bits in rotated bitboard• Worked example:
– Leading Diagonal– bitboard is organized as shown
• leading diagonal (╲):
b0b1
b2
b3
b4
b5
b6
b7
2b0
2b1
2b2
2b3
2b4
2b5
2b6
2b7
3b0
2b7 2b6 2b5 2b4 b6 b5 b3 b0b1b2b4b72b02b12b22b3
3b1
3b4
3b5
4b0
4b3
4b4
5b4
6b3
7b1
7b6
8b2
8b5
8b7
Rotated Bitboards• Bitboards
– for the leading diagonalmaintained in parallel with theother bitboards
ldk “leading diagonal white king”ldK “leading diagonal black king”...ldb “leading diagonal white bishop”...ldP “leading diagonal black pawns”
• Computed Bitboardsldwhite = ( ldk | ldq | ldr | ldb | ldk |ldp )ldblack = ( ldK | ldQ | ldr | ldB | ldK |ldP )
• leading diagonal (╲):
b0b1
b2
b3
b4
b5
b6
b7
2b0
2b1
2b2
2b3
2b4
2b5
2b6
2b7
3b4
3b5
4b3
4b4
5b4
6b3
7b1
7b6
8b2
8b5
8b7
Rotated Bitboards• Two arrays/tables needed:
– Find your diagonal by rightshifting the bitmap
– Mask with your diagonal (ofvarying length)
• Example:– ldb = 0x0000000080000000– ldQ = 0x0000000020000000
• look up table:– given a bitmap, find its shift
number– diagonal_shift(ldb) = 28– (ldwhite | ldblack) >> 28 will give
what’s on the diagonal and more
• leading diagonal (╲):
b0b1
b2
b3
b4
b5
b6
b7
2b0
2b1
2b2
2b3
2b4
2b5
2b6
2b7
3b4
3b5
4b3
4b4
5b4
6b3
7b1
7b6
8b2
8b5
8b7
Rotated Bitboards• Two arrays/tables needed:
– Find your diagonal by right shifting thebitmap
– Mask with your diagonal (of varyinglength)
• Example:– ldb = 0x0000000080000000– ldQ = 0x0000000020000000
• look up table:– given a bitmap, find its mask– diagonal_mask(ldb) = FF (8bits long)
• summary:– diagonal(bb) = ((ldwhite | ldblack)
>> diagonal_shift(bb)) &diagonal_mask(bb)
– will give the diagonal
• leading diagonal (╲):
b0b1
b2
b3
b4
b5
b6
b7
2b0
2b1
2b2
2b3
2b4
2b5
2b6
2b7
3b4
3b5
4b3
4b4
5b4
6b3
7b1
7b6
8b2
8b5
8b7
Rotated Bitboards• Access diagonal
– diagonal right shift (>>) mask1 0 0x012 1 0x033 3 0x074 6 0x0F5 10 0x1F6 15 0x3F7 21 0x7F8 28 0xFF9 36 0x7F10 43 0x3F11 49 0x1F12 54 0x0F13 58 0x0714 61 0x0315 63 0x01
• trailing diagonal (╱):
12
3
4
5
7
8
11
12
16
17
22
23
9
10
13
14
18
19
20
21
24
25
26
27
15
28
6
Rotated Bitboards• Computed diagonal can be
looked up using the existingrank attacks tables
– diagonal(bb) = ((ldwhite | ldblack) >> diagonal_shift(bb)) &diagonal_mask(bb)computes a single byte
• Note:– if diagonal is shorter than 8 bits, fill in with 1’s for 8 bit lookup
diagonal(bb) | inv_mask(diagonal_mask(bb))• Examples:
– mask inv_mask– 0xFF 0x00– 0x0F 0xF0
• rank attacks lookup:
1 11 1 1
rank returns 11101100
Rotated Bitboards• define
– ld_moves(ldbb) = rank((( ldwhite |ldblack) >> diagonal_shift(ldbb)) &diagonal_mask(ldbb)) |inv_dmask(diagonal_mask(ldbb)),ldbb >> diagonal_shift(ldbb) &diagonal_mask(ldbb)) <<diagonal_shift(ldbb)
• Worked example: white bishop– ldwhite = ldb = 0x0000000080000000– ldblack = ldQ = 0x0000000020000000– diagonal_shift(ldb) = 28– diagonal_mask(ldbb) = 0xFF– rank((0x00000000A0000000 >> 28) &
0xFF | 0x00, (0x0000000080000000>> 28) & 0xFF) << 28)
– rank(0x0A,0x08) << 28– 0xF6 << 28 = 0x0000000F60000000
• compute diagonal attacks
0 1 0 1 0 0 0 0 (msb)
0 1 1 0 1 1 1 1 (msb)
+ mask out white pieces
Rotated Bitboards• Similar considerations for the
trailing diagonal representation
• Functions (or arrays):diagonal_shift(bb)diagonal_mask(bb)
(described earlier) can be re-used on the understandingthat they apply to the trailingdiagonal representation
• trailing diagonal (╱):
b0
b2
b1
b5
b4
b3
2b1
2b0
b7
b6
2b6
2b5
2b4
2b3
2b2 2b7
3b0
(1,1) (8,1)
(1,8) (8,8)
Rotated Bitboards
• result:
APPROXIMATE CHESS RANKINGS• 1. Complete beginner ( Rating<300)• 2. Beginner (Rating 300-600)• 3. Stronger beginner (Rating 600-900)• 4. Strong beginner (Rating 900-1200)• 5. Intermediate player ( Rating 1200-1400)• 6. Class D player (Rating 1400-1600)• 7.Class C player (Rating 1600-1800)• 8.Class B player ( Rating 1800-1900)• 9. Class A player (Rating 1900-1999)• 10. Expert (Rating 2000-2199)• 11. Master (Rating 2200)• 12. National Master ( Rating 2200 up to about 2300 )• 13. Senior Master (Rating of about 2300 to 2400 )• 13. FIDE Master ( International Rating of 2300 or higher after 24 games)• 14. International Master ( International rating of 2400> and 3 Norms completed )• 15. Grandmaster ( International rating of 2500> and 3 Norms completed )• 16. World Champion ( Best in the world, usually rating of 2750> and the winner of a
match recognized by FIDE )
KARPOV-KASPAROVLINARES 93
BOTVINNIK-CAPABLANCAHolland 1938
One of the most beautiful tactics of that era.Botvinnik was just becoming a top player,while Capablanca was still at his best. Thegame is also famous for being the 1st game
that a Chess Computer “Pioneer” in 1977 wasable to solve not by calculating million moves
but only few and choosing the best out ofthem.
BOTVINNIK-CAPABLANCA
The Opening
The Middlegame fight
The Tactical Calculation
Tactical Execution of the Idea
The Final Struggle by Black
Short Description of the Game• 1. A Normal Chess Opening by both sides.• 2. A power struggle on all 3 sides of the board.• 3. White opens the center and aims at the Black King.• 4. Black destroys white’s Queen side.• 5. White creates a strong Passed Pawn.• 6. White Sacrifices 2 pieces to open the Black King and
attack it.• 7. White threatens a Checkmate or Queen Promotion of
the “E” pawn.• 8. Black seeks Perpetual Chess but cannot find it.• 9. White wins.
HOMEWORKSet-up a chess board ( or use a Computer generated chess board ). Find thisgame (Botvinnik-Capablanca, 1938) in a chess book, use the full notationprovided above or on-line. You can use sources such as Chessbase (Lite),chessgames.com, chesslab.com, chessbase.com or any other to find thegame and possibly some commentaries about the game by Grandmasters.Go move-by-move over the game and find out what the opponents tried to doand what did they possibly miss.
1. What can you tell us about the Nimzo-Indian Opening that was used in thisgame. Its origination, strategic concepts, some examples, names of famouschess players who resorted to this defense when playing black. (15 Pts)
2. Was there a defense for Black anywhere after move 28? Think of your ownsuggestions, or use any sources to help improve Black’s defense. Where doyou think Black went wrong in the game? ( it could be on multiple points ofthe game ) (15 pts)
3. What can you tell me about the “Pioneer” Chess program developed byBotvinnik and what was so special about it? (Extra Credit-5 Pts)
Should be typed,Between 1-2 pages per question.Sources cited.