Created
November 20, 2019 15:35
-
-
Save dolegi/5f754570c813f348ccd9ff8517a47fd4 to your computer and use it in GitHub Desktop.
FEN parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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