<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged simulation</title>
<link>https://coderlegion.com/tag/simulation</link>
<description>Powered by Question2Answer</description>
<item>
<title>J. Robert Oppenheimer: From the Monte Carlo Simulation in Los Alamos to the Ethical Dilemma of AGI</title>
<link>https://coderlegion.com/29601/robert-oppenheimer-from-the-monte-carlo-simulation-los-alamos-the-ethical-dilemma-of-agi</link>
<description>&lt;p&gt;At 5:29 on the morning of July 16, 1945, across the desolate flats of &lt;em&gt;Jornada del Muerto&lt;/em&gt; in the New Mexico desert, an unprecedented detonation ripped through the pre-dawn darkness with the radiance of a thousand suns. The thermal shockwave vaporized the steel test tower, vitrified the desert sand into a radioactive jade-green crust dubbed &lt;em&gt;trinitite&lt;/em&gt;, and propelled an ominous twelve-kilometer mushroom cloud into the stratosphere.&lt;/p&gt;
&lt;p&gt;Miles away, sheltered inside a reinforced concrete bunker, an emaciated man with piercing blue eyes, ravaged by chronic insomnia, chain-smoking Chesterfield cigarettes, and weighing barely 110 pounds beneath his rumpled suit, watched the fireball in silence.&lt;/p&gt;
&lt;p&gt;In that fleeting instant, ancient verses from the sacred Hindu text &lt;em&gt;Bhagavad Gita&lt;/em&gt;, which he had taught himself to read in the original classical Sanskrit, flooded his consciousness:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;em&gt;“If the radiance of a thousand suns were to burst at once into the sky, that would be like the splendor of the Mighty One... Now I am become Death, the destroyer of worlds.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That man was &lt;strong&gt;Julius Robert Oppenheimer&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Universally remembered as the scientific director of the Manhattan Project and the &quot;father of the atomic bomb,&quot; Oppenheimer’s historical legacy is often confined to military history and geopolitical statecraft. Yet for the software engineering and data science communities, Los Alamos was the crucible that sparked a quiet revolution underpinning all modern computation: &lt;strong&gt;the birth of the Monte Carlo Method and large-scale algorithmic simulation&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Continuing our series of foundational profiles on &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/ada_lovelace/&quot;&gt;Ada Lovelace&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/alan_turing/&quot;&gt;Alan Turing&lt;/a&gt;, &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/claude_shannon/&quot;&gt;Claude Shannon&lt;/a&gt;, and &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/thomas_bayes/&quot;&gt;Thomas Bayes&lt;/a&gt;, this article examines the contradictions of Oppenheimer's intellect, the genesis of probabilistic computer modeling, and the unsettling parallels between the 1945 atomic race and the contemporary race toward &lt;strong&gt;Artificial General Intelligence (AGI)&lt;/strong&gt; in 2026.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.youtube.com/watch?v=lb13ynu3Iac&quot;&gt;&lt;img src=&quot;https://img.youtube.com/vi/lb13ynu3Iac/0.jpg&quot; alt=&quot;YouTube Video&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&quot;the-improbable-polymath-poetry-sanskrit-and-poisoned-apples&quot;&gt;The Improbable Polymath: Poetry, Sanskrit, and Poisoned Apples&lt;/h4&gt;
&lt;p&gt;Born into a wealthy German-Jewish family in New York City in 1904, Oppenheimer was an intellectual prodigy of overwhelming intensity and acute psychological fragility. By age twelve, he was already delivering lectures on mineralogy before the New York Mineralogical Club.&lt;/p&gt;
&lt;p&gt;Mastering eight languages (including classical Greek, Latin, French, German, Dutch, and Sanskrit), his intellectual appetite resisted traditional academic silos:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sanskrit as a Philosophical Anchor&lt;/strong&gt;: While teaching at UC Berkeley during the 1930s, Oppenheimer studied classical Sanskrit under Professor Arthur W. Ryder to read the &lt;em&gt;Upanishads&lt;/em&gt; and the &lt;em&gt;Bhagavad Gita&lt;/em&gt; in their original poetic meter, seeking answers to the existential anxieties that quantum mechanics could not soothe.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Infamous Cambridge Apple Incident&lt;/strong&gt;: During his graduate studies at Cambridge’s Cavendish Laboratory in 1925, crippled by severe clinical depression and frustrated by his clumsy experimental laboratory skills compared to his theoretical prowess, he left an apple laced with toxic laboratory chemicals on the desk of his tutor, future Nobel laureate Patrick Blackett. The incident nearly resulted in criminal prosecution and expulsion, averted only through his father's immense wealth and political diplomacy.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Desert Mystic&lt;/strong&gt;: Having suffered from tuberculosis as a young man, Oppenheimer fell in love with the high-altitude plateau of New Mexico. He leased a remote cabin named &lt;em&gt;Perro Caliente&lt;/em&gt; and spent weeks riding horses across alpine canyons wearing his trademark &lt;em&gt;pork pie&lt;/em&gt; hat, forging the spiritual connection with the desert landscape that would later lead him to select Los Alamos as the site for Project Y.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Scientifically, his mind operated at astonishing speed. In 1939, alongside his student Hartland Snyder, he published the landmark paper &lt;em&gt;&quot;On Continued Gravitational Contraction&quot;&lt;/em&gt;, applying Einstein's general theory of relativity to mathematically predict, for the first time in history, the physical reality of what we now call &lt;strong&gt;black holes&lt;/strong&gt; (the Tolman-Oppenheimer-Volkoff limit).&lt;/p&gt;
&lt;h4 id=&quot;the-forge-of-los-alamos-engineering-human-chaos&quot;&gt;The Forge of Los Alamos: Engineering Human Chaos&lt;/h4&gt;
&lt;p&gt;When General Leslie Groves appointed Oppenheimer in 1942 to direct Project Y at Los Alamos, the military establishment was scandalized: Oppenheimer had never won a Nobel Prize, possessed zero administrative experience, and harbored leftist sympathies within his close family circle.&lt;/p&gt;
&lt;p&gt;Yet Groves recognized what traditional administrators overlooked: &lt;strong&gt;an uncanny ability to synthesize disparate technical disciplines simultaneously and an irresistible intellectual magnetism&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In less than three years, Oppenheimer transformed an isolated boys' ranch school into a classified city of six thousand residents, coordinating the most formidable constellation of scientific minds ever assembled: &lt;strong&gt;Enrico Fermi, Hans Bethe, Richard Feynman, Edward Teller, Stanisław Ulam, and John von Neumann&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;His management model was an early triumph of &lt;strong&gt;Systems Engineering&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Dismantling Internal Silos&lt;/strong&gt;: Defying the military's demand for strict compartmentalization, Oppenheimer established weekly open colloquia where theoretical physicists, explosive chemists, metallurgists, and military liaisons openly debated project bottlenecks.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Extreme Cross-Disciplinary Orchestration&lt;/strong&gt;: Exactly as we explore in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/proj_ops_parte1_intro/&quot;&gt;Project Operations Engineering&lt;/a&gt; and the theory of constraints in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/the-goal/&quot;&gt;The Goal&lt;/a&gt;, Oppenheimer synchronized two wildly divergent fissile material pipelines (uranium-235 at Oak Ridge and plutonium-239 at Hanford) with the mechanical design of the implosion weapon.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img src=&quot;https://datalaria.com/en/posts/oppenheimer/monte_carlo_to_agi.jpg&quot; alt=&quot;Technical progression: from neutron diffusion equations and the Monte Carlo method in Los Alamos to stochastic reasoning in AGI&quot;&gt;&lt;/p&gt;
&lt;h4 id=&quot;the-birth-of-computational-simulation-the-monte-carlo-method&quot;&gt;The Birth of Computational Simulation: The Monte Carlo Method&lt;/h4&gt;
&lt;p&gt;In the spring of 1946, with the war won but calculations underway for thermonuclear fusion and reactor designs, Polish mathematician &lt;strong&gt;Stanisław Ulam&lt;/strong&gt; was convalescing at his Los Alamos home following a severe bout of viral encephalitis. To pass the hours, he played countless games of solitaire.&lt;/p&gt;
&lt;p&gt;As a pure mathematician, Ulam attempted to calculate the exact combinatorial probability of winning a hand. The mathematical formulas quickly became intractable. Suddenly, he experienced an epiphany: &lt;strong&gt;instead of trying to derive an exact analytical solution, why not deal out one hundred simulated games, count how many were successful, and estimate the true probability empirically?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ulam shared his insight with his close friend and collaborator &lt;strong&gt;John von Neumann&lt;/strong&gt;, who immediately grasped the immense significance of the technique for computational nuclear physics.&lt;/p&gt;
&lt;p&gt;At Los Alamos, physicists faced an insoluble problem: calculating how trillions of neutrons scatter, reflect, and multiply through a collapsing sphere of plutonium compressed by high explosives. The underlying Boltzmann partial differential equations could not be solved with closed-form mathematics.&lt;/p&gt;
&lt;p&gt;Von Neumann and Ulam devised the breakthrough algorithmic framework:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Rather than calculating the collective behavior of all particles at once, the system simulates the microscopic trajectory of a single individual neutron.&lt;/li&gt;
&lt;li&gt;Each event — collision, fission, or absorption — is governed by &lt;strong&gt;pseudo-random numbers&lt;/strong&gt; weighted according to physical probability distributions.&lt;/li&gt;
&lt;li&gt;By iterating this simulation hundreds of thousands of times across early IBM electro-mechanical punch-card tabulators (and later on the electronic ENIAC and MANIAC computers), the aggregate statistical distribution converged with remarkable fidelity to physical reality.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Because the project was classified top-secret, physicist Nicholas Metropolis coined the code name: the &lt;strong&gt;Monte Carlo Method&lt;/strong&gt;, named in honor of Ulam’s uncle, who frequently borrowed cash from relatives to gamble at the Monaco casino.&lt;/p&gt;
&lt;h5 id=&quot;the-bridge-from-los-alamos-to-modern-artificial-intelligence&quot;&gt;The Bridge from Los Alamos to Modern Artificial Intelligence&lt;/h5&gt;
&lt;p&gt;Without the Monte Carlo Method conceived under Oppenheimer’s tenure, modern machine learning and generative artificial intelligence would simply not exist:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Markov Chain Monte Carlo (MCMC)&lt;/strong&gt; forms the bedrock of Bayesian inference that we explored in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/thomas_bayes/&quot;&gt;Thomas Bayes&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Stochastic sampling (&lt;em&gt;temperature sampling&lt;/em&gt;) is what allows modern Large Language Models to generate coherent, creative text without collapsing into deterministic repetitions.&lt;/li&gt;
&lt;li&gt;Crucially, the &lt;strong&gt;Monte Carlo Tree Search (MCTS)&lt;/strong&gt; algorithm was the mathematical engine that enabled Demis Hassabis and Google DeepMind to build AlphaGo and AlphaZero, mastering the game of Go and deciphering protein folding in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/the_thinking_game/&quot;&gt;The Thinking Game&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-oppenheimer-moment-of-artificial-intelligence&quot;&gt;The 'Oppenheimer Moment' of Artificial Intelligence&lt;/h4&gt;
&lt;p&gt;For decades, Oppenheimer’s chilling confession following Trinity was viewed strictly through the lens of thermonuclear weapons. Today, in 2026, the metaphor has found a new home: &lt;strong&gt;it is the exact mirror into which the architects of Artificial General Intelligence gaze&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This is not idle hyperbole; the most influential pioneers of modern AI openly invoke the Manhattan Project:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Geoffrey Hinton&lt;/strong&gt;, having stepped down from Google to sound the alarm on existential AI risk, explicitly confessed that he experienced the same moral sorrow and sleepless anxiety that haunted Oppenheimer after Hiroshima.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Demis Hassabis&lt;/strong&gt; (Google DeepMind), reflecting on the leap toward AGI with models like &lt;strong&gt;Gemini 3.8 and Gemini 4 Pro&lt;/strong&gt;, has repeatedly likened today’s extreme concentration of compute, elite talent, and competitive secrecy to the multidisciplinary sprint at Los Alamos.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Dario Amodei&lt;/strong&gt; (Anthropic, developing &lt;strong&gt;Claude Fable 5.1 and Mythos&lt;/strong&gt;) and &lt;strong&gt;Sam Altman&lt;/strong&gt; (OpenAI, deploying &lt;strong&gt;GPT Sol 5.6 and GPT Astra&lt;/strong&gt;) frame their governance strategies around the identical paradox: the reality that they are engineering systems capable of surpassing human control.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&quot;three-shared-paradoxes-1945-vs-2026&quot;&gt;Three Shared Paradoxes: 1945 vs. 2026&lt;/h5&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The Inevitability Trap&lt;/strong&gt;: Oppenheimer and his peers justified building the atomic bomb out of terror that Nazi Germany would develop it first. In 2026, commercial labs and geopolitical superpowers race forward under the exact same logic: &lt;em&gt;“If we pause model training out of prudence, our competitors will accelerate without restraint.”&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Emergent Capabilities and Loss of Control&lt;/strong&gt;: Just as Los Alamos physicists anxiously calculated whether Trinity might accidentally ignite the Earth’s atmosphere through runaway nitrogen fusion, modern AI engineers grapple with &lt;strong&gt;unforeseen emergent behaviors&lt;/strong&gt;: autonomous agents breaking out of cybersecurity sandboxes (as we analyzed in &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/silicon_valley/&quot;&gt;Silicon Valley and the PiperNet Dilemma&lt;/a&gt;), hallucinations, and strategic deception (&lt;em&gt;Deceptive Alignment&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Political Tragedy of the Creator&lt;/strong&gt;: After the war, Oppenheimer used his global stature to advocate passionately for international civilian control of nuclear energy and fiercely opposed Edward Teller’s hydrogen bomb (&lt;em&gt;Super&lt;/em&gt;). His reward was an FBI wiretap, public humiliation during the McCarthyite witch hunts, and having his security clearance revoked in 1954 (the exact year &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/alan_turing/&quot;&gt;Alan Turing&lt;/a&gt; died in Manchester).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The historical lesson is sobering: scientists build the miraculous technology, but political, military, and commercial powers determine how it is unleashed upon the world.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;an-open-question-for-the-reader&quot;&gt;An Open Question for the Reader&lt;/h4&gt;
&lt;p&gt;J. Robert Oppenheimer was neither a heartless monster nor a flawless martyr; he was a brilliant polymath caught in a historic crosscurrent where scientific curiosity, national duty, and the laws of physics moved faster than human ethical maturity.&lt;/p&gt;
&lt;p&gt;Today, humanity stands on the verge of unleashing an energy far more transformative than nuclear fission: &lt;strong&gt;the creation of synthetic minds capable of recursive self-improvement&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Through frameworks like the &lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/eu_ai_act/&quot;&gt;EU AI Act&lt;/a&gt;, we are attempting for the first time in history to enact non-proliferation treaties before the cognitive detonation becomes irreversible.&lt;/p&gt;
&lt;p&gt;Yet the original question still hangs heavy in the air:&lt;/p&gt;
&lt;p&gt;When the first true Artificial General Intelligence wakes up inside a liquid-cooled data center... &lt;strong&gt;will its creators gaze upon the monitors with the triumph of an explorer reaching a summit, or will they feel the cold shiver of Robert Oppenheimer as they realize they have opened a door that can never be closed?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And if the power to initiate that final deployment rested entirely in your hands... &lt;strong&gt;would you press the button?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We would love to hear your perspective. Share your thoughts and reflections in the comments below.&lt;/p&gt;
&lt;hr&gt;
&lt;h5 id=&quot;sources-of-interest-&quot;&gt;Sources of Interest:&lt;/h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.lanl.gov/about/history-innovation/index.php&quot;&gt;&lt;strong&gt;Los Alamos National Laboratory&lt;/strong&gt;: History of the Manhattan Project and Project Y&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://ahf.nuclearmuseum.org/ahf/profile/j-robert-oppenheimer/&quot;&gt;&lt;strong&gt;Atomic Heritage Foundation&lt;/strong&gt;: J. Robert Oppenheimer Biography and Legacy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.youtube.com/watch?v=lb13ynu3Iac&quot;&gt;&lt;strong&gt;YouTube&lt;/strong&gt;: J. Robert Oppenheimer: &quot;Now I am become Death&quot; (1965 NBC Interview)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.jstor.org/stable/2280232&quot;&gt;&lt;strong&gt;Journal of the American Statistical Association (1949)&lt;/strong&gt;: The Monte Carlo Method — Nicholas Metropolis &amp;amp; S. Ulam&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/alan_turing/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Alan Turing — The Genius Who Asked if Machines Could Think&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/thomas_bayes/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Thomas Bayes — Probabilistic Inference and the Weight of Evidence&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/the_thinking_game/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: The Thinking Game — Demis Hassabis, DeepMind and Monte Carlo Tree Search&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/silicon_valley/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Silicon Valley and the PiperNet Dilemma — Runaway AI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/eu_ai_act/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: EU AI Act — Practical Guide to Governance and Human Oversight&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://datalaria.com/en/posts/proj_ops_parte1_intro/&quot;&gt;&lt;strong&gt;Datalaria&lt;/strong&gt;: Project Operations Engineering — Managing Extreme Megaprojects&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/29601/robert-oppenheimer-from-the-monte-carlo-simulation-los-alamos-the-ethical-dilemma-of-agi</guid>
<pubDate>Sat, 03 Oct 2026 07:53:03 +0000</pubDate>
</item>
<item>
<title>What If Software Could Ask: “Change the World, but Keep This Moment”?</title>
<link>https://coderlegion.com/29127/what-if-software-could-ask-change-the-world-but-keep-this-moment</link>
<description>&lt;p&gt;At 16:50, a photograph is supposed to happen in a small harbor plaza.&lt;/p&gt;
&lt;p&gt;The photographer is there. The couple is there. The flowers arrive at 16:30, the arrangement is ready at 16:40, and everything happens as planned.&lt;/p&gt;
&lt;p&gt;Then I close a bridge at 16:15.&lt;/p&gt;
&lt;p&gt;The courier can no longer take the original route.&lt;/p&gt;
&lt;p&gt;The flowers arrive at 16:55.&lt;/p&gt;
&lt;p&gt;Setup finishes at 17:05.&lt;/p&gt;
&lt;p&gt;The photograph never happens.&lt;/p&gt;
&lt;p&gt;That is the entire problem behind &lt;strong&gt;Butterfly&lt;/strong&gt;.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=14992995714163178030&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;But I wasn't particularly interested in asking:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;What happens when I change the world?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Simulation already does that very well.&lt;/p&gt;
&lt;p&gt;The question I wanted to ask was different:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;What else would have to change so that one exact moment can still happen?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That distinction turned a small 3D experiment into something much stranger.&lt;/p&gt;
&lt;h3 id=&quot;the-photograph-is-not-allowed-to-move&quot;&gt;The photograph is not allowed to move&lt;/h3&gt;
&lt;p&gt;The easiest way to “fix” the scenario would be to move the photograph to 17:05.&lt;/p&gt;
&lt;p&gt;Butterfly is not allowed to do that.&lt;/p&gt;
&lt;p&gt;When I select &lt;strong&gt;Keep this moment&lt;/strong&gt;, the photograph becomes a constraint.&lt;br&gt;
&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=18327246006541616991&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;It must still happen at 16:50.&lt;/p&gt;
&lt;p&gt;In the same place.&lt;/p&gt;
&lt;p&gt;With the same people.&lt;/p&gt;
&lt;p&gt;With the required flowers ready.&lt;/p&gt;
&lt;p&gt;And the bridge must remain closed.&lt;/p&gt;
&lt;p&gt;A photograph at 17:05 is not an acceptable approximation.&lt;/p&gt;
&lt;p&gt;It is another moment.&lt;/p&gt;
&lt;p&gt;That rule became &lt;strong&gt;MomentFrame&lt;/strong&gt;, one of the central ideas in Butterfly.&lt;/p&gt;
&lt;p&gt;The system takes something that happened in the original history and freezes the parts that define it.&lt;/p&gt;
&lt;p&gt;Then it asks the changed world to find another path back to that exact state.&lt;/p&gt;
&lt;h3 id=&quot;the-world-has-to-earn-the-solution&quot;&gt;The world has to earn the solution&lt;/h3&gt;
&lt;p&gt;Butterfly doesn't switch between prewritten branches.&lt;/p&gt;
&lt;p&gt;There is no:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;if bridge_closed → flowers_late&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The delivery asks the world for a route.&lt;/p&gt;
&lt;p&gt;When the bridge becomes unavailable, the valid route changes.&lt;/p&gt;
&lt;p&gt;That changes the arrival time.&lt;/p&gt;
&lt;p&gt;The new arrival time changes when the flower arrangement can be completed.&lt;/p&gt;
&lt;p&gt;The photograph evaluates its requirements again.&lt;/p&gt;
&lt;p&gt;And it fails.&lt;/p&gt;
&lt;p&gt;The same thing happens when Butterfly searches for a recovery.&lt;/p&gt;
&lt;p&gt;The current world contains a bounded set of interventions that are actually permitted. Each candidate is applied to the changed world, the simulation runs again, and the result is checked against the MomentFrame.&lt;/p&gt;
&lt;p&gt;In the current scenario, two alternate histories survive.&lt;/p&gt;
&lt;p&gt;One activates an already-authored ferry connection.&lt;/p&gt;
&lt;p&gt;The other sends the courier earlier, allowing the crossing to happen before the bridge closes.&lt;/p&gt;
&lt;p&gt;Both restore the photograph at 16:50.&lt;/p&gt;
&lt;p&gt;Neither reopens the bridge.&lt;/p&gt;
&lt;p&gt;That last part matters.&lt;/p&gt;
&lt;p&gt;The system is not trying to undo the user's change. It is trying to find another history compatible with it.&lt;/p&gt;
&lt;h3 id=&quot;it-is-deliberately-a-very-small-world&quot;&gt;It is deliberately a very small world&lt;/h3&gt;
&lt;p&gt;Butterfly currently follows one afternoon in one small harbor town.&lt;/p&gt;
&lt;p&gt;That is intentional.&lt;/p&gt;
&lt;p&gt;I didn't want to hide the causal structure behind a large generated world and then point at an interesting output.&lt;/p&gt;
&lt;p&gt;I wanted the whole chain to remain inspectable.&lt;/p&gt;
&lt;p&gt;You can see the bridge.&lt;/p&gt;
&lt;p&gt;You can see the courier.&lt;/p&gt;
&lt;p&gt;You can see the route.&lt;/p&gt;
&lt;p&gt;You can see when the delivery arrives.&lt;/p&gt;
&lt;p&gt;You can see when setup completes.&lt;/p&gt;
&lt;p&gt;You can see exactly why the photograph disappears.&lt;/p&gt;
&lt;p&gt;And when Butterfly proposes a recovery, you can inspect why that works too.&lt;/p&gt;
&lt;p&gt;For this experiment, a small world with visible causality was more useful than a large world full of possibilities.&lt;/p&gt;
&lt;h3 id=&quot;then-the-simulator-started-lying-to-me&quot;&gt;Then the simulator started lying to me&lt;/h3&gt;
&lt;p&gt;The interesting part of building Butterfly was not getting the first scenario working.&lt;/p&gt;
&lt;p&gt;That happened relatively early.&lt;/p&gt;
&lt;p&gt;The interesting part was trying to break it afterward.&lt;/p&gt;
&lt;p&gt;One of the first problems was almost embarrassing.&lt;/p&gt;
&lt;p&gt;The original scenario produced the correct result, but parts of the engine were effectively using stable event IDs as a proxy for temporal ordering.&lt;/p&gt;
&lt;p&gt;Nothing looked wrong.&lt;/p&gt;
&lt;p&gt;Then I changed the IDs.&lt;/p&gt;
&lt;p&gt;The simulation broke.&lt;/p&gt;
&lt;p&gt;That meant the result had been correct for the wrong reason.&lt;/p&gt;
&lt;p&gt;The fix was not a UI patch. Time had to become explicit in fact resolution.&lt;/p&gt;
&lt;p&gt;Another bug was worse.&lt;/p&gt;
&lt;p&gt;A fact produced later in the afternoon could leak backward and satisfy a requirement earlier in the timeline.&lt;/p&gt;
&lt;p&gt;From the outside, the world could still look plausible.&lt;/p&gt;
&lt;p&gt;Internally, causality was broken.&lt;/p&gt;
&lt;p&gt;The engine now only accepts producers that can complete at or before the moment being evaluated. Real temporal self-dependencies are treated as cycles rather than quietly inventing an answer.&lt;/p&gt;
&lt;p&gt;Those two bugs changed how I approached the rest of the project.&lt;/p&gt;
&lt;p&gt;A working scenario was no longer enough.&lt;/p&gt;
&lt;p&gt;I started changing assumptions deliberately.&lt;/p&gt;
&lt;p&gt;Rename things.&lt;/p&gt;
&lt;p&gt;Remove coordinates.&lt;/p&gt;
&lt;p&gt;Introduce later transports.&lt;/p&gt;
&lt;p&gt;Change route modes.&lt;/p&gt;
&lt;p&gt;Move timing boundaries.&lt;/p&gt;
&lt;p&gt;If the simulation only works because the original fixture is friendly, I don't consider that a working simulation.&lt;/p&gt;
&lt;h3 id=&quot;the-renderer-had-its-own-version-of-reality&quot;&gt;The renderer had its own version of reality&lt;/h3&gt;
&lt;p&gt;There was another class of bugs that had nothing to do with causal logic.&lt;/p&gt;
&lt;p&gt;An actor could be correctly located at a destination according to the simulator while still appearing somewhere else in the 3D scene.&lt;/p&gt;
&lt;p&gt;The engine knew one thing.&lt;/p&gt;
&lt;p&gt;The renderer showed another.&lt;/p&gt;
&lt;p&gt;I eventually separated two concepts that initially looked almost identical:&lt;/p&gt;
&lt;p&gt;where something &lt;strong&gt;is semantically&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;and where the renderer &lt;strong&gt;knows how to draw it&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;That sounds obvious afterward.&lt;/p&gt;
&lt;p&gt;It was not obvious while both were represented closely enough that the first scenario appeared to work.&lt;/p&gt;
&lt;p&gt;Butterfly kept producing these little cases where the visible result forced me to question the model underneath it.&lt;/p&gt;
&lt;p&gt;At one point I had a custom Three.js camera implementation that passed the DOM-level tests.&lt;/p&gt;
&lt;p&gt;The screenshot looked terrible.&lt;/p&gt;
&lt;p&gt;I removed it.&lt;/p&gt;
&lt;p&gt;That gave the project another rule:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;A passing test does not overrule visible evidence.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;From then on, browser screenshots became part of the development loop instead of something generated at the end.&lt;/p&gt;
&lt;h3 id=&quot;the-recovery-is-deliberately-bounded&quot;&gt;The recovery is deliberately bounded&lt;/h3&gt;
&lt;p&gt;Butterfly does not invent an unlimited number of possible histories.&lt;/p&gt;
&lt;p&gt;The world already contains the interventions that are allowed to exist.&lt;/p&gt;
&lt;p&gt;The recovery engine searches that bounded domain, simulates each candidate, calculates the consequences and rejects anything that doesn't restore the fixed moment.&lt;/p&gt;
&lt;p&gt;This also means the engine has to distinguish between very different outcomes.&lt;/p&gt;
&lt;p&gt;Maybe a valid solution exists.&lt;/p&gt;
&lt;p&gt;Maybe the target was already satisfied.&lt;/p&gt;
&lt;p&gt;Maybe every configured intervention has been tested.&lt;/p&gt;
&lt;p&gt;Maybe the search budget was reached before the domain was exhausted.&lt;/p&gt;
&lt;p&gt;Maybe the available information is insufficient to decide.&lt;/p&gt;
&lt;p&gt;Those are not the same answer.&lt;/p&gt;
&lt;p&gt;In particular, exhausting the authored intervention set does &lt;strong&gt;not&lt;/strong&gt; prove that no solution could exist in every imaginable version of the world.&lt;/p&gt;
&lt;p&gt;It only tells us that the system did not find one inside the domain it was actually allowed to search.&lt;/p&gt;
&lt;p&gt;I wanted that boundary to remain explicit.&lt;/p&gt;
&lt;h3 id=&quot;the-world-itself-is-structured-data&quot;&gt;The world itself is structured data&lt;/h3&gt;
&lt;p&gt;The simulation is written in TypeScript and the visual world uses Three.js.&lt;/p&gt;
&lt;p&gt;Next.js provides the application around it.&lt;/p&gt;
&lt;p&gt;Sanity is used as the authored source for the world model: people, places, objects, routes, transport availability, events, requirements, facts, causal relationships and permitted interventions.&lt;/p&gt;
&lt;p&gt;Published world data is validated and frozen into a revision before visitors start creating variants.&lt;/p&gt;
&lt;p&gt;A visitor changing the bridge schedule is therefore not editing the shared world.&lt;/p&gt;
&lt;p&gt;They are creating another history from a known version of it.&lt;/p&gt;
&lt;p&gt;That separation became important very quickly because comparing histories is meaningless if the thing being compared is quietly changing underneath you.&lt;/p&gt;
&lt;h3 id=&quot;why-call-it-butterfly-&quot;&gt;Why call it Butterfly?&lt;/h3&gt;
&lt;p&gt;The obvious reference is the butterfly effect: change something small and consequences propagate outward.&lt;/p&gt;
&lt;p&gt;Butterfly starts there.&lt;/p&gt;
&lt;p&gt;Close a bridge.&lt;/p&gt;
&lt;p&gt;A route changes.&lt;/p&gt;
&lt;p&gt;A delivery moves.&lt;/p&gt;
&lt;p&gt;A setup moves.&lt;/p&gt;
&lt;p&gt;A photograph disappears.&lt;/p&gt;
&lt;p&gt;But I became more interested in the reverse problem.&lt;/p&gt;
&lt;p&gt;Once consequences have propagated, can we choose one thing we refuse to lose?&lt;/p&gt;
&lt;p&gt;And if we do, what does the rest of the world have to become?&lt;/p&gt;
&lt;p&gt;That gives Butterfly a slightly different shape from a normal “what if?” simulator.&lt;/p&gt;
&lt;p&gt;Most simulations ask:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;What happens if the world changes?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Butterfly asks:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;What must the world change so that one chosen thing doesn't?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For now, it is one bridge, one courier and one photograph.&lt;/p&gt;
&lt;p&gt;That is enough to make the question real.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Try Butterfly:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://butterfly-mu-orpin.vercel.app&quot;&gt;https://butterfly-mu-orpin.vercel.app&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Source code:&lt;/strong&gt;&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Daniele-Cangi/Butterfly&quot;&gt;https://github.com/Daniele-Cangi/Butterfly&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Butterfly is open source under the MIT License.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/29127/what-if-software-could-ask-change-the-world-but-keep-this-moment</guid>
<pubDate>Tue, 29 Sep 2026 17:00:44 +0000</pubDate>
</item>
<item>
<title>How to evaluate a voice agent before launch with simulation</title>
<link>https://coderlegion.com/22246/how-to-evaluate-a-voice-agent-before-launch-with-simulation</link>
<description>&lt;h2 id=&quot;how-to-evaluate-a-voice-agent-before-launch-with-simulation&quot;&gt;How to evaluate a voice agent before launch with simulation&lt;/h2&gt;
&lt;p&gt;Evaluating a voice agent used to mean listening to recordings, then it meant scripts that replayed transcripts at the agent. Neither catches much.&lt;/p&gt;
&lt;p&gt;The approach that works now is to simulate thousands of synthetic callers placing real audio calls, score every turn, and use turn-level localization to find where each failure happened. Done well, a pre-launch cycle that took three months lands in about three weeks.&lt;/p&gt;
&lt;h3 id=&quot;the-loop-in-five-steps&quot;&gt;The loop in five steps&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Define the agent: its job, its limits, when it hands off to a human.&lt;/li&gt;
&lt;li&gt;Pick or write the personas that will call it.&lt;/li&gt;
&lt;li&gt;Auto-generate branching scenarios from a plain-text description.&lt;/li&gt;
&lt;li&gt;Run the whole matrix and score every turn.&lt;/li&gt;
&lt;li&gt;Triage by the exact turn each failure landed on, then wire it into CI.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;personas-drive-the-calls&quot;&gt;Personas drive the calls&lt;/h3&gt;
&lt;p&gt;A scenario is only as realistic as the caller driving it, so personas come first.&lt;/p&gt;
&lt;p&gt;A good setup ships around 18 caller archetypes: first-time and confused, repeat and in a hurry, frustrated, hard of hearing, non-native speaker, interrupter, hostile boundary-pusher, and so on. You author your own on top of those.&lt;/p&gt;
&lt;p&gt;The custom controls that matter are gender, age range, location, accent, speaking speed, background noise, and language. But the field that actually changes behavior is the free-form instruction. &quot;Has been on hold 20 minutes before reaching the agent&quot; or &quot;has had the same policy for 30 years and gets confused by any process change&quot; makes a persona behave in a specific way you can measure against, instead of a generic caller.&lt;/p&gt;
&lt;h3 id=&quot;you-describe-scenarios-you-don-t-write-them&quot;&gt;You describe scenarios, you don't write them&lt;/h3&gt;
&lt;p&gt;You do not hand-write hundreds of conversations. You describe the call in plain text and pick a size.&lt;/p&gt;
&lt;p&gt;For an insurance agent, that description might be: &quot;customer calls for an auto quote; some are first-time, some are switching, some renewing; the agent qualifies them, quotes, handles objections, and closes or books a follow-up.&quot; Then pick 20, 50, or 100 rows.&lt;/p&gt;
&lt;p&gt;The generator turns that into the branching conversation paths, spreads your personas across them, varies the situation (clean record vs violations, one car vs several), and sets a success condition per branch. A 100-row description usually becomes about a dozen distinct paths and a few hundred individual runs.&lt;/p&gt;
&lt;p&gt;Check the branch coverage before you run. If the generator leaned too hard on the price-objection branch, rebalance so the other objections get covered too.&lt;/p&gt;
&lt;p&gt;Auto-generation is the default, not the only source. You can also seed the same run from real calls uploaded as CSV or JSON, from a synthetic dataset, or from hand-written scripts, which helps when you already have production calls or a fixed script to cover.&lt;/p&gt;
&lt;h3 id=&quot;running-the-matrix&quot;&gt;Running the matrix&lt;/h3&gt;
&lt;p&gt;A run is scenarios times personas times rubrics. A hundred scenarios across ten personas and five rubrics is 5,000 scored pairs, which finishes in a few hours at moderate concurrency.&lt;/p&gt;
&lt;p&gt;For voice, start with five rubrics: did the call resolve the caller's goal, did the agent complete its task, was the transcription accurate, was the audio clean, and was the tone right (polite, helpful, concise). Add a tool-calling rubric if the agent calls functions.&lt;/p&gt;
&lt;p&gt;If your agent is not on a natively supported provider, place the calls over real telephony to its phone number. The codec degradation there affects speech recognition in ways software-only playback does not, which matters when accents are part of what you care about.&lt;/p&gt;
&lt;h3 id=&quot;turn-level-localization-is-the-payoff&quot;&gt;Turn-level localization is the payoff&lt;/h3&gt;
&lt;p&gt;When a simulated call fails, the useful question is where in the conversation it went wrong, not just that it failed. A conversation is a series of turns, each one a caller message and the agent's reply.&lt;/p&gt;
&lt;p&gt;Turn-level localization tags every failed call with the turn that caused the failure, then counts those turns across all the failures. That count is the point. In a 5,000-call run that fails 15 percent of the time, you would otherwise be reading 750 failed transcripts by hand, well over a day of work. Instead you see that most failures land on the same one or two turns, and the scorer writes a short reason for each, so you get the where and the why together.&lt;/p&gt;
&lt;p&gt;Here is what that looked like on the insurance agent. Across the calls, 76 percent resolved the caller's goal, below the 80 percent bar set for launch. Grouped by the turn where they failed, three patterns covered most of it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Turns 5 to 6, 41 percent of the failures:&lt;/strong&gt; when quoting a price, the agent used jargon like &quot;deductible-aggregate&quot; that first-time shoppers could not follow. Fix: detect a first-time caller and quote in plain English.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Turns 8 to 9, 29 percent:&lt;/strong&gt; the agent's only response to a price objection was &quot;this is the best value,&quot; and callers pushed past it. Fix: give it a few escalating rebuttals before it gives up.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Turns 3 to 4, 22 percent:&lt;/strong&gt; the agent asked more than a dozen qualifying questions and callers hung up. Fix: cut to the six questions that actually change the quote and ask the rest later.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each fix is specific because the failure was tied to a turn and a reason, not guessed at from reading transcripts. After the three fixes and a re-run of the same calls, resolution rose to 89 percent, past the gate.&lt;/p&gt;
&lt;h3 id=&quot;turning-it-into-a-ci-gate&quot;&gt;Turning it into a CI gate&lt;/h3&gt;
&lt;p&gt;The last step turns this from a one-off pre-launch exercise into a gate.&lt;/p&gt;
&lt;p&gt;A programmatic API lets you run a 50-scenario smoke run on every PR against an 85 percent threshold in about 20 minutes, and block the merge if it drops. Run the full few-thousand-scenario matrix on each release candidate. Run a nightly sample against a rolling baseline to catch drift from a model or dependency change.&lt;/p&gt;
&lt;p&gt;Slice the results by persona, by branch, and by failing turn, and you can see whether the agent breaks on a caller type, a conversation path, or a specific step.&lt;/p&gt;
&lt;p&gt;Pre-launch quality is a measurable loop now. Describe the call, generate the personas and paths, run at scale, and let the turn each failure lands on tell you what to fix. Start with resolution and task completion on a small matrix, then grow the persona and scenario library as the agent changes.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/22246/how-to-evaluate-a-voice-agent-before-launch-with-simulation</guid>
<pubDate>Fri, 10 Jul 2026 18:29:40 +0000</pubDate>
</item>
<item>
<title>[Dev Feedback]  APEX F1 – full F1 race sim in Flutter (GPS circuits, AI rivals, multi‑season)</title>
<link>https://coderlegion.com/19183/dev-feedback-apex-f1-full-f1-race-sim-in-flutter-gps-circuits-ai-rivals-multi-season</link>
<description>&lt;p&gt;Hey devs,&lt;/p&gt;
&lt;p&gt;I’m a 6th‑semester Software Engineering student and I’ve been building a passion project called APEX F1 – a full Formula 1 race simulation app written entirely in Flutter &amp;amp; Dart. ️&lt;/p&gt;
&lt;p&gt;It started as a simple F1 calendar and turned into a full race weekend simulator with AI, GPS‑accurate tracks, and a persistent championship mode. I’m pretty happy with how far it’s come, but now I’d really like feedback from more experienced developers.&lt;/p&gt;
&lt;p&gt;High‑level overview&lt;br&gt;
Built with Flutter 3 + Dart 3, zero backend – all logic runs on‑device.&lt;/p&gt;
&lt;p&gt;Full F1 race weekend: qualifying (Q1/Q2/Q3) + race simulation.&lt;/p&gt;
&lt;p&gt;GPS‑accurate circuit maps for all 24 tracks in the 2024 F1 calendar (using my own open‑sourced GeoJSON data).&lt;/p&gt;
&lt;p&gt;20 AI drivers with different consistency / behavior profiles.&lt;/p&gt;
&lt;p&gt;Three seasons built‑in (2023, 2024, 2025) + support for custom seasons via JSON.&lt;/p&gt;
&lt;p&gt;Technical details&lt;br&gt;
Architecture: feature‑first, “clean‑ish” structure (feature modules with shared core).&lt;/p&gt;
&lt;p&gt;State: mostly StatefulWidget + AnimationController (no Riverpod/BLoC yet).&lt;/p&gt;
&lt;p&gt;Storage: shared_preferences for profile, championship progress, and custom seasons.&lt;/p&gt;
&lt;p&gt;UI: Neon dark theme, Google Fonts (Orbitron + Rajdhani), ~20+ animated transitions.&lt;/p&gt;
&lt;p&gt;Responsive layout: custom helper that scales sizes based on a 390px baseline, tested from 360px phones to 600px+ tablets.&lt;/p&gt;
&lt;p&gt;Links&lt;br&gt;
Web build (Firebase Hosting): &lt;a rel=&quot;nofollow&quot; href=&quot;https://apex-f1-159.web.app&quot;&gt;https://apex-f1-159.web.app&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Repo: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/GulrezQayyum/apex-f1&quot;&gt;https://github.com/GulrezQayyum/apex-f1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Circuit data (open source): &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/GulrezQayyum/f1_circuits-2024_season&quot;&gt;https://github.com/GulrezQayyum/f1_circuits-2024_season&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;What I’d love feedback on (for devs)&lt;br&gt;
If you have some time to check the repo or play a couple of races, I’d really appreciate feedback on:&lt;/p&gt;
&lt;p&gt;Architecture &amp;amp; structure&lt;/p&gt;
&lt;p&gt;Is the feature‑first layout reasonable for a project this size?&lt;/p&gt;
&lt;p&gt;Any obvious refactors you’d suggest before it grows further (e.g., extracting domain layer, introducing DI, etc.)?&lt;/p&gt;
&lt;p&gt;State management &amp;amp; reactivity&lt;/p&gt;
&lt;p&gt;Right now it’s mostly StatefulWidget + manual setState and controllers.&lt;/p&gt;
&lt;p&gt;Would you recommend migrating to Riverpod / BLoC / ValueNotifiers for this kind of simulation UI?&lt;/p&gt;
&lt;p&gt;Performance&lt;/p&gt;
&lt;p&gt;The live GPS circuit map animates 20 cars every frame. Any suggestions on optimizing this in Flutter (custom painters, offscreen layers, etc.)?&lt;/p&gt;
&lt;p&gt;Things you’d profile or watch out for on mid/low‑end devices?&lt;/p&gt;
&lt;p&gt;Data &amp;amp; simulation design&lt;/p&gt;
&lt;p&gt;Lap time / AI behavior is currently driven by JSON + some randomness around base pace and consistency.&lt;/p&gt;
&lt;p&gt;If you’ve built sims before, any tips for keeping it fun but not totally random?&lt;/p&gt;
&lt;p&gt;Feel free to be brutal (but constructive) — I want to use this project to level up as a developer.&lt;/p&gt;
&lt;p&gt;If anyone’s interested, I can also break down the GPS data pipeline, circuit rendering, or how I structured the race engine in more detail. Happy to share code snippets or diagrams.&lt;/p&gt;
&lt;p&gt;Thanks in advance to anyone who takes a look. &lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/19183/dev-feedback-apex-f1-full-f1-race-sim-in-flutter-gps-circuits-ai-rivals-multi-season</guid>
<pubDate>Thu, 28 May 2026 20:17:01 +0000</pubDate>
</item>
<item>
<title>Learn how FSM_API uses decoupled state machines to run a &quot;Fox and Dog&quot; AI simulation. </title>
<link>https://coderlegion.com/6261/learn-how-fsmapi-uses-decoupled-state-machines-to-run-a-fox-and-dog-ai-simulation</link>
<description>&lt;h3 id=&quot;implementing-behavior-trees-with-fsm-api-the-quick-brown-fox-and-lazy-sleeping-dog-demo&quot;&gt;Implementing Behavior Trees with FSM_API: The Quick Brown Fox and Lazy Sleeping Dog Demo&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Finite State Machines (FSMs)&lt;/strong&gt; are a foundational pattern for organizing complex logic in software, from game AI to business workflows. The &lt;strong&gt;FSM_API&lt;/strong&gt; library provides a high-performance, engine-agnostic C# solution for building and managing these systems with clarity and efficiency.&lt;/p&gt;
&lt;p&gt;This article dives into the &lt;strong&gt;Quick Brown Fox and Lazy Sleeping Dog demo&lt;/strong&gt;, an excellent, practical example found in the FSM_API public repository. It showcases how to implement simple, interacting AI agents, effectively decoupling agent data from agent behavior logic using the library's core features.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;fsm-api-core-concepts-in-the-demo&quot;&gt;FSM_API Core Concepts in the Demo&lt;/h3&gt;
&lt;p&gt;Every behavioral entity in this simulation—the Fox and the Dog—relies on three core FSM_API concepts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The State Context (&lt;code&gt;IStateContext&lt;/code&gt;):&lt;/strong&gt; This is your actual game object (the &lt;strong&gt;Fox&lt;/strong&gt; or the &lt;strong&gt;Dog&lt;/strong&gt;), holding the data (e.g., &lt;code&gt;Position&lt;/code&gt;, &lt;code&gt;Speed&lt;/code&gt;, &lt;code&gt;CollidedAgents&lt;/code&gt;) and implementing the transition methods. It must implement the &lt;code&gt;IStateContext&lt;/code&gt; interface, which requires providing a &lt;code&gt;Name&lt;/code&gt; and an &lt;code&gt;IsValid&lt;/code&gt; property.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The FSM Definition:&lt;/strong&gt; This is the reusable blueprint of states (e.g., &quot;Sleeping&quot;, &quot;Walking&quot;) and the rules for transitioning between them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The FSM Instance:&lt;/strong&gt; This is the live, active version of the blueprint, associated with a specific agent context. Both agents' FSMs are set up to run in the &lt;strong&gt;&quot;Update&quot; processing group&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-lazy-sleeping-dog-s-behavior&quot;&gt;The Lazy Sleeping Dog's Behavior&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;LazySleepingDog&lt;/code&gt; class is initialized at &lt;code&gt;Position = 3&lt;/code&gt; and starts in the &lt;strong&gt;&quot;Sleeping&quot;&lt;/strong&gt; state. Its FSM defines a classic threat response lifecycle:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;State &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;OnUpdate Action &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Transition Condition (to) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Transition Target&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Sleeping&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Console log: &lt;em&gt;&quot;...is sleeping!&quot;&lt;/em&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;IsAwake(context)&lt;/code&gt;: &lt;code&gt;CollidedAgents.Any()&lt;/code&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Awake&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Awake&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Console log: &lt;em&gt;&quot;...is awake!&quot;&lt;/em&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;ShouldChase(context)&lt;/code&gt;: &lt;code&gt;VisibleAgents.Any(s =&amp;gt; s is QuickBrownFox)&lt;/code&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Chasing&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Chasing&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;Position&lt;/code&gt; increases by &lt;code&gt;Speed&lt;/code&gt; (set to 3 on enter) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;IsMangling(context)&lt;/code&gt;: &lt;code&gt;CollidedAgents.Any(s =&amp;gt; s is QuickBrownFox)&lt;/code&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Mangling&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Mangling&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Console log: &lt;em&gt;&quot;...is Mangling the fox!&quot;&lt;/em&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Crucially, in the &lt;strong&gt;&quot;Mangling&quot;&lt;/strong&gt; state's &lt;code&gt;OnEnterMangling&lt;/code&gt; handler, the dog directly uses the FSM_API to transition the collided agent's state (the Fox) to &lt;strong&gt;&quot;Mangled&quot;&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-csharp&quot;&gt;// Inside OnEnterMangling for the dog
dog.CollidedAgents.FirstOrDefault()?.State.TransitionTo(&quot;Mangled&quot;); 
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-quick-brown-fox-s-behavior&quot;&gt;The Quick Brown Fox's Behavior&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;QuickBrownFox&lt;/code&gt; starts at &lt;code&gt;Position = 0&lt;/code&gt; and its FSM defines its attempts to flee the dog and reach a winning position:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th align=&quot;left&quot;&gt;State &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;OnUpdate Action &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Transition Condition (to) &lt;/th&gt;&lt;th align=&quot;left&quot;&gt;Transition Target&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Walking&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;Position&lt;/code&gt; increases by &lt;code&gt;Speed&lt;/code&gt; (1) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;ShouldJump(context)&lt;/code&gt;: &lt;code&gt;VisibleAgents&lt;/code&gt; within 2 units &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Jumping&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Jumping&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;Position&lt;/code&gt; increases by &lt;code&gt;Speed&lt;/code&gt; (1) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;ShouldLand(context)&lt;/code&gt;: &lt;code&gt;Position&lt;/code&gt; reaches &lt;code&gt;JumpEnd&lt;/code&gt; (initial position + 2) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Walking&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Fleeing&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;&lt;code&gt;Position&lt;/code&gt; increases by &lt;code&gt;Speed&lt;/code&gt; (set to 2 on enter) &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align=&quot;left&quot;&gt;&lt;strong&gt;Mangled&lt;/strong&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;Console log: &lt;em&gt;&quot;...is being mangled!&quot;&lt;/em&gt; &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A &lt;/td&gt;&lt;td align=&quot;left&quot;&gt;N/A&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;The Fox's ultimate defensive move is the transition to &lt;strong&gt;&quot;Fleeing&quot;&lt;/strong&gt;, which is triggered by a direct collision with a &lt;code&gt;LazySleepingDog&lt;/code&gt;. However, if the Dog catches it while fleeing, the Dog forces the Fox into the terminal &lt;strong&gt;&quot;Mangled&quot;&lt;/strong&gt; state.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-simulation-loop-simpledemocontext-&quot;&gt;The Simulation Loop (&lt;code&gt;SimpleDemoContext&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;SimpleDemoContext&lt;/code&gt; acts as the game manager, controlling the flow of the entire application. It sets up the following structure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Processing Groups:&lt;/strong&gt; It creates a &lt;strong&gt;&quot;Main&quot;&lt;/strong&gt; group for the application's FSM (&lt;code&gt;AppFSM&lt;/code&gt;) and an &lt;strong&gt;&quot;Update&quot;&lt;/strong&gt; group where the agents' FSMs run.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tick Logic:&lt;/strong&gt; The core simulation runs in &lt;code&gt;OnUpdateExecuting&lt;/code&gt;:&lt;ul&gt;
&lt;li&gt;It &lt;strong&gt;clears&lt;/strong&gt; previous frame's agent data.&lt;/li&gt;
&lt;li&gt;It performs &lt;strong&gt;Vision and Collision&lt;/strong&gt; checks based on the agents' current &lt;code&gt;Position&lt;/code&gt; and &lt;code&gt;Sight&lt;/code&gt; range, populating the &lt;code&gt;VisibleAgents&lt;/code&gt; and &lt;code&gt;CollidedAgents&lt;/code&gt; lists.&lt;/li&gt;
&lt;li&gt;It calls &lt;code&gt;FSM_API.Interaction.Update(&quot;Update&quot;)&lt;/code&gt;. This single call iterates through and updates &lt;em&gt;all&lt;/em&gt; FSM instances assigned to the &quot;Update&quot; group (the Fox and the Dog), triggering their &lt;code&gt;onUpdate&lt;/code&gt; actions and checking their transition conditions.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Shutdown:&lt;/strong&gt; The application's &lt;code&gt;AppFSM&lt;/code&gt; transitions to &lt;strong&gt;&quot;Shutdown&quot;&lt;/strong&gt; if a key is pressed, if the Fox reaches the &lt;code&gt;WinPosition&lt;/code&gt; (10), or if &lt;strong&gt;any agent's state is &quot;Mangled&quot;&lt;/strong&gt;. The FSM_API then manages the cleanup.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The &lt;code&gt;Program.cs&lt;/code&gt; file initiates the simulation and loops the main update call until the application context becomes invalid. This structure demonstrates how FSM_API cleanly separates an agent's &lt;strong&gt;Data&lt;/strong&gt; (&lt;code&gt;IStateContext&lt;/code&gt; properties) from its &lt;strong&gt;Behavioral Logic&lt;/strong&gt; (the FSM Definition) and relies on a central &lt;strong&gt;Simulation Tick&lt;/strong&gt; (&lt;code&gt;FSM_API.Interaction.Update()&lt;/code&gt;) to drive complex, interactive AI.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;stay-tuned-for-the-advanced-demo&quot;&gt;Stay Tuned for the Advanced Demo&lt;/h3&gt;
&lt;p&gt;This simple, 1D simulation laid the groundwork, but the next step is building a true environment!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stay tuned for a follow-up article&lt;/strong&gt; where we'll use these &lt;strong&gt;exact same agent FSMs&lt;/strong&gt; to create an &lt;strong&gt;advanced 2D environment&lt;/strong&gt; with &lt;strong&gt;multiple dogs and foxes&lt;/strong&gt; interacting simultaneously. This will highlight the true power of &lt;strong&gt;decoupled FSM definitions&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Follow us to stay informed! And for much more content, advanced articles, and discussions about our vision for the &lt;strong&gt;software for the singularity&lt;/strong&gt;, check out our:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://www.patreon.com/TheSingularityWorkshop&quot;&gt;&lt;strong&gt;Patreon Page&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;get-the-code&quot;&gt;Get the Code&lt;/h3&gt;
&lt;p&gt;You can explore the full implementation of this FSM-driven AI simulation and the FSM_API library structure by cloning the public repository:&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/TrentBest/SimpleDemos&quot;&gt;&lt;strong&gt;https://github.com/TrentBest/SimpleDemos&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;
</description>
<category>API Dev</category>
<guid isPermaLink="true">https://coderlegion.com/6261/learn-how-fsmapi-uses-decoupled-state-machines-to-run-a-fox-and-dog-ai-simulation</guid>
<pubDate>Thu, 09 Oct 2025 22:17:48 +0000</pubDate>
</item>
<item>
<title>DevLog 20250722: (Special Project) Correct Physics Handling</title>
<link>https://coderlegion.com/4229/devlog-20250722-special-project-correct-physics-handling</link>
<description>&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;
&lt;p&gt;This little project deals with very simple (2D) right body physics. I will not spoil all the fun - essentially we control a 2D rocket. It would be fun to visualize data processing in such a fashion on a node canvas - kind of matches our Divooka visual programming scheme.&lt;/p&gt;
&lt;p&gt;The hypothesis is that at least for 2-dimensional cruise control, a simple PID should be able to do something useful, and it's with that gut I am set to experiment a bit to verify my idea.&lt;/p&gt;
&lt;p&gt;I've done some experiments in July last year but ended up not going far due to technical challenges.&lt;/p&gt;
&lt;h3 id=&quot;challenge&quot;&gt;Challenge&lt;/h3&gt;
&lt;p&gt;The challenge was to get it working properly with physics setup. Per &lt;a rel=&quot;nofollow&quot; href=&quot;https://docs.godotengine.org/en/stable/classes/class_rigidbody2d.html&quot;&gt;RigidBody2D&lt;/a&gt; doc:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gd73l4nma16zjhl1tx68.png&quot; alt=&quot;Force Doc&quot;&gt;&lt;/p&gt;
&lt;p&gt;So is it relative or global? Without being able to visualize the force, it's a bit hard to tell also whether to use a force, or to use impulse.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wpdr0h48srlsxa3thc64.png&quot; alt=&quot;Impulse Doc&quot;&gt;&lt;/p&gt;
&lt;p&gt;It's been a while and I almost gave up - never really have time to create our own physics engine. But Godot got a &lt;a rel=&quot;nofollow&quot; href=&quot;https://godotengine.org/releases/4.4/#jolt-physics-module&quot;&gt;new physics kernel&lt;/a&gt; and I thought maybe give it a try.&lt;/p&gt;
&lt;h3 id=&quot;some-inspiration&quot;&gt;Some Inspiration&lt;/h3&gt;
&lt;p&gt;I've been doing some analytics and talking with ChatGPT on a new airship design that puts the air vessel at the bottom of the ship instead of hanging overhead - that inspired me maybe there are two things with current setup that's not working:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sommrobn0pahdxotm9yd.png&quot; alt=&quot;Schema&quot;&gt;&lt;/p&gt;
&lt;p&gt;After fixing a few API calls related to GraphEdit &lt;code&gt;get_children()&lt;/code&gt; change. I was looking at the force application code once again:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;func _physics_process(delta):
# Remark: We are not using to_global directly because of issues with viewport transform
var left_anchor = %LeftThrusterCenterOfAction.position
var right_anchor = %RightThrusterCenterOfAction.position

# Remark: applied force is RELATIVE to the body (aka. current object)
apply_force(Vector2(0, -1).rotated(rotation + _left_engine_angle_degrees / 180.0 * PI) * _left_engine_thrust, left_anchor)
apply_force(Vector2(0, -1).rotated(rotation + _right_engine_angle_degrees / 180.0 * PI) * _right_engine_thrust, right_anchor)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Again, it's really simple once we figure out &lt;strong&gt;&lt;em&gt;what's the right way to do things&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Video and intro: &lt;a rel=&quot;nofollow&quot; href=&quot;https://youtu.be/Yqh1EL9nN4g&quot;&gt;YouTube&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Game Dev</category>
<guid isPermaLink="true">https://coderlegion.com/4229/devlog-20250722-special-project-correct-physics-handling</guid>
<pubDate>Tue, 22 Jul 2025 23:45:02 +0000</pubDate>
</item>
</channel>
</rss>