Skip to content

Commit d42a487

Browse files
run gometalinter
1 parent d1cb0cf commit d42a487

File tree

15 files changed

+107
-143
lines changed

15 files changed

+107
-143
lines changed

.DS_Store

2 KB
Binary file not shown.

attack.go

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ package main
88
import "fmt"
99

1010
func attackMap(brd *Board, occ BB, sq int) BB {
11-
// return ((pawn_attack_masks[BLACK][sq] & brd.pieces[WHITE][PAWN]) | // Pawns
12-
// (pawn_attack_masks[WHITE][sq] & brd.pieces[BLACK][PAWN])) |
13-
// (knight_masks[sq] & (brd.pieces[WHITE][KNIGHT] | brd.pieces[BLACK][KNIGHT])) | // Knights
14-
// (bishop_attacks(occ, sq) & (brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] | // Bishops and Queens
15-
// brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN])) |
16-
// (rook_attacks(occ, sq) & (brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] | // Rooks and Queens
17-
// brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN])) |
18-
// (king_masks[sq] & (brd.pieces[WHITE][KING] | brd.pieces[BLACK][KING])) // Kings
19-
2011
bb := ((pawnAttackMasks[BLACK][sq] & brd.pieces[WHITE][PAWN]) |
2112
(pawnAttackMasks[WHITE][sq] & brd.pieces[BLACK][PAWN])) | // Pawns
2213
(knightMasks[sq] & (brd.pieces[WHITE][KNIGHT] | brd.pieces[BLACK][KNIGHT])) | // Knights
@@ -31,12 +22,6 @@ func attackMap(brd *Board, occ BB, sq int) BB {
3122
}
3223

3324
func colorAttackMap(brd *Board, occ BB, sq int, c, e uint8) BB {
34-
// return (pawn_attack_masks[e][sq] & brd.pieces[c][PAWN]) | // Pawns
35-
// (knight_masks[sq] & brd.pieces[c][KNIGHT]) | // Knights
36-
// (bishop_attacks(occ, sq) & (brd.pieces[c][BISHOP] | brd.pieces[c][QUEEN])) | // Bishops and Queens
37-
// (rook_attacks(occ, sq) & (brd.pieces[c][ROOK] | brd.pieces[c][QUEEN])) | // Rooks and Queens
38-
// (king_masks[sq] & brd.pieces[c][KING]) // Kings
39-
4025
bb := (pawnAttackMasks[e][sq] & brd.pieces[c][PAWN]) | // Pawns
4126
(knightMasks[sq] & brd.pieces[c][KNIGHT]) | // Knights
4227
(kingMasks[sq] & brd.pieces[c][KING]) // Kings
@@ -49,21 +34,6 @@ func colorAttackMap(brd *Board, occ BB, sq int, c, e uint8) BB {
4934
return bb
5035
}
5136

52-
// // attacks_after_move(brd, occ, occ&brd.occupied[e], king_sq, e, c)
53-
//
54-
// func attacks_after_move(brd *Board, all_occ, attacker_occ BB, sq int, attacker, defender uint8) BB {
55-
//
56-
// return (pawn_attack_masks[defender][sq] & brd.pieces[attacker][PAWN] & attacker_occ) | // Pawns
57-
//
58-
// (knight_masks[sq] & brd.pieces[attacker][KNIGHT]) | // Knights
59-
//
60-
// (bishop_attacks(all_occ, sq) & (brd.pieces[attacker][BISHOP]|brd.pieces[attacker][QUEEN])) | // Bishops and Queens
61-
//
62-
// (rook_attacks(all_occ, sq) & (brd.pieces[attacker][ROOK]|brd.pieces[attacker][QUEEN])) | // Rooks and Queens
63-
//
64-
// (king_masks[sq] & brd.pieces[attacker][KING]) // Kings
65-
// }
66-
6737
func isAttackedBy(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
6838
if pawnAttackMasks[defender][sq]&brd.pieces[attacker][PAWN] > 0 { // Pawns
6939
return true
@@ -123,7 +93,7 @@ func isPinned(brd *Board, sq int, c, e uint8) BB {
12393
// way of reducing the size of the q-search without impacting playing strength.
12494
const (
12595
SEE_MIN = -780 // worst possible outcome (trading a queen for a pawn)
126-
SEE_MAX = 880 // best outcome (capturing an undefended queen)
96+
// SEE_MAX = 880 // best outcome (capturing an undefended queen)
12797
)
12898

12999
func getSee(brd *Board, from, to int, capturedPiece Piece) int {
@@ -149,6 +119,7 @@ func getSee(brd *Board, from, to int, capturedPiece Piece) int {
149119
// this move is illegal and will be discarded by search. return the lowest possible
150120
// SEE value so that this move will be put at end of list. If cutoff occurs before then,
151121
// the cost of detecting the illegal move will be saved.
122+
// TODO: send this in UCI-compatible format
152123
fmt.Println("king capture detected in getSee()!")
153124
return SEE_MIN
154125
}

balancer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const (
3737

3838
var loadBalancer *Balancer
3939

40-
func setupLoadBalancer(numCpu int) {
41-
numWorkers := uint8(min(numCpu, MAX_WORKERS))
40+
func setupLoadBalancer(numCPU int) {
41+
numWorkers := uint8(min(numCPU, MAX_WORKERS))
4242
loadBalancer = NewLoadBalancer(numWorkers)
4343
loadBalancer.Start()
4444
}
@@ -48,15 +48,15 @@ func NewLoadBalancer(numWorkers uint8) *Balancer {
4848
workers: make([]*Worker, numWorkers),
4949
done: make(chan *Worker, numWorkers),
5050
}
51-
for i := uint8(0); i < uint8(numWorkers); i++ {
51+
for i := uint8(0); i < numWorkers; i++ {
5252
b.workers[i] = &Worker{
53-
mask: 1 << i,
54-
index: i,
53+
mask: 1 << i,
54+
index: i,
5555
spList: make(SPList, 0, MAX_DEPTH),
56-
stk: NewStack(),
57-
ptt: NewPawnTT(),
56+
stk: NewStack(),
57+
ptt: NewPawnTT(),
5858
assignSp: make(chan *SplitPoint, 1),
59-
recycler: NewRecycler(512),
59+
recycler: NewRecycler(512),
6060
}
6161
}
6262
return b

bitboard_magic.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ func writeMagicsToDisk() {
9292
defer f.Close()
9393

9494
data, err := json.Marshal(magics)
95+
checkError(err)
9596

97+
_, err = f.Write(data) // write the magics to disk as JSON.
9698
checkError(err)
97-
f.Write(data) // write the magics to disk as JSON.
9899
}
99100

100101
func loadMagics() (success bool) {

bitboard_setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ var bishopOffsets = [4]int{7, 9, -7, -9}
3232
var rookOffsets = [4]int{8, 1, -8, -1}
3333
var kingOffsets = [8]int{-9, -7, 7, 9, -8, -1, 1, 8}
3434
var pawnAttackOffsets = [4]int{9, 7, -9, -7}
35-
var pawnAdvanceOffsets = [4]int{8, 16, -8, -16}
35+
36+
// var pawnAdvanceOffsets = [4]int{8, 16, -8, -16}
3637

3738
var directions [64][64]int
3839

board.go

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ var printMutex sync.Mutex
2020
// When spawning new goroutines for subtree search, a deep copy of the Board struct will have to be made
2121
// and passed to the new goroutine. Keep this struct as small as possible.
2222
type Board struct {
23-
pieces [2][6]BB // 768 bits
24-
squares [64]Piece // 512 bits
25-
occupied [2]BB // 128 bits
26-
material [2]int32 // 64 bits
23+
pieces [2][6]BB // 768 bits
24+
squares [64]Piece // 512 bits
25+
occupied [2]BB // 128 bits
26+
material [2]int32 // 64 bits
2727
hashKey uint64 // 64 bits
28-
pawnHashKey uint32 // 32 bits
29-
c uint8 // 8 bits
30-
castle uint8 // 8 bits
28+
pawnHashKey uint32 // 32 bits
29+
c uint8 // 8 bits
30+
castle uint8 // 8 bits
3131
enpTarget uint8 // 8 bits
3232
halfmoveClock uint8 // 8 bits
3333
endgameCounter uint8 // 8 bits
34-
worker *Worker
34+
worker *Worker
3535
}
3636

3737
type BoardMemento struct { // memento object used to store board state to unmake later.
3838
hashKey uint64
39-
pawnHashKey uint32
40-
castle uint8
39+
pawnHashKey uint32
40+
castle uint8
4141
enpTarget uint8
4242
halfmoveClock uint8
4343
}
4444

4545
func (brd *Board) NewMemento() *BoardMemento {
4646
return &BoardMemento{
4747
hashKey: brd.hashKey,
48-
pawnHashKey: brd.pawnHashKey,
49-
castle: brd.castle,
48+
pawnHashKey: brd.pawnHashKey,
49+
castle: brd.castle,
5050
enpTarget: brd.enpTarget,
5151
halfmoveClock: brd.halfmoveClock,
5252
}
@@ -226,12 +226,7 @@ func (brd *Board) ValidMove(m Move, inCheck bool) bool {
226226
}
227227
}
228228

229-
if brd.TypeAt(to) != capturedPiece {
230-
// fmt.Printf("Captured piece not found on to square!{%s}", m.ToString())
231-
return false
232-
}
233-
234-
return true
229+
return brd.TypeAt(to) == capturedPiece
235230
}
236231

237232
func (brd *Board) MayPromote(m Move) bool {
@@ -278,14 +273,14 @@ func (brd *Board) ColorPawnsOnly(c uint8) bool {
278273

279274
func (brd *Board) Copy() *Board {
280275
return &Board{
281-
pieces: brd.pieces,
282-
squares: brd.squares,
283-
occupied: brd.occupied,
284-
material: brd.material,
276+
pieces: brd.pieces,
277+
squares: brd.squares,
278+
occupied: brd.occupied,
279+
material: brd.material,
285280
hashKey: brd.hashKey,
286-
pawnHashKey: brd.pawnHashKey,
287-
c: brd.c,
288-
castle: brd.castle,
281+
pawnHashKey: brd.pawnHashKey,
282+
c: brd.c,
283+
castle: brd.castle,
289284
enpTarget: brd.enpTarget,
290285
halfmoveClock: brd.halfmoveClock,
291286
endgameCounter: brd.endgameCounter,
@@ -360,8 +355,8 @@ func EmptyBoard() *Board {
360355
}
361356

362357
func onBoard(sq int) bool { return 0 <= sq && sq <= 63 }
363-
func row(sq int) int { return sq >> 3 }
364-
func column(sq int) int { return sq & 7 }
358+
func row(sq int) int { return sq >> 3 }
359+
func column(sq int) int { return sq & 7 }
365360

366361
var pieceGraphics = [2][6]string{
367362
{"\u265F", "\u265E", "\u265D", "\u265C", "\u265B", "\u265A"},

eval_pawns.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ var duoBonus = [2][8]int{
3030
{0, 0, 1, 1, 1, 2, 0, 0},
3131
}
3232

33-
var promoteRow = [2][2]int{
34-
{1, 2},
35-
{6, 5},
36-
}
33+
// var promoteRow = [2][2]int{
34+
// {1, 2},
35+
// {6, 5},
36+
// }
3737

3838
// PAWN EVALUATION
3939
// Good structures:

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ func assert(statement bool, failureMessage string) {
4444
}
4545

4646
func init() {
47-
numCpu := runtime.NumCPU()
48-
runtime.GOMAXPROCS(numCpu)
47+
numCPU := runtime.NumCPU()
48+
runtime.GOMAXPROCS(numCPU)
4949
setupChebyshevDistance()
5050
setupMasks()
5151
setupMagicMoveGen()
5252
setupEval()
5353
setupRand()
5454
setupZobrist()
5555
resetMainTt()
56-
setupLoadBalancer(numCpu)
56+
setupLoadBalancer(numCPU)
5757
}
5858

5959
var version = "0.1.1"

move.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func NewCapture(from, to int, piece, capturedPiece Piece) Move {
108108
(Move(capturedPiece) << 15) | (Move(EMPTY) << 18)
109109
}
110110

111-
// since moving piece is always PAWN (0) for promotions, no need to merge in the moving piece.
112-
func NewPromotion(from, to int, piece, promotedTo Piece) Move {
113-
return Move(from) | (Move(to) << 6) | (Move(piece) << 12) |
114-
(Move(EMPTY) << 15) | (Move(promotedTo) << 18)
115-
}
111+
// // since moving piece is always PAWN (0) for promotions, no need to merge in the moving piece.
112+
// func NewPromotion(from, to int, piece, promotedTo Piece) Move {
113+
// return Move(from) | (Move(to) << 6) | (Move(piece) << 12) |
114+
// (Move(EMPTY) << 15) | (Move(promotedTo) << 18)
115+
// }

notation.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
)
1818

1919
type EPD struct {
20-
brd *Board
20+
brd *Board
2121
bestMoves []string
2222
avoidMoves []string
2323
nodeCount map[int]int
24-
id string
24+
id string
2525
}
2626

2727
func (epd *EPD) Print() {
@@ -69,18 +69,14 @@ func ParseEPDString(str string) *EPD {
6969
if loc != nil {
7070
field = field[loc[1]:]
7171
subFields = strings.Split(field, " ")
72-
for _, moveField := range subFields {
73-
epd.bestMoves = append(epd.bestMoves, moveField)
74-
}
72+
epd.bestMoves = append(epd.bestMoves, subFields...)
7573
continue
7674
}
7775
loc = am.FindStringIndex(field)
7876
if loc != nil {
7977
field = field[:loc[1]+1]
8078
subFields = strings.Split(field, " ")
81-
for _, moveField := range subFields {
82-
epd.avoidMoves = append(epd.avoidMoves, moveField)
83-
}
79+
epd.avoidMoves = append(epd.avoidMoves, subFields...)
8480
continue
8581
}
8682
loc = id.FindStringIndex(field)
@@ -320,7 +316,7 @@ func ParseMove(brd *Board, str string) Move {
320316
return NO_MOVE
321317
}
322318

323-
from := ParseSquare(string(str[:2]))
319+
from := ParseSquare(str[:2])
324320
to := ParseSquare(string(str[2:4]))
325321
piece := brd.TypeAt(from)
326322
capturedPiece := brd.TypeAt(to)

0 commit comments

Comments
 (0)