Skip to content

Commit 24f0c6f

Browse files
committed
18 three rules about check
1 parent f473e7c commit 24f0c6f

File tree

9 files changed

+529
-144
lines changed

9 files changed

+529
-144
lines changed

.vscode/settings.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"design.png": true,
55
"**/*.exe": true,
66
"**/*.png": true,
7-
"temp.go": true,
87
"README.md": true,
98
"LICENSE": true,
109
"uci_example.txt": true,
@@ -13,7 +12,6 @@
1312
"_config.yml": true,
1413
"diverese": true,
1514
"pm.txt": true,
16-
"engine-interface.txt": true,
1715
".gitignore": true
1816
},
1917
"cSpell.words": [

castlings.go

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package main
22

3-
import "strings"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
type castlings uint
69

@@ -18,19 +21,20 @@ const (
1821
)
1922

2023
type castlOptions struct {
21-
short uint
22-
long uint
23-
rook int
24-
king int
25-
rookPosSh uint
26-
rookPosL uint
27-
betweenSh bitBoard
28-
betweenL bitBoard
24+
short uint // flag
25+
long uint // flag
26+
rook int // rook p12 (wR/bR)
27+
kingPos int // king pos
28+
rookSh uint // rook pos short
29+
rookL uint // rook pos long
30+
betweenSh bitBoard
31+
betweenL bitBoard
32+
pawnsSh, pawnsL, knightsSh, knightsL bitBoard
2933
}
3034

3135
var castl = [2]castlOptions{
32-
{shortW, longW, wR, E1, H1, A1, betweenWSh, betweenWL},
33-
{shortB, longB, bR, E8, H8, A8, betweenBSh, betweenBL},
36+
{shortW, longW, wR, E1, H1, A1, betweenWSh, betweenWL, 0x0, 0x0, 0x0, 0x0},
37+
{shortB, longB, bR, E8, H8, A8, betweenBSh, betweenBL, 0x0, 0x0, 0x0, 0x0},
3438
}
3539

3640
// only castling privileges (not if it is legal on board)
@@ -94,3 +98,81 @@ func parseCastlings(fenCastl string) castlings {
9498

9599
return castlings(c)
96100
}
101+
102+
func initCastlings() {
103+
fmt.Println("init castlings")
104+
// pawns stops short castling W
105+
castl[WHITE].pawnsSh.set(D2)
106+
castl[WHITE].pawnsSh.set(E2)
107+
castl[WHITE].pawnsSh.set(F2)
108+
castl[WHITE].pawnsSh.set(G2)
109+
castl[WHITE].pawnsSh.set(H2)
110+
// pawns stops long castling W
111+
castl[WHITE].pawnsL.set(B2)
112+
castl[WHITE].pawnsL.set(C2)
113+
castl[WHITE].pawnsL.set(D2)
114+
castl[WHITE].pawnsL.set(E2)
115+
castl[WHITE].pawnsL.set(F2)
116+
117+
// pawns stops short castling B
118+
castl[BLACK].pawnsSh.set(D7)
119+
castl[BLACK].pawnsSh.set(E7)
120+
castl[BLACK].pawnsSh.set(F7)
121+
castl[BLACK].pawnsSh.set(G7)
122+
castl[BLACK].pawnsSh.set(H7)
123+
// pawns stops long castling B
124+
castl[BLACK].pawnsL.set(B7)
125+
castl[BLACK].pawnsL.set(C7)
126+
castl[BLACK].pawnsL.set(D7)
127+
castl[BLACK].pawnsL.set(E7)
128+
castl[BLACK].pawnsL.set(F7)
129+
130+
// knights stops short castling W
131+
castl[WHITE].knightsSh.set(C2)
132+
castl[WHITE].knightsSh.set(D2)
133+
castl[WHITE].knightsSh.set(E2)
134+
castl[WHITE].knightsSh.set(G2)
135+
castl[WHITE].knightsSh.set(H2)
136+
castl[WHITE].knightsSh.set(D3)
137+
castl[WHITE].knightsSh.set(E3)
138+
castl[WHITE].knightsSh.set(F3)
139+
castl[WHITE].knightsSh.set(G3)
140+
castl[WHITE].knightsSh.set(H3)
141+
// knights stops long castling W
142+
castl[WHITE].knightsL.set(A2)
143+
castl[WHITE].knightsL.set(B2)
144+
castl[WHITE].knightsL.set(C2)
145+
castl[WHITE].knightsL.set(E2)
146+
castl[WHITE].knightsL.set(F2)
147+
castl[WHITE].knightsL.set(G2)
148+
castl[WHITE].knightsL.set(B3)
149+
castl[WHITE].knightsL.set(C3)
150+
castl[WHITE].knightsL.set(D3)
151+
castl[WHITE].knightsL.set(E3)
152+
castl[WHITE].knightsL.set(F3)
153+
154+
// knights stops short castling B
155+
castl[BLACK].knightsSh.set(C7)
156+
castl[BLACK].knightsSh.set(D7)
157+
castl[BLACK].knightsSh.set(E7)
158+
castl[BLACK].knightsSh.set(G7)
159+
castl[BLACK].knightsSh.set(H7)
160+
castl[BLACK].knightsSh.set(D6)
161+
castl[BLACK].knightsSh.set(E6)
162+
castl[BLACK].knightsSh.set(F6)
163+
castl[BLACK].knightsSh.set(G6)
164+
castl[BLACK].knightsSh.set(H6)
165+
// knights stops long castling B
166+
castl[BLACK].knightsL.set(A7)
167+
castl[BLACK].knightsL.set(B7)
168+
castl[BLACK].knightsL.set(C7)
169+
castl[BLACK].knightsL.set(E7)
170+
castl[BLACK].knightsL.set(F7)
171+
castl[BLACK].knightsL.set(G7)
172+
castl[BLACK].knightsL.set(B6)
173+
castl[BLACK].knightsL.set(C6)
174+
castl[BLACK].knightsL.set(D6)
175+
castl[BLACK].knightsL.set(E6)
176+
castl[BLACK].knightsL.set(F6)
177+
178+
}

engine.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ func engine() (toEngine chan string, frEngine chan string) {
4747

4848
return
4949
}
50+

main.go

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

moves.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ const (
3232

3333
var pieceRules [nP][]int // not pawns
3434

35-
func init() {
36-
pieceRules[Rook] = append(pieceRules[Rook], E)
37-
pieceRules[Rook] = append(pieceRules[Rook], W)
38-
pieceRules[Rook] = append(pieceRules[Rook], N)
39-
pieceRules[Rook] = append(pieceRules[Rook], S)
40-
}
41-
4235
type move uint64
4336

4437
func (m move) String() string {
@@ -55,7 +48,6 @@ func (m move) StringFull() string {
5548
return fmt.Sprintf("%v%v-%v%v%v", p, fr, cp[:1], to, pr)
5649
}
5750

58-
5951
func (m *move) packMove(fr, to, p12, cp, pr, epSq, castl uint) {
6052
// 6 bits fr, 6 bits to, 4 bits p12, 4 bits cp, 4 bits prom, 4 bits ep, 4 bits castl = 32 bits
6153
*m = move(fr | (to << toShift) | (p12 << p12Shift) |
@@ -87,16 +79,23 @@ func (m move) castl() castlings {
8779

8880
type moveList []move
8981

90-
func (mvs *moveList) add(mv move) {
91-
*mvs = append(*mvs, mv)
82+
func (ml *moveList) add(mv move) {
83+
*ml = append(*ml, mv)
9284
}
9385

94-
func (mvs moveList) String() string {
86+
func (ml *moveList) remove(ix int){
87+
if len(*ml) > ix && ix >=0{
88+
*ml = append((*ml)[:ix],(*ml)[ix+1:]...)
89+
}
90+
}
91+
92+
93+
func (ml moveList) String() string {
9594
theString := ""
96-
for _, mv := range mvs {
95+
for _, mv := range ml {
9796
theString += mv.String() + " "
9897
}
9998
return theString
10099
}
101100

102-
var ml = moveList{}
101+
var ml = moveList{}

moves_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,26 @@ func Test_move_packMove(t *testing.T) {
7777
})
7878
}
7979
}
80+
81+
func Test_moveList_remove(t *testing.T) {
82+
tests := []struct {
83+
name string
84+
cnt int
85+
ix int
86+
}{
87+
{"5 3",5,3},
88+
{"5 0",5,0},
89+
{"5 4",5,4},
90+
{"1 0",1,0},
91+
}
92+
for _, tt := range tests {
93+
t.Run(tt.name, func(t *testing.T) {
94+
var ml moveList
95+
for i :=0;i<tt.cnt;i++{ml.add(move(i))}
96+
ml.remove(tt.ix)
97+
if len(ml) != tt.cnt-1{
98+
t.Errorf("%v: we should have %v moves but have %v",tt.name,tt.cnt-1,len(ml))
99+
}
100+
})
101+
}
102+
}

0 commit comments

Comments
 (0)