Skip to content

Commit 50e9380

Browse files
authored
Merge pull request #353 from glinscott/next
v0.7
2 parents 3fb4406 + 214dc60 commit 50e9380

45 files changed

Lines changed: 1718 additions & 346 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ training/tf/models/
3030
*.exe
3131
*.dll
3232
/go/src/client/settings.json
33+
*.vspx
34+
*.psess

CMakeLists.txt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ set (Boost_USE_MULTITHREADED ON)
2929
find_package (Boost 1.54.0 REQUIRED program_options filesystem)
3030
find_package (Threads REQUIRED)
3131
find_package (ZLIB REQUIRED)
32-
find_package (OpenCL REQUIRED)
32+
if (NOT FEATURE_USE_CPU_ONLY)
33+
find_package (OpenCL REQUIRED)
34+
endif()
3335

3436
# We need OpenBLAS for now, because we make some specific
3537
# calls. Ideally we'd use OpenBLAS is possible and fall back to
@@ -84,7 +86,9 @@ set (SrcPath "${CMAKE_CURRENT_SOURCE_DIR}/src")
8486

8587
include_directories (${IncludePath})
8688
include_directories (SYSTEM ${Boost_INCLUDE_DIRS})
87-
include_directories (SYSTEM ${OpenCL_INCLUDE_DIRS})
89+
if (NOT FEATURE_USE_CPU_ONLY)
90+
include_directories (SYSTEM ${OpenCL_INCLUDE_DIRS})
91+
endif()
8892
include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
8993

9094
if ((UNIX AND NOT APPLE) OR WIN32)
@@ -106,7 +110,9 @@ add_executable (lczero $<TARGET_OBJECTS:objs> ${lczero_MAIN})
106110

107111
target_link_libraries (lczero ${Boost_LIBRARIES})
108112
target_link_libraries (lczero ${BLAS_LIBRARIES})
109-
target_link_libraries (lczero ${OpenCL_LIBRARIES})
113+
if (NOT FEATURE_USE_CPU_ONLY)
114+
target_link_libraries (lczero ${OpenCL_LIBRARIES})
115+
endif()
110116
target_link_libraries (lczero ${ZLIB_LIBRARIES})
111117
target_link_libraries (lczero ${CMAKE_THREAD_LIBS_INIT})
112118
install (TARGETS lczero DESTINATION bin)
@@ -117,6 +123,8 @@ add_executable (tests ${tests_SRC} $<TARGET_OBJECTS:objs>)
117123

118124
target_link_libraries (tests ${Boost_LIBRARIES})
119125
target_link_libraries (tests ${BLAS_LIBRARIES})
120-
target_link_libraries (tests ${OpenCL_LIBRARIES})
126+
if (NOT FEATURE_USE_CPU_ONLY)
127+
target_link_libraries (tests ${OpenCL_LIBRARIES})
128+
endif()
121129
target_link_libraries (tests ${ZLIB_LIBRARIES})
122130
target_link_libraries (tests gtest_main ${CMAKE_THREAD_LIBS_INIT})

go/src/client/http/http.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"bytes"
5-
"compress/gzip"
65
"encoding/json"
76
"errors"
87
"fmt"
@@ -117,12 +116,6 @@ func DownloadNetwork(httpClient *http.Client, hostname string, networkPath strin
117116
return err
118117
}
119118

120-
// Copy while decompressing
121-
zr, err := gzip.NewReader(r.Body)
122-
if err != nil {
123-
log.Fatal(err)
124-
}
125-
126-
_, err = io.Copy(out, zr)
119+
_, err = io.Copy(out, r.Body)
127120
return err
128121
}

go/src/client/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func getExtraParams() map[string]string {
7878
return map[string]string{
7979
"user": *USER,
8080
"password": *PASSWORD,
81-
"version": "6",
81+
"version": "7",
8282
}
8383
}
8484

go/src/server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func uploadNetwork(c *gin.Context) {
225225
}
226226

227227
// TODO(gary): Make this more generic - upload to s3 for now
228-
cmd := exec.Command("aws", "s3", "cp", network.Path, "s3://lczero/" + network.Path)
228+
cmd := exec.Command("aws", "s3", "cp", network.Path, "s3://lczero/networks/")
229229
err = cmd.Run()
230230
if err != nil {
231231
log.Println(err.Error())

lc0/build.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/usr/bin/bash
22

33
rm -fr build
4-
CC=clang CXX=clang++ meson build --buildtype release
5-
# CC=clang CXX=clang++ meson build --buildtype debugoptimized
4+
CC=clang CXX=clang++ meson build --buildtype release # -Db_ndebug=true
5+
# CC=clang CXX=clang++ meson build --buildtype debugoptimized -Db_asneeded=false
6+
# CC=clang CXX=clang++ meson build --buildtype debug
67
cd build
78
ninja

lc0/meson.build

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
project('lc0', 'cpp',
2-
default_options : ['c_std=c17', 'cpp_std=c++17'])
1+
project('lc0', 'cpp')
2+
# default_options : ['cpp_std=c++17'])
33

4-
# add_global_arguments('-Wno-macro-redefined', language : 'cpp')
4+
add_global_arguments('-std=c++17', language : 'cpp')
55
cc = meson.get_compiler('cpp')
66

77
# Installed from https://github.com/FloopCZ/tensorflow_cc
@@ -33,6 +33,8 @@ files = [
3333
'src/chess/board.cc',
3434
'src/neural/loader.cc',
3535
'src/neural/network_tf.cc',
36+
'src/neural/network_random.cc',
37+
'src/neural/cache.cc',
3638
'src/mcts/search.cc',
3739
'src/mcts/node.cc',
3840
'src/engine.cc',
@@ -62,3 +64,8 @@ test('Network',
6264
executable('network_test', 'src/neural/network_test.cc',
6365
files, include_directories: includes, dependencies: test_deps
6466
))
67+
68+
test('HashCat',
69+
executable('hashcat_test', 'src/utils/hashcat_test.cc',
70+
files, include_directories: includes, dependencies: test_deps
71+
))

lc0/src/chess/bitboard.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,7 @@ const Move kIdxToMove[] = {
256256
"e7f8r", "e7f8b", "f7e8q", "f7e8r", "f7e8b", "f7f8q", "f7f8r", "f7f8b",
257257
"f7g8q", "f7g8r", "f7g8b", "g7f8q", "g7f8r", "g7f8b", "g7g8q", "g7g8r",
258258
"g7g8b", "g7h8q", "g7h8r", "g7h8b", "h7g8q", "h7g8r", "h7g8b", "h7h8q",
259-
"h7h8r", "h7h8b", "a2a1q", "a2a1r", "a2a1b", "a2b1q", "a2b1r", "a2b1b",
260-
"b2a1q", "b2a1r", "b2a1b", "b2b1q", "b2b1r", "b2b1b", "b2c1q", "b2c1r",
261-
"b2c1b", "c2b1q", "c2b1r", "c2b1b", "c2c1q", "c2c1r", "c2c1b", "c2d1q",
262-
"c2d1r", "c2d1b", "d2c1q", "d2c1r", "d2c1b", "d2d1q", "d2d1r", "d2d1b",
263-
"d2e1q", "d2e1r", "d2e1b", "e2d1q", "e2d1r", "e2d1b", "e2e1q", "e2e1r",
264-
"e2e1b", "e2f1q", "e2f1r", "e2f1b", "f2e1q", "f2e1r", "f2e1b", "f2f1q",
265-
"f2f1r", "f2f1b", "f2g1q", "f2g1r", "f2g1b", "g2f1q", "g2f1r", "g2f1b",
266-
"g2g1q", "g2g1r", "g2g1b", "g2h1q", "g2h1r", "g2h1b", "h2g1q", "h2g1r",
267-
"h2g1b", "h2h1q", "h2h1r", "h2h1b"};
259+
"h7h8r", "h7h8b"};
268260

269261
std::vector<unsigned short> BuildMoveIndices() {
270262
std::vector<unsigned short> res(4 * 64 * 64);

lc0/src/chess/bitboard.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BoardSquare {
3636
// From row(bottom to top), and col(left to right), 0-based.
3737
constexpr BoardSquare(int row, int col) : BoardSquare(row * 8 + col) {}
3838
// From Square name, e.g e4. Only lowercase.
39-
constexpr BoardSquare(const std::string& str, bool black = false)
39+
BoardSquare(const std::string& str, bool black = false)
4040
: BoardSquare(black ? '8' - str[1] : str[1] - '1', str[0] - 'a') {}
4141
constexpr std::uint8_t as_int() const { return square_; }
4242
void set(int row, int col) { square_ = row * 8 + col; }
@@ -198,11 +198,13 @@ class Move {
198198
BoardSquare from() const { return from_; }
199199
BoardSquare to() const { return to_; }
200200
Promotion promotion() const { return promotion_; }
201+
bool IsCastling() const { return castling_; }
202+
void SetCastling() { castling_ = true; }
201203

202204
// 0 .. 16384, knight promotion and no promotion is the same.
203205
uint16_t as_packed_int() const;
204206

205-
// 0 .. 1923, to use in neural networks.
207+
// 0 .. 1857, to use in neural networks.
206208
uint16_t as_nn_index() const;
207209

208210
bool operator==(const Move& other) const {
@@ -219,7 +221,11 @@ class Move {
219221
}
220222

221223
std::string as_string() const {
222-
std::string res = from_.as_string() + to_.as_string();
224+
BoardSquare to = to_;
225+
if (castling_) {
226+
to = BoardSquare(to.row(), (to.col() == 7) ? 6 : 2);
227+
}
228+
std::string res = from_.as_string() + to.as_string();
223229
switch (promotion_) {
224230
case Promotion::None:
225231
return res;
@@ -238,6 +244,7 @@ class Move {
238244
BoardSquare from_;
239245
BoardSquare to_;
240246
Promotion promotion_ = Promotion::None;
247+
bool castling_ = false;
241248
};
242249

243250
using MoveList = std::vector<Move>;

lc0/src/chess/board.cc

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <sstream>
2525
#include "utils/exception.h"
2626

27+
#ifdef _MSC_VER
28+
#include <nmmintrin.h>
29+
#endif
30+
2731
namespace lczero {
2832

2933
using std::string;
@@ -199,7 +203,8 @@ MoveList ChessBoard::GeneratePseudovalidMoves() const {
199203
}
200204
}
201205
if (can_castle) {
202-
result.emplace_back(source, BoardSquare(0, 6));
206+
result.emplace_back(source, BoardSquare(0, 7));
207+
result.back().SetCastling();
203208
}
204209
}
205210
if (castlings_.we_can_000()) {
@@ -219,7 +224,8 @@ MoveList ChessBoard::GeneratePseudovalidMoves() const {
219224
}
220225
}
221226
if (can_castle) {
222-
result.emplace_back(source, BoardSquare(0, 2));
227+
result.emplace_back(source, BoardSquare(0, 0));
228+
result.back().SetCastling();
223229
}
224230
}
225231
continue;
@@ -303,7 +309,7 @@ MoveList ChessBoard::GeneratePseudovalidMoves() const {
303309
// Ordinary capture.
304310
result.emplace_back(source, destination);
305311
}
306-
} else if (dst_row == 5 and pawns_.get(7, dst_col)) {
312+
} else if (dst_row == 5 && pawns_.get(7, dst_col)) {
307313
// En passant.
308314
result.emplace_back(source, destination);
309315
}
@@ -330,9 +336,9 @@ bool ChessBoard::ApplyMove(Move move) {
330336
const auto to_row = to.row();
331337
const auto to_col = to.col();
332338

333-
// Move in our pieces.
339+
// Remove our piece from old location, but not put to destination
340+
// (for the case of castling).
334341
our_pieces_.reset(from);
335-
our_pieces_.set(to);
336342

337343
// Remove captured piece
338344
bool reset_50_moves = their_pieces_.get(to);
@@ -364,24 +370,33 @@ bool ChessBoard::ApplyMove(Move move) {
364370
if (from == our_king_) {
365371
castlings_.reset_we_can_00();
366372
castlings_.reset_we_can_000();
367-
our_king_ = to;
368373
// Castling
369-
if (to_col - from_col == 2) {
374+
if (to_col - from_col > 1) {
370375
// 0-0
371376
our_pieces_.reset(7);
372377
rooks_.reset(7);
373378
our_pieces_.set(5);
374379
rooks_.set(5);
375-
} else if (from_col - to_col == 2) {
380+
our_king_ = BoardSquare(0, 6); /* g8 */
381+
our_pieces_.set(our_king_);
382+
} else if (from_col - to_col > 1) {
376383
// 0-0-0
377384
our_pieces_.reset(0);
378385
rooks_.reset(0);
379386
our_pieces_.set(3);
380387
rooks_.set(3);
388+
our_king_ = BoardSquare(0, 2); /* c8 */
389+
our_pieces_.set(our_king_);
390+
} else {
391+
our_king_ = to;
392+
our_pieces_.set(to);
381393
}
382394
return reset_50_moves;
383395
}
384396

397+
// Now destination square for our piece is known.
398+
our_pieces_.set(to);
399+
385400
// Promotion
386401
if (move.promotion() != Move::Promotion::None) {
387402
switch (move.promotion()) {
@@ -418,7 +433,7 @@ bool ChessBoard::ApplyMove(Move move) {
418433
pawns_.reset(from);
419434

420435
// Set en passant flag.
421-
if (to_row - from_row == 2 and pawns_.get(to)) {
436+
if (to_row - from_row == 2 && pawns_.get(to)) {
422437
pawns_.set(0, to_col);
423438
}
424439
return reset_50_moves;
@@ -600,8 +615,13 @@ bool ChessBoard::HasMatingMaterial() const {
600615
return true;
601616
}
602617

618+
#ifdef _MSC_VER
619+
int our = _mm_popcnt_u64(our_pieces_.as_int());
620+
int their = _mm_popcnt_u64(their_pieces_.as_int());
621+
#else
603622
int our = __builtin_popcountll(our_pieces_.as_int());
604623
int their = __builtin_popcountll(their_pieces_.as_int());
624+
#endif
605625
if (our > 2 || their > 2) {
606626
return true;
607627
}
@@ -661,7 +681,8 @@ string ChessBoard::DebugString() const {
661681
}
662682
if (i == 0) {
663683
result += " " + castlings_.as_string();
664-
result += flipped_ ? " (from black's eyes)" : "(from white's eyes)";
684+
result += flipped_ ? " (from black's eyes)" : " (from white's eyes)";
685+
result += " Hash: " + std::to_string(Hash());
665686
}
666687
result += '\n';
667688
}

0 commit comments

Comments
 (0)