Skip to content

Commit 876dd18

Browse files
committed
generate pawn moves
1 parent d7c6889 commit 876dd18

File tree

7 files changed

+554
-67
lines changed

7 files changed

+554
-67
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
"See_c": true,
1313
"_config.yml": true,
1414
"diverese": true,
15+
"pm.txt": true,
16+
"engine-interface.txt": true,
1517
".gitignore": true
1618
},
1719
"cSpell.words": [

castlings.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@ const (
99
longW = uint(0x2) // white can castle long
1010
shortB = uint(0x4) // black can castle short
1111
longB = uint(0x8) // black can castle short
12+
13+
// squares between rook and king
14+
betweenWSh = bitBoard(uint64(1)<<G1) | bitBoard(uint64(1)<<F1)
15+
betweenWL = bitBoard(uint64(1)<<B1) | bitBoard(uint64(1)<<C1) | bitBoard(uint64(1)<<D1)
16+
betweenBSh = bitBoard(uint64(1)<<G8) | bitBoard(uint64(1)<<F8)
17+
betweenBL = bitBoard(uint64(1)<<B8) | bitBoard(uint64(1)<<C8) | bitBoard(uint64(1)<<D8)
1218
)
1319

1420
type castlOptions struct {
15-
short uint
16-
long uint
17-
rook int
18-
king int
19-
rookSh uint
20-
rookLong uint
21+
short uint
22+
long uint
23+
rook int
24+
king int
25+
rookPosSh uint
26+
rookPosL uint
27+
betweenSh bitBoard
28+
betweenL bitBoard
2129
}
2230

23-
var castl = [2]castlOptions{{shortW, longW, wR,E1, H1, A1}, {shortB, longB,bR, E8, H8, A8}}
31+
var castl = [2]castlOptions{
32+
{shortW, longW, wR, E1, H1, A1, betweenWSh, betweenWL},
33+
{shortB, longB, bR, E8, H8, A8, betweenBSh, betweenBL},
34+
}
2435

2536
// only castling privileges (not if it is legal on board)
2637
func (c castlings) canCastle(sd color) bool {

magic.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ var mRookTab [64]sMagic
1414

1515
// all attacks from current square
1616
func (m *sMagic) atks(b *boardStruct) bitBoard {
17-
return m.toSqBB[int(((b.allBB() & m.innerBB)*bitBoard(m.magic)) >>m.shift)]
17+
return m.toSqBB[int(((b.allBB()&m.innerBB)*bitBoard(m.magic))>>m.shift)]
1818
}
1919

2020
func initMagic() {
2121
fmt.Println("starting init() for magic.go")
2222

2323
// bishops
24-
fillOptimalMagicsB()
24+
//fillOptimalMagicsB()
2525
for sq := A1; sq <= H8; sq++ {
2626
mBishopTab[sq].shift = uint(64 - nBBits[sq])
2727
mBishopTab[sq].innerBB = bitBoard(innerBAtks(sq))
@@ -59,7 +59,7 @@ func prepareMagicB() {
5959
// all bit combinations for fr and all possible blockers
6060
cnt := bitCombs(0x0, fr, fr, 0, &maxM, &mBishopTab[fr], dirsB)
6161
_ = cnt
62-
// fmt.Println("bishop on", sq2Fen[fr], "#of combinations", cnt, "maxIx", maxM)
62+
// fmt.Println("bishop on", sq2Fen[fr], "#of combinations", cnt, "maxIx", maxM)
6363
}
6464
}
6565

@@ -71,7 +71,7 @@ func prepareMagicR() {
7171
// all bit combinations for fr and all possible moves (toSqBB)
7272
cnt := bitCombs(0x0, fr, fr, 0, &maxM, &mRookTab[fr], dirsR)
7373
_ = cnt
74-
// fmt.Println("rook on", sq2Fen[fr], "#of combinations", cnt, "maxIx", maxM)
74+
// fmt.Println("rook on", sq2Fen[fr], "#of combinations", cnt, "maxIx", maxM)
7575
}
7676
}
7777

@@ -96,7 +96,7 @@ func bitCombs(wBits bitBoard, fr, currSq, currIx int, maxM *int, mTabEntry *sMag
9696
}
9797
toBB := bitBoard(computeAtks(fr, dirs, uint64(wBits)))
9898

99-
if (*toSqBB)[int(m)] != 0x0 && (*toSqBB)[int(m)] != toBB && fr == F8 { // for bishop
99+
if (*toSqBB)[int(m)] != 0x0 && (*toSqBB)[int(m)] != toBB { // for bishop
100100
fmt.Println("we have problem", sq2Fen[fr], "with ix", int(m), "wBits:\n", bitBoard(wBits).Stringln())
101101
fmt.Println((*toSqBB)[int(m)].Stringln())
102102
fmt.Printf("%X\n", uint64((*toSqBB)[int(m)]))
@@ -251,7 +251,6 @@ func innerBAtks(sq int) uint64 {
251251
r--
252252
f++
253253
}
254-
255254
return atkBB
256255
}
257256

@@ -418,7 +417,7 @@ var nBBits = [64]int{
418417
// Thanks to Tord Romstad code from:
419418
// https://chessprogramming.wikispaces.com/Looking+for+Magics
420419
// This site will soon be closed down and moved somewhere else
421-
// Search for "Feeding in randoms Tord Romstad"
420+
// Search for "Feeding in randoms Tord Romstad"
422421

423422
var magicB = [64]uint64{
424423
0xc085080200420200,
@@ -573,4 +572,4 @@ func findDuplicates(toBBTab []bitBoard, fr int, magic uint64) int {
573572
}
574573
return cntDup
575574
}
576-
*/
575+
*/

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ func init(){
1313
initMagic()
1414
initAtksKings()
1515
initAtksKnights()
16+
board.newGame()
1617
}

0 commit comments

Comments
 (0)