mirror of
https://github.com/maaslalani/gambit.git
synced 2024-12-26 20:54:07 +02:00
fix: validate fen
This commit is contained in:
parent
3bc7d04a80
commit
f476062edb
@ -2,9 +2,16 @@ package fen
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var fenRegex = regexp.MustCompile(`\s*([rnbqkpRNBQKP1-8]+\/){7}([rnbqkpRNBQKP1-8]+)\s[bw-]\s(([a-hkqA-HKQ]{1,4})|(-))\s(([a-h][36])|(-))\s\d+\s\d+\s*`)
|
||||
|
||||
func IsValid(fen string) bool {
|
||||
return fenRegex.MatchString(fen)
|
||||
}
|
||||
|
||||
// Tokens returns the (6) tokens of a FEN string
|
||||
//
|
||||
// [Pieces, Turn, Castling, En passant, Halfmove Clock, Fullmove number]
|
||||
|
@ -31,7 +31,11 @@ type model struct {
|
||||
|
||||
// InitialModel returns an initial model of the game board.
|
||||
func InitialModel(position string) tea.Model {
|
||||
if !fen.IsValid(position) {
|
||||
position = dt.Startpos
|
||||
}
|
||||
board := dt.ParseFen(position)
|
||||
|
||||
return model{
|
||||
board: &board,
|
||||
moves: board.GenerateLegalMoves(),
|
||||
|
Loading…
Reference in New Issue
Block a user