Skip to content

Commit 8fb5dfa

Browse files
Revert "use code_caser gem to eliminate snake_case identifiers"
This reverts commit 4d3ceaf.
1 parent 4d3ceaf commit 8fb5dfa

35 files changed

+1837
-1836
lines changed

attack.go

Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,77 @@ package main
77

88
import "fmt"
99

10-
func attackMap(brd *Board, occ BB, sq int) BB {
11-
// return ((pawnAttackMasks[BLACK][sq] & brd.pieces[WHITE][PAWN]) | // Pawns
12-
// (pawnAttackMasks[WHITE][sq] & brd.pieces[BLACK][PAWN])) |
13-
// (knightMasks[sq] & (brd.pieces[WHITE][KNIGHT] | brd.pieces[BLACK][KNIGHT])) | // Knights
14-
// (bishopAttacks(occ, sq) & (brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] | // Bishops and Queens
10+
func attack_map(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
1515
// brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN])) |
16-
// (rookAttacks(occ, sq) & (brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] | // Rooks and Queens
16+
// (rook_attacks(occ, sq) & (brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] | // Rooks and Queens
1717
// brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN])) |
18-
// (kingMasks[sq] & (brd.pieces[WHITE][KING] | brd.pieces[BLACK][KING])) // Kings
18+
// (king_masks[sq] & (brd.pieces[WHITE][KING] | brd.pieces[BLACK][KING])) // Kings
1919

20-
bb := ((pawnAttackMasks[BLACK][sq] & brd.pieces[WHITE][PAWN]) |
21-
(pawnAttackMasks[WHITE][sq] & brd.pieces[BLACK][PAWN])) | // Pawns
22-
(knightMasks[sq] & (brd.pieces[WHITE][KNIGHT] | brd.pieces[BLACK][KNIGHT])) | // Knights
23-
(kingMasks[sq] & (brd.pieces[WHITE][KING] | brd.pieces[BLACK][KING])) // Kings
24-
if bSliders := (brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] | brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]); bSliders&bishopMasks[sq] > 0 {
25-
bb |= (bishopAttacks(occ, sq) & bSliders) // Bishops and Queens
20+
bb := ((pawn_attack_masks[BLACK][sq] & brd.pieces[WHITE][PAWN]) |
21+
(pawn_attack_masks[WHITE][sq] & brd.pieces[BLACK][PAWN])) | // Pawns
22+
(knight_masks[sq] & (brd.pieces[WHITE][KNIGHT] | brd.pieces[BLACK][KNIGHT])) | // Knights
23+
(king_masks[sq] & (brd.pieces[WHITE][KING] | brd.pieces[BLACK][KING])) // Kings
24+
if b_sliders := (brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] | brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]); b_sliders&bishop_masks[sq] > 0 {
25+
bb |= (bishop_attacks(occ, sq) & b_sliders) // Bishops and Queens
2626
}
27-
if rSliders := (brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] | brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]); rSliders&rookMasks[sq] > 0 {
28-
bb |= (rookAttacks(occ, sq) & rSliders) // Rooks and Queens
27+
if r_sliders := (brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] | brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]); r_sliders&rook_masks[sq] > 0 {
28+
bb |= (rook_attacks(occ, sq) & r_sliders) // Rooks and Queens
2929
}
3030
return bb
3131
}
3232

