Skip to content

Commit 6cec8ac

Browse files
committed
Handle uci go command init
1 parent 7772042 commit 6cec8ac

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

bitboard.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ func (b *bitBoard) firstOne() int {
3333
return bit
3434
}
3535

36-
//TODO: lastOne() here
36+
func (b *bitBoard) lastOne() int {
37+
bit := bits.LeadingZeros64(uint64(*b))
38+
if bit == 64 {
39+
return 64
40+
}
41+
*b = (*b << uint(bit+1)) >> uint(bit+1)
42+
return 63-bit
43+
}
3744

3845
// returns the full bitstring (with leading zeroes) of the bitBoard
3946
func (b bitBoard) String() string {
File renamed without changes.

move_test.go renamed to moves_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ func Test_moveList_add(t *testing.T) {
1717
ml = moveList{}
1818
for _, tt := range tests {
1919
t.Run(tt.name, func(t *testing.T) {
20-
tt.ml = tt.ml
2120
tt.ml.add(tt.mv)
22-
ix:=len(tt.ml.mv)-1
21+
ix:=len(tt.ml)-1
2322
if ix<0{
24-
t.Fatalf("wrong len %v: %v %v %v",ix,tt.ml,tt.ml.mv,tt.ml.mv[0])
23+
t.Fatalf("wrong len %v: %v %v",ix,tt.ml,tt.ml[0])
2524
}
26-
testMv := tt.ml.mv[ix]
25+
testMv := tt.ml[ix]
2726
if testMv != tt.mv{
2827
t.Errorf("tt.ml.add() = %v. want %v",testMv,tt.mv)
2928
}

position.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (b *boardStruct) clear() {
6464

6565
// make a pseudomove
6666
func (b *boardStruct) move(fr, to, pr int) bool {
67+
6768
newEp := 0
6869
// we assume that the move is legally correct
6970
p12 := b.sq[fr]
@@ -145,7 +146,11 @@ func (b *boardStruct) move(fr, to, pr int) bool {
145146
}
146147

147148
func (b *boardStruct) setSq(p12, s int) {
149+
if b.sq[s] != empty {
150+
b.count[b.sq[s]]--
151+
}
148152
b.sq[s] = p12
153+
149154
if p12 == empty {
150155
b.wbBB[WHITE].clr(uint(s))
151156
b.wbBB[BLACK].clr(uint(s))
@@ -154,6 +159,8 @@ func (b *boardStruct) setSq(p12, s int) {
154159
}
155160
return
156161
}
162+
163+
b.count[p12]++
157164

158165
p := piece(p12)
159166
sd := p12Color(p12)
@@ -165,6 +172,7 @@ func (b *boardStruct) setSq(p12, s int) {
165172
b.wbBB[sd].set(uint(s))
166173
b.pieceBB[p].set(uint(s))
167174
}
175+
168176
func (b *boardStruct) newGame() {
169177
b.stm = WHITE
170178
b.clear()
@@ -173,15 +181,14 @@ func (b *boardStruct) newGame() {
173181
func (b *boardStruct) genRookMoves() {
174182
sd := b.stm
175183
frBB := b.pieceBB[Rook] & b.wbBB[sd]
176-
p12 := pc2P12(Rook,sd)
177-
b.genFrMoves(p12,frBB,&ml)
184+
p12 := pc2P12(Rook, sd)
185+
b.genFrMoves(p12, frBB, &ml)
178186
}
179187

180-
func (b *boardStruct) genFrMoves(p12 int, frBB bitBoard, ml *moveList){
188+
func (b *boardStruct) genFrMoves(p12 int, frBB bitBoard, ml *moveList) {
181189
// TODO finish genRookMoves
182190
}
183191

184-
185192
//////////////////////////////////// my own commands - NOT UCI /////////////////////////////////////
186193
func (b *boardStruct) Print() {
187194
txtStm := "BLACK"
@@ -374,7 +381,7 @@ func parseMvs(mvstr string) {
374381
}
375382

376383
// is the prom piece ok?
377-
pr := 0
384+
pr := empty
378385
if len(mv) == 5 { //prom
379386
if !strings.ContainsAny(mv[4:5], "qrbn") {
380387
tell("info string promotion piece in ", mv, " in the position command is not correct")

position_test.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package main
32

43
import (
@@ -53,3 +52,38 @@ func Test_boardStruct_allBB(t *testing.T) {
5352
})
5453
}
5554
}
55+
56+
func Test_boardStruct_setSq(t *testing.T) {
57+
board.newGame()
58+
tests := []struct {
59+
name string
60+
p12 int
61+
sq int
62+
}{
63+
{"Ke4", fen2Int("K"), E4},
64+
{"pe3", fen2Int("p"), E3},
65+
{"pe5", fen2Int("p"), E5},
66+
{"Qb6", fen2Int("Q"), B6},
67+
{"nh6", fen2Int("n"), H6},
68+
}
69+
for _, tt := range tests {
70+
t.Run(tt.name, func(t *testing.T) {
71+
count := board.count[tt.p12]
72+
board.setSq(tt.p12, tt.sq)
73+
if board.sq[tt.sq] != tt.p12 {
74+
t.Errorf("%v: board should contain %v on sq=%v. Got %v", tt.name, tt.p12, tt.sq, board.sq[tt.sq])
75+
}
76+
pc := piece(tt.p12)
77+
sd := p12Color(tt.p12)
78+
if !board.wbBB[sd].test(uint(tt.sq)) {
79+
t.Errorf("%v: wbBB[%v] on sq=%v should be set to 1 but is 0", tt.name, sd, tt.sq)
80+
}
81+
if !board.pieceBB[pc].test(uint(tt.sq)) {
82+
t.Errorf("%v: pieceBB[%v] on sq=%v should be set to 1 but is 0", tt.name, pc, tt.sq)
83+
}
84+
if board.count[tt.p12] != count+1 {
85+
t.Errorf("%v: count[%v] should be %v. Got %v", tt.name, tt.p12, count+1, board.count[tt.p12])
86+
}
87+
})
88+
}
89+
}

uci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func handleSetOption(words []string) {
156156
// go searchmoves <move1-moveii>/ponder/wtime <ms>/ btime <ms>/winc <ms>/binc <ms>/movestogo <x>/
157157
// depth <x>/nodes <x>/movetime <ms>/mate <x>/infinite
158158
func handleGo(words []string) {
159-
// TODO: Start with moeveTime and infinite
159+
// TODO: Start with moveTime and infinite
160160
if len(words) > 1 {
161161
words[1] = trim(low(words[1]))
162162
switch words[1] {

0 commit comments

Comments
 (0)