<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Rpg on cassiobotaro</title><link>https://cassiobotaro.dev/en/tags/rpg/</link><description>Recent content in Rpg on cassiobotaro</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 25 Jul 2026 13:06:19 -0300</lastBuildDate><atom:link href="https://cassiobotaro.dev/en/tags/rpg/index.xml" rel="self" type="application/rss+xml"/><item><title>When Python Meets RPG: Rolling Dice with Style</title><link>https://cassiobotaro.dev/en/posts/dice-rolling-dsl/</link><pubDate>Sun, 01 Feb 2026 00:00:00 +0000</pubDate><guid>https://cassiobotaro.dev/en/posts/dice-rolling-dsl/</guid><description>&lt;p&gt;&lt;img src="https://cassiobotaro.dev/images/rpg.png" alt="People playing RPG" title="People playing RPG"&gt;&lt;/p&gt;
&lt;h2 id="shall-we-roll-the-dice"&gt;
 Shall we roll the dice?
 &lt;a class="heading-link" href="#shall-we-roll-the-dice"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Imagine being able to write RPG dice rolls as naturally as:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D6 &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;2&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D10
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And running a roll simply with:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;(&lt;span style="color:#ae81ff"&gt;3&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D10 &lt;span style="color:#f92672"&gt;+&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#f92672"&gt;*&lt;/span&gt; D4)&lt;span style="color:#f92672"&gt;.&lt;/span&gt;roll()
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That is possible in Python through operator overloading! Let&amp;rsquo;s create a DSL (Domain Specific Language) to make dice rolling intuitive and expressive.&lt;/p&gt;
&lt;h2 id="a-bit-of-context"&gt;
 A Bit of Context
 &lt;a class="heading-link" href="#a-bit-of-context"&gt;
 &lt;i class="fa-solid fa-link" aria-hidden="true" title="Link to heading"&gt;&lt;/i&gt;
 &lt;span class="sr-only"&gt;Link to heading&lt;/span&gt;
 &lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;In my teenage years I was an RPG game master and had a lot of fun playing Vampire: The Masquerade and Tagmar. Recently, while taking an online Smalltalk course, I came across a similar example of a dice rolling DSL. I found the idea brilliant and decided to implement it in Python! It was a lot of fun exploring how operator overloading can create such a natural and expressive interface.&lt;/p&gt;</description></item></channel></rss>