Skip to content

Instantly share code, notes, and snippets.

@dolegi
Created November 20, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolegi/5f754570c813f348ccd9ff8517a47fd4 to your computer and use it in GitHub Desktop.
Save dolegi/5f754570c813f348ccd9ff8517a47fd4 to your computer and use it in GitHub Desktop.
FEN parser
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
fen := "2r3k1/1q1nbppp/r3p3/3pP3/pPpP4/P1Q2N2/2RN1PPP/2R4K"
rows := strings.SplitN(fen, "/", -1)
board := [8][]string{}
for y := 0; y < len(rows); y++ {
squares := strings.SplitN(rows[y], "", -1)
for x := 0; x < len(squares); x++ {
square := squares[x]
if num, err := strconv.Atoi(square); err == nil {
for i := 0; i < int(num); i++ {
board[y] = append(board[y], " ")
}
} else {
board[y] = append(board[y], square)
}
}
}
for y := 0; y < len(board); y++ {
fmt.Println(board[y])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment