Fix Chess960: seed RNG and use proper castling notation
All checks were successful
Build and Push / build-all (push) Successful in 1m1s

This commit is contained in:
doomtube 2026-01-08 02:43:12 -05:00
parent ada6b44236
commit 1ad3179cc3

View file

@ -82,6 +82,9 @@ type MatchLabel struct {
}
func InitModule(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, initializer runtime.Initializer) error {
// Seed random number generator for Chess960 positions
rand.Seed(time.Now().UnixNano())
logger.Info("Initializing realms.india Nakama Go modules")
// Register custom authentication hook
@ -170,10 +173,16 @@ func generateChess960Position() (string, int) {
pieces[remaining[1]] = 'K'
pieces[remaining[2]] = 'R'
// Build FEN
// Build FEN with Chess960 castling rights
whitePieces := string(pieces)
blackPieces := strings.ToLower(whitePieces)
fen := fmt.Sprintf("%s/pppppppp/8/8/8/8/PPPPPPPP/%s w KQkq - 0 1", blackPieces, whitePieces)
// Find rook positions for Chess960 castling notation
// remaining[0] is queenside rook, remaining[2] is kingside rook
castling := fmt.Sprintf("%c%c%c%c",
'A'+remaining[2], 'A'+remaining[0], // White kingside, queenside
'a'+remaining[2], 'a'+remaining[0]) // Black kingside, queenside
fen := fmt.Sprintf("%s/pppppppp/8/8/8/8/PPPPPPPP/%s w %s - 0 1", blackPieces, whitePieces, castling)
// Calculate position ID
positionID := (lightBishopIdx*4+darkBishopIdx)*6*10*10 + queenIdx*10*10 + knight1Idx*10 + knight2Idx