Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle game moves in standard algrbraic notation #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lc0_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,28 @@ func convertMovesToPGN(moves []string, result string, start_ply_count int) strin
return game2.String() + " {OL: " + strconv.Itoa(start_ply_count) + "}"
}

func convertSANToPGN(moves []string, result string, start_ply_count int) string {
pgn := ""
if len(moves) > 6 && moves[len(moves)-7] == "from_fen" {
fen := strings.Join(moves[len(moves)-6:], " ")
moves = moves[:len(moves)-7]
pgn += "[FEN \"" + fen + "\"]\n"
}
pgn += "\n" + strings.Join(moves, " ") + " "

if result == "draw" {
pgn += "1/2-1/2"
} else if result == "whitewon" {
pgn += "1-0"
} else if result == "blackwon" {
pgn += "0-1"
} else {
pgn += "*"
}

return pgn + " {OL: " + strconv.Itoa(start_ply_count) + "}"
}

func createCmdWrapper() *cmdWrapper {
c := &cmdWrapper{
gi: make(chan gameInfo),
Expand Down Expand Up @@ -459,6 +481,9 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
idx1 := strings.Index(line, "trainingfile")
idx2 := strings.LastIndex(line, "gameid")
idx3 := strings.LastIndex(line, "moves")
if idx3 < 0 {
idx3 = strings.LastIndex(line, "san")
}
if idx1 < 0 || idx2 < 0 || idx3 < 0 {
log.Printf("Malformed gameready: %q", line)
break
Expand All @@ -481,7 +506,12 @@ func (c *cmdWrapper) launch(networkPath string, otherNetPath string, args []stri
start_ply_count, err = strconv.Atoi(line[idx6+15 : idx4-1])
}
file := line[idx1+13 : idx2-1]
pgn := convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "), result, start_ply_count)
pgn := ""
if line[idx3] == 'm' {
pgn = convertMovesToPGN(strings.Split(line[idx3+6:len(line)], " "), result, start_ply_count)
} else {
pgn = convertSANToPGN(strings.Split(line[idx3+4:len(line)], " "), result, start_ply_count)
}
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