@@ -48,6 +48,9 @@ const controls = {
4848 cellSize : document . querySelector ( "#cell-size" ) ,
4949 ruleMode : document . querySelector ( "#rule-mode" ) ,
5050 wolframRule : document . querySelector ( "#wolfram-rule" ) ,
51+ ruleNumber : document . querySelector ( "#rule-number" ) ,
52+ randomRule : document . querySelector ( "#random-rule" ) ,
53+ ruleSpaceSize : document . querySelector ( "#rule-space-size" ) ,
5154 ruleGenerator : document . querySelector ( "#rule-generator" ) ,
5255 json : document . querySelector ( "#config-json" ) ,
5356 importJson : document . querySelector ( "#import-json" ) ,
@@ -70,6 +73,7 @@ const liveFieldControls = [
7073const liveRuleControls = [
7174 controls . ruleMode ,
7275 controls . wolframRule ,
76+ controls . ruleNumber ,
7377 controls . ruleGenerator ,
7478] ;
7579
@@ -154,6 +158,7 @@ function controlsToConfig() {
154158 hauteur : Math . max ( 1 , Number ( controls . height . value || 100 ) ) ,
155159 frontiere : controls . boundary . value ,
156160 mode_regle : controls . ruleMode . value ,
161+ numero_regle : controls . ruleNumber . value || "0" ,
157162 etat_initial : { mode : initialMode } ,
158163 rendu : { ...( current . rendu || { } ) , taille_cellule : Math . max ( 1 , Number ( controls . cellSize . value || 5 ) ) } ,
159164 } ;
@@ -206,7 +211,10 @@ function syncControls(config) {
206211 controls . initialProbability . value = config . etat_initial ?. probabilite ?? 0.28 ;
207212 controls . cellSize . value = config . rendu ?. taille_cellule || 5 ;
208213 controls . ruleMode . value = config . mode_regle || "table" ;
209- controls . json . value = JSON . stringify ( config , null , 2 ) ;
214+ controls . ruleNumber . value = ( config . numero_regle ? String ( config . numero_regle ) : "0" ) ;
215+ // Convert BigInt to string for JSON serialization
216+ const configForJson = { ...config , numero_regle : String ( config . numero_regle || 0n ) } ;
217+ controls . json . value = JSON . stringify ( configForJson , null , 2 ) ;
210218}
211219
212220const DEFAULT_PALETTES = {
@@ -379,6 +387,12 @@ function describe(config) {
379387 renderTransitionSignals ( config ) ;
380388}
381389
390+ function updateRuleSpaceDisplay ( config ) {
391+ const { s, k, t, m, maxRule } = window . AutomaginariumCore . ruleConfiguration ( config ) ;
392+ const ruleSpaceText = `${ t } ^(${ m } ·${ s } ^${ k } ) = ${ maxRule } règles possibles` ;
393+ if ( controls . ruleSpaceSize ) controls . ruleSpaceSize . textContent = ruleSpaceText ;
394+ }
395+
382396function applyConfig ( config , { updateJson = true , updateControls = true , source = "Synchronisation" , live = false } = { } ) {
383397 const normalized = window . AutomaginariumCore . normaliserConfiguration ( config ) ;
384398 const validation = validateConfig ( normalized ) ;
@@ -393,8 +407,13 @@ function applyConfig(config, { updateJson = true, updateControls = true, source
393407 state . lastValidConfig = structuredClone ( normalized ) ;
394408 state . universe = window . AutomaginariumCore . genererUnivers ( normalized ) ;
395409 if ( updateControls ) syncControls ( normalized ) ;
396- if ( updateJson ) controls . json . value = JSON . stringify ( normalized , null , 2 ) ;
410+ if ( updateJson ) {
411+ // Convert BigInt to string for JSON serialization
412+ const configForJson = { ...normalized , numero_regle : String ( normalized . numero_regle || 0n ) } ;
413+ controls . json . value = JSON . stringify ( configForJson , null , 2 ) ;
414+ }
397415 describe ( normalized ) ;
416+ updateRuleSpaceDisplay ( normalized ) ;
398417 render ( ) ;
399418 updateLiveNarrative ( normalized , source , live ) ;
400419 setSyncState ( "ok" , live ? "Synchronisation live active" : "Configuration synchronisee" ) ;
@@ -543,6 +562,17 @@ PRESETS.forEach((preset) => {
543562 presetSelect . appendChild ( option ) ;
544563} ) ;
545564
565+ function randomBigInt ( max ) {
566+ const bits = max . toString ( 2 ) . length ;
567+ const words = Math . ceil ( bits / 32 ) + 1 ;
568+ const rng = AutomaginariumCore . mulberry32 ( Date . now ( ) >>> 0 ) ;
569+ let n = 0n ;
570+ for ( let i = 0 ; i < words ; i += 1 ) {
571+ n = ( n << 32n ) | BigInt ( Math . floor ( rng ( ) * 0x100000000 ) ) ;
572+ }
573+ return n % max ;
574+ }
575+
546576liveFieldControls . forEach ( ( control ) => {
547577 control . addEventListener ( "input" , ( ) => queueConfigPreview ( "Parametres" ) ) ;
548578 control . addEventListener ( "change" , ( ) => queueConfigPreview ( "Parametres" ) ) ;
@@ -566,6 +596,14 @@ document.querySelector("#generate-rule").addEventListener("click", () => {
566596 clearTimeout ( previewTimer ) ;
567597 applyGeneratedRule ( { updateJson : true , updateControls : true , source : "Regles" , live : false } ) ;
568598} ) ;
599+ document . querySelector ( "#random-rule" ) . addEventListener ( "click" , ( ) => {
600+ clearTimeout ( previewTimer ) ;
601+ const config = AutomaginariumCore . normaliserConfiguration ( controlsToConfig ( ) ) ;
602+ const { maxRule } = AutomaginariumCore . ruleConfiguration ( config ) ;
603+ controls . ruleNumber . value = randomBigInt ( maxRule ) . toString ( ) ;
604+ controls . ruleMode . value = "numerique" ;
605+ applyConfig ( controlsToConfig ( ) , { updateJson : true , updateControls : true , source : "Aléatoire" , live : false } ) ;
606+ } ) ;
569607document . querySelector ( "#apply-json" ) . addEventListener ( "click" , ( ) => {
570608 try {
571609 clearTimeout ( previewTimer ) ;
0 commit comments