Build the pipe-board app in Godot
Tables are cards on a felt board, joined by copper pipes that carry a
roll from one table to the next. Play mode rolls with a flicker and a
bead down each pipe; Build mode edits names, results, ranges and pipes.
- core/: data model (RollTable, TableEntry, TowerBoard), sample board
with a d100 table of 100 trinkets and a weighted d100 range table,
and a Roller with a depth limit
- ui/: board with pan and zoom, pipe and port layers, collapsible table
cards, result tray with earlier rolls, undo toasts, and a Collapse all
/ Expand all button
- assets/fonts/: Rokkitt and Atkinson Hyperlegible (SIL OFL)
- tests/test_roller.gd: headless checks for the model and roller
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:05:41 -06:00
extends SceneTree
## Headless checks for the data model and roller.
## Run: godot --headless --path . -s res://tests/test_roller.gd
var _failures : = 0
func _init ( ) - > void :
var board : = SampleBoard . create ( )
var rng : = RandomNumberGenerator . new ( )
rng . seed = 12345
var trinkets : = board . get_table ( " trinkets " )
_check ( trinkets . entries . size ( ) == 100 , " trinkets has 100 entries " )
_check ( trinkets . die_size ( ) == 100 , " trinkets rolls a d100 " )
var unique : = { }
for e in trinkets . entries :
unique [ e . text ] = true
_check ( unique . size ( ) == 100 , " trinket entries are unique " )
_check ( trinkets . num_label ( trinkets . entries [ 0 ] , 0 ) == " 01 " , " first trinket is numbered 01 " )
_check ( trinkets . num_label ( trinkets . entries [ 99 ] , 99 ) == " 00 " , " last trinket is numbered 00 " )
var wild : = board . get_table ( " wilderness " )
_check ( wild . is_ranged ( ) and wild . die_size ( ) == 100 , " wilderness is a ranged d100 " )
_check ( wild . range_problems ( ) == " " , " wilderness ranges have no gaps or overlaps " )
_check ( wild . num_label ( wild . entries [ 5 ] , 5 ) == " 96– 00 " , " last range reads 96– 00 " )
for e in wild . entries :
_check ( e . pipes . size ( ) == 1 , " range %s has exactly one pipe " % e . text )
# Range weighting: 01– 30 should come up about 30% of the time.
var counts : = { }
for i in 20000 :
var n : = Roller . roll ( board , " wilderness " , rng )
var text : String = ( n [ " entry " ] as TableEntry ) . text
counts [ text ] = counts . get ( text , 0 ) + 1
var share : = float ( counts . get ( " Travelers on the road " , 0 ) ) / 20000.0
_check ( absf ( share - 0.30 ) < 0.02 , " 01– 30 rolls about 30 %% of the time (got %.3f ) " % share )
var rare : = float ( counts . get ( " An odd find " , 0 ) ) / 20000.0
_check ( absf ( rare - 0.05 ) < 0.01 , " 96– 00 rolls about 5 %% of the time (got %.3f ) " % rare )
# Chains follow pipes.
var reached : = false
for i in 500 :
var n : = Roller . roll ( board , " wilderness " , rng )
if Roller . reaches ( n , " trinkets " ) :
reached = true
_check ( Roller . flatten ( n , [ ] ) . size ( ) == 2 , " wilderness → trinkets chain has two steps " )
break
_check ( reached , " wilderness can reach trinkets " )
# Gaps and overlaps are reported.
wild . entries [ 1 ] . range_lo = 35
_check ( wild . range_problems ( ) == " No result for 31– 34. " , " gap reported: %s " % wild . range_problems ( ) )
wild . entries [ 1 ] . range_lo = 25
_check ( wild . range_problems ( ) == " 25– 30 matches more than one result. " , " overlap reported: %s " % wild . range_problems ( ) )
wild . entries [ 1 ] . range_lo = 31
var n_gap : = RollTable . new ( " g " , " Gappy " )
var only : = TableEntry . new ( " e1 " , " Low " )
only . has_range = true
only . range_lo = 1
only . range_hi = 50
n_gap . entries . append ( only )
var stops : = 0
for i in 200 :
var b2 : = TowerBoard . new ( )
b2 . tables . append ( n_gap )
if Roller . roll ( b2 , " g " , rng ) . has ( " stop " ) :
stops += 1
_check ( stops > 50 and stops < 150 , " rolls into a gap stop with a message ( %d /200) " % stops )
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
# A self-pipe stops at the action limit (docs/LOGIC.md §7) instead of looping forever.
Build the pipe-board app in Godot
Tables are cards on a felt board, joined by copper pipes that carry a
roll from one table to the next. Play mode rolls with a flicker and a
bead down each pipe; Build mode edits names, results, ranges and pipes.
- core/: data model (RollTable, TableEntry, TowerBoard), sample board
with a d100 table of 100 trinkets and a weighted d100 range table,
and a Roller with a depth limit
- ui/: board with pan and zoom, pipe and port layers, collapsible table
cards, result tray with earlier rolls, undo toasts, and a Collapse all
/ Expand all button
- assets/fonts/: Rokkitt and Atkinson Hyperlegible (SIL OFL)
- tests/test_roller.gd: headless checks for the model and roller
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:05:41 -06:00
var loop : = RollTable . new ( " loop " , " Loop " )
var again : = TableEntry . new ( " e1 " , " Again " )
again . pipes . append ( " loop " )
loop . entries . append ( again )
var b3 : = TowerBoard . new ( )
b3 . tables . append ( loop )
var steps : = Roller . flatten ( Roller . roll ( b3 , " loop " , rng ) , [ ] )
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
_check ( steps . size ( ) == Roller . MAX_ACTIONS + 1 and str ( steps [ steps . size ( ) - 1 ] [ " text " ] ) == Roller . limit_text ( ) , " self-pipe stops at the action limit ( %d steps) " % steps . size ( ) )
Build the pipe-board app in Godot
Tables are cards on a felt board, joined by copper pipes that carry a
roll from one table to the next. Play mode rolls with a flicker and a
bead down each pipe; Build mode edits names, results, ranges and pipes.
- core/: data model (RollTable, TableEntry, TowerBoard), sample board
with a d100 table of 100 trinkets and a weighted d100 range table,
and a Roller with a depth limit
- ui/: board with pan and zoom, pipe and port layers, collapsible table
cards, result tray with earlier rolls, undo toasts, and a Collapse all
/ Expand all button
- assets/fonts/: Rokkitt and Atkinson Hyperlegible (SIL OFL)
- tests/test_roller.gd: headless checks for the model and roller
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 12:05:41 -06:00
# JSON round trip keeps everything.
var copy : = TowerBoard . new ( )
_check ( copy . load_json ( board . to_json ( ) ) , " board JSON loads back " )
_check ( copy . to_json ( ) == board . to_json ( ) , " board JSON round-trips unchanged " )
_check ( copy . get_table ( " trinkets " ) . collapsed , " collapsed state is saved " )
# Removing a table removes pipes into it.
copy . remove_table ( " loot " )
var dangling : = false
for t in copy . tables :
for e in t . entries :
if e . pipes . has ( " loot " ) :
dangling = true
_check ( not dangling and copy . get_table ( " loot " ) == null , " removing a table removes pipes into it " )
print ( " %s : %d failure(s) " % [ " PASS " if _failures == 0 else " FAIL " , _failures ] )
quit ( 1 if _failures else 0 )
func _check ( ok : bool , what : String ) - > void :
if not ok :
_failures += 1
print ( " ✗ " , what )