Skip to content

Commit

Permalink
Merge pull request #89 from LeelaChessZero/master
Browse files Browse the repository at this point in the history
Merge to release branch for v22
  • Loading branch information
Tilps committed Mar 22, 2019
2 parents 7b908d3 + 0f0fdf5 commit 5fe2f51
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions lc0_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func getExtraParams() map[string]string {
return map[string]string{
"user": *user,
"password": *password,
"version": "21",
"version": "22",
"token": strconv.Itoa(randId),
"train_only": strconv.FormatBool(*trainOnly),
}
Expand Down Expand Up @@ -201,7 +201,7 @@ func (c *cmdWrapper) openInput() {
}
}

func convertMovesToPGN(moves []string) string {
func convertMovesToPGN(moves []string, result string) string {
game := chess.NewGame(chess.UseNotation(chess.LongAlgebraicNotation{}))
for _, m := range moves {
err := game.MoveStr(m)
Expand All @@ -217,6 +217,16 @@ func convertMovesToPGN(moves []string) string {
if err != nil {
log.Fatalf("MarshalText failed: %v", err)
}
b_str := string(b)
if strings.HasSuffix(b_str, " *") && result != "" {
to_append := "1/2-1/2"
if result == "whitewon" {
to_append = "1-0"
} else if result == "blackwon" {
to_append = "0-1"
}
b = []byte(strings.TrimRight(b_str, "*") + to_append)
}
game2.UnmarshalText(b)
return game2.String()
}
Expand Down Expand Up @@ -377,7 +387,7 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
player = line[idx4+8 : idx5-1]
}
file := line[idx1+13 : idx2-1]
pgn := convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "))
pgn := convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "), result)
fmt.Printf("PGN: %s\n", pgn)
c.gi <- gameInfo{pgn: pgn, fname: file, fp_threshold: last_fp_threshold, player1: player, result: result}
last_fp_threshold = -1.0
Expand Down Expand Up @@ -720,15 +730,15 @@ func acquireLock(dir string, sha string) (lockfile.Lockfile, error) {
func getNetwork(httpClient *http.Client, sha string, keepTime string) (string, error) {
dir := "networks"
os.MkdirAll(dir, os.ModePerm)
if keepTime != inf {
err := removeAllExcept(dir, sha, keepTime)
if err != nil {
log.Printf("Failed to remove old network(s): %v", err)
}
}
path, err := checkValidNetwork(dir, sha)
if err == nil {
// There is already a valid network. Use it.
if keepTime != inf {
err := removeAllExcept(dir, sha, keepTime)
if err != nil {
log.Printf("Failed to remove old network(s): %v", err)
}
}
return path, nil
}

Expand Down Expand Up @@ -883,6 +893,19 @@ func hideLc0argsFlag() {
}
}

func maybeSetTrainOnly() {
found := false
flag.Visit(func(f *flag.Flag) {
if f.Name == "train-only" {
found = true
}
})
if !found && !hasCudnn && !hasCudnnFp16 {
*trainOnly = true
log.Println("Will only run training games, use -train-only=false to override")
}
}

func main() {
fmt.Printf("Lc0 client version %v\n", getExtraParams()["version"])

Expand All @@ -897,6 +920,8 @@ func main() {

checkLc0()

maybeSetTrainOnly()

// 640 ought to be enough for anybody.
if *runId > 640 {
log.Fatal("Training run number too large")
Expand Down

0 comments on commit 5fe2f51

Please sign in to comment.