I created the Game Programming category over two years ago. At the time, though, my actual game programming was at a nadir. Several prior attempts at building a d20 combat system had left me unsatisfied. I recently found an interest, again, so here we are.
Much of the prior work is good; I am not starting over. This post is to highlight the core elements that my new work is leveraging.
The original and still current goal of this project is to allow me to compare combat rules between any of the editions of D&D as well as my own homebrew versions. Wedded to this is a second goal of using this problem domain to experiment with and gain experience with programming concepts new to me. Lately, this has been functional programming—but only where applicable. As with any large project, some components are best composed functionally while others are best as objects. Supporting both/all in one project is a great real-world experience. Oh, and my preferred programming language is PHP—even on command line. Experimenting with new features recently added to the language is of huge practical value.
Controlling all variables except the edition rules means having the identical die rolls at all points. My first attempt was via a “Dice Tray” concept but that encountered serious problems around usage. So my second attempt was—and still is—via a Probability Set. That component is then utilized by a Dice component to produce random results within the desired ranges.
Lastly, the data structure that I am using as my starting point is named Combatant. This is a D&D character distilled down to the essential elements needed for combat. I just rewrote this using the readonly class feature added in PHP 8.2:
final readonly class Combatant
{
public function __construct(
public string $identity,
public int $defenseValue,
public AttackSeries $attacks,
) {}
}