33-
func colorAttackMap(brd *Board, occ BB, sq int, c, e uint8) BB {
34-
// return (pawnAttackMasks[e][sq] & brd.pieces[c][PAWN]) | // Pawns
35-
// (knightMasks[sq] & brd.pieces[c][KNIGHT]) | // Knights
36-
// (bishopAttacks(occ, sq) & (brd.pieces[c][BISHOP] | brd.pieces[c][QUEEN])) | // Bishops and Queens
37-
// (rookAttacks(occ, sq) & (brd.pieces[c][ROOK] | brd.pieces[c][QUEEN])) | // Rooks and Queens
38-
// (kingMasks[sq] & brd.pieces[c][KING]) // Kings
33+
func color_attack_map(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
3939

40-
bb := (pawnAttackMasks[e][sq] & brd.pieces[c][PAWN]) | // Pawns
41-
(knightMasks[sq] & brd.pieces[c][KNIGHT]) | // Knights
42-
(kingMasks[sq] & brd.pieces[c][KING]) // Kings
43-
if bSliders := (brd.pieces[c][BISHOP] | brd.pieces[c][QUEEN]); bSliders&bishopMasks[sq] > 0 {
44-
bb |= (bishopAttacks(occ, sq) & bSliders) // Bishops and Queens
40+
bb := (pawn_attack_masks[e][sq] & brd.pieces[c][PAWN]) | // Pawns
41+
(knight_masks[sq] & brd.pieces[c][KNIGHT]) | // Knights
42+
(king_masks[sq] & brd.pieces[c][KING]) // Kings
43+
if b_sliders := (brd.pieces[c][BISHOP] | brd.pieces[c][QUEEN]); b_sliders&bishop_masks[sq] > 0 {
44+
bb |= (bishop_attacks(occ, sq) & b_sliders) // Bishops and Queens
4545
}
46-
if rSliders := (brd.pieces[c][ROOK] | brd.pieces[c][QUEEN]); rSliders&rookMasks[sq] > 0 {
47-
bb |= (rookAttacks(occ, sq) & rSliders) // Rooks and Queens
46+
if r_sliders := (brd.pieces[c][ROOK] | brd.pieces[c][QUEEN]); r_sliders&rook_masks[sq] > 0 {
47+
bb |= (rook_attacks(occ, sq) & r_sliders) // Rooks and Queens
4848
}
4949
return bb
5050
}
5151

52-
// // attacksAfterMove(brd, occ, occ&brd.occupied[e], kingSq, e, c)
52+
// // attacks_after_move(brd, occ, occ&brd.occupied[e], king_sq, e, c)
5353
//
54-
// func attacksAfterMove(brd *Board, allOcc, attackerOcc BB, sq int, attacker, defender uint8) BB {
54+
// func attacks_after_move(brd *Board, all_occ, attacker_occ BB, sq int, attacker, defender uint8) BB {
5555
//
56-
// return (pawnAttackMasks[defender][sq] & brd.pieces[attacker][PAWN] & attackerOcc) | // Pawns
56+
// return (pawn_attack_masks[defender][sq] & brd.pieces[attacker][PAWN] & attacker_occ) | // Pawns
5757
//
58-
// (knightMasks[sq] & brd.pieces[attacker][KNIGHT]) | // Knights
58+
// (knight_masks[sq] & brd.pieces[attacker][KNIGHT]) | // Knights
5959
//
60-
// (bishopAttacks(allOcc, sq) & (brd.pieces[attacker][BISHOP]|brd.pieces[attacker][QUEEN])) | // Bishops and Queens
60+
// (bishop_attacks(all_occ, sq) & (brd.pieces[attacker][BISHOP]|brd.pieces[attacker][QUEEN])) | // Bishops and Queens
6161
//
62-
// (rookAttacks(allOcc, sq) & (brd.pieces[attacker][ROOK]|brd.pieces[attacker][QUEEN])) | // Rooks and Queens
62+
// (rook_attacks(all_occ, sq) & (brd.pieces[attacker][ROOK]|brd.pieces[attacker][QUEEN])) | // Rooks and Queens
6363
//
64-
// (kingMasks[sq] & brd.pieces[attacker][KING]) // Kings
64+
// (king_masks[sq] & brd.pieces[attacker][KING]) // Kings
6565
// }
6666

67-
func isAttackedBy(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
68-
if pawnAttackMasks[defender][sq]&brd.pieces[attacker][PAWN] > 0 { // Pawns
67+
func is_attacked_by(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
68+
if pawn_attack_masks[defender][sq]&brd.pieces[attacker][PAWN] > 0 { // Pawns
6969
return true
7070
}
71-
if knightMasks[sq]&(brd.pieces[attacker][KNIGHT]) > 0 { // Knights
71+
if knight_masks[sq]&(brd.pieces[attacker][KNIGHT]) > 0 { // Knights
7272
return true
7373
}
74-
if kingMasks[sq]&(brd.pieces[attacker][KING]) > 0 { // Kings
74+
if king_masks[sq]&(brd.pieces[attacker][KING]) > 0 { // Kings
7575
return true
7676
}
77-
if bishopAttacks(occ, sq)&(brd.pieces[attacker][BISHOP]|brd.pieces[attacker][QUEEN]) > 0 { // Bishops and Queens
77+
if bishop_attacks(occ, sq)&(brd.pieces[attacker][BISHOP]|brd.pieces[attacker][QUEEN]) > 0 { // Bishops and Queens
7878
return true
7979
}
80-
if rookAttacks(occ, sq)&(brd.pieces[attacker][ROOK]|brd.pieces[attacker][QUEEN]) > 0 { // Rooks and Queens
80+
if rook_attacks(occ, sq)&(brd.pieces[attacker][ROOK]|brd.pieces[attacker][QUEEN]) > 0 { // Rooks and Queens
8181
return true
8282
}
8383
return false
@@ -92,19 +92,19 @@ func isAttackedBy(brd *Board, occ BB, sq int, attacker, defender uint8) bool {
9292
// 3. Scan in the opposite direction to see detect any potential threats along this ray.
9393

9494
// Return a bitboard of locations the piece at sq can move to without leaving the king in check.
95-
func isPinned(brd *Board, sq int, c, e uint8) BB {
95+
func is_pinned(brd *Board, sq int, c, e uint8) BB {
9696
occ := brd.AllOccupied()
9797
var line, attacks, threat BB
98-
kingSq := brd.KingSq(c)
99-
dir := directions[sq][kingSq] // get direction toward king
98+
king_sq := brd.KingSq(c)
99+
dir := directions[sq][king_sq] // get direction toward king
100100

101-
line = lineMasks[sq][kingSq]
101+
line = line_masks[sq][king_sq]
102102
if line > 0 { // can only be pinned if on a ray to the king.
103103
if dir < NORTH {
104-
attacks = bishopAttacks(occ, sq)
104+
attacks = bishop_attacks(occ, sq)
105105
threat = line & attacks & (brd.pieces[e][BISHOP] | brd.pieces[e][QUEEN])
106106
} else {
107-
attacks = rookAttacks(occ, sq)
107+
attacks = rook_attacks(occ, sq)
108108
threat = line & attacks & (brd.pieces[e][ROOK] | brd.pieces[e][QUEEN])
109109
}
110110
if threat > 0 && (attacks&brd.pieces[c][KING]) > 0 {
@@ -126,122 +126,122 @@ const (
126126
SEE_MAX = 880 // best outcome (capturing an undefended queen)
127127
)
128128

129-
func getSee(brd *Board, from, to int, capturedPiece Piece) int {
130-
var nextVictim int
129+
func get_see(brd *Board, from, to int, captured_piece Piece) int {
130+
var next_victim int
131131
var t Piece
132-
// var t, lastT Piece
133-
tempColor := brd.Enemy()
132+
// var t, last_t Piece
133+
temp_color := brd.Enemy()
134134
// get initial map of all squares directly attacking this square (does not include 'discovered'/hidden attacks)
135-
bAttackers := brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] |
135+
b_attackers := brd.pieces[WHITE][BISHOP] | brd.pieces[BLACK][BISHOP] |
136136
brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]
137-
rAttackers := brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] |
137+
r_attackers := brd.pieces[WHITE][ROOK] | brd.pieces[BLACK][ROOK] |
138138
brd.pieces[WHITE][QUEEN] | brd.pieces[BLACK][QUEEN]
139139

140-
tempOcc := brd.AllOccupied()
141-
tempMap := attackMap(brd, tempOcc, to)
140+
temp_occ := brd.AllOccupied()
141+
temp_map := attack_map(brd, temp_occ, to)
142142

143-
var tempPieces BB
143+
var temp_pieces BB
144144

145-
var pieceList [20]int
145+
var piece_list [20]int
146146
count := 1
147147

148-
if capturedPiece == KING {
148+
if captured_piece == KING {
149149
// this move is illegal and will be discarded by search. return the lowest possible
150150
// SEE value so that this move will be put at end of list. If cutoff occurs before then,
151151
// the cost of detecting the illegal move will be saved.
152-
fmt.Println("king capture detected in getSee()!")
152+
fmt.Println("king capture detected in get_see()!")
153153
return SEE_MIN
154154
}
155155
t = brd.TypeAt(from)
156156
if t == KING { // Only commit to the attack if target piece is undefended.
157-
if tempMap&brd.occupied[tempColor] > 0 {
157+
if temp_map&brd.occupied[temp_color] > 0 {
158158
return SEE_MIN
159159
} else {
160-
return pieceValues[capturedPiece]
160+
return piece_values[captured_piece]
161161
}
162162
}
163163
// before entering the main loop, perform each step once for the initial attacking piece.
164164
// This ensures that the moved piece is the first to capture.
165-
pieceList[0] = pieceValues[capturedPiece]
166-
nextVictim = brd.ValueAt(from)
165+
piece_list[0] = piece_values[captured_piece]
166+
next_victim = brd.ValueAt(from)
167167

168-
tempOcc.Clear(from)
168+
temp_occ.Clear(from)
169169
if t != KNIGHT && t != KING { // if the attacker was a pawn, bishop, rook, or queen, re-scan for hidden attacks:
170170
if t == PAWN || t == BISHOP || t == QUEEN {
171-
tempMap |= bishopAttacks(tempOcc, to) & bAttackers
171+
temp_map |= bishop_attacks(temp_occ, to) & b_attackers
172172
}
173173
if t == PAWN || t == ROOK || t == QUEEN {
174-
tempMap |= rookAttacks(tempOcc, to) & rAttackers
174+
temp_map |= rook_attacks(temp_occ, to) & r_attackers
175175
}
176176
}
177177

178-
for tempMap &= tempOcc; tempMap > 0; tempMap &= tempOcc {
178+
for temp_map &= temp_occ; temp_map > 0; temp_map &= temp_occ {
179179
for t = PAWN; t <= KING; t++ { // loop over piece ts in order of value.
180-
tempPieces = brd.pieces[tempColor][t] & tempMap
181-
if tempPieces > 0 {
180+
temp_pieces = brd.pieces[temp_color][t] & temp_map
181+
if temp_pieces > 0 {
182182
break
183183
} // stop as soon as a match is found.
184184
}
185185
if t >= KING {
186186
if t == KING {
187-
if tempMap&brd.occupied[tempColor^1] > 0 {
187+
if temp_map&brd.occupied[temp_color^1] > 0 {
188188
break // only commit a king to the attack if the other side has no defenders left.
189189
}
190190
}
191191
break
192192
}
193193

194-
pieceList[count] = nextVictim - pieceList[count-1]
195-
nextVictim = pieceValues[t]
194+
piece_list[count] = next_victim - piece_list[count-1]
195+
next_victim = piece_values[t]
196196

197197
count++
198198

199-
if (pieceList[count-1] - nextVictim) > 0 { // validate this.
199+
if (piece_list[count-1] - next_victim) > 0 { // validate this.
200200
break
201201
}
202202

203-
tempOcc ^= (tempPieces & -tempPieces) // merge the first set bit of tempPieces into tempOcc
203+
temp_occ ^= (temp_pieces & -temp_pieces) // merge the first set bit of temp_pieces into temp_occ
204204
if t != KNIGHT && t != KING {
205205
if t == PAWN || t == BISHOP || t == QUEEN {
206-
tempMap |= (bishopAttacks(tempOcc, to) & bAttackers)
206+
temp_map |= (bishop_attacks(temp_occ, to) & b_attackers)
207207
}
208208
if t == ROOK || t == QUEEN {
209-
tempMap |= (rookAttacks(tempOcc, to) & rAttackers)
209+
temp_map |= (rook_attacks(temp_occ, to) & r_attackers)
210210
}
211211
}
212-
tempColor ^= 1
212+
temp_color ^= 1
213213
}
214214

215215
for count-1 > 0 {
216216
count--
217-
pieceList[count-1] = -max(-pieceList[count-1], pieceList[count])
217+
piece_list[count-1] = -max(-piece_list[count-1], piece_list[count])
218218
}
219-
// fmt.Printf(" %d ", pieceList[0])
220-
return pieceList[0]
219+
// fmt.Printf(" %d ", piece_list[0])
220+
return piece_list[0]
221221
}
222222

223-
func pinnedCanMove(brd *Board, from, to int, c, e uint8) bool {
224-
return isPinned(brd, from, brd.c, brd.Enemy())&sqMaskOn[to] > 0
223+
func pinned_can_move(brd *Board, from, to int, c, e uint8) bool {
224+
return is_pinned(brd, from, brd.c, brd.Enemy())&sq_mask_on[to] > 0
225225
}
226226

227-
func isCheckmate(brd *Board, inCheck bool) bool {
228-
if !inCheck {
227+
func is_checkmate(brd *Board, in_check bool) bool {
228+
if !in_check {
229229
return false
230230
}
231231
c := brd.c
232232
e := brd.Enemy()
233233
var to int
234234
from := brd.KingSq(c)
235235
occ := brd.AllOccupied()
236-
for t := kingMasks[from] & (^brd.occupied[c]); t > 0; t.Clear(to) { // generate to squares
237-
to = furthestForward(c, t)
238-
if !isAttackedBy(brd, occAfterMove(occ, from, to), to, e, c) {
236+
for t := king_masks[from] & (^brd.occupied[c]); t > 0; t.Clear(to) { // generate to squares
237+
to = furthest_forward(c, t)
238+
if !is_attacked_by(brd, occ_after_move(occ, from, to), to, e, c) {
239239
return false
240240
}
241241
}
242242
return true
243243
}
244244

245-
func occAfterMove(occ BB, from, to int) BB {
246-
return (occ | sqMaskOn[to]) & sqMaskOff[from]
245+
func occ_after_move(occ BB, from, to int) BB {
246+
return (occ | sq_mask_on[to]) & sq_mask_off[from]
247247
}

0 commit comments

Comments
 (0)