IF System that allows for slightly complex simulations?

Such as? If it’s just some mid-level arithmetic, you could use choicescript. My latest game has a city management system which uses plenty of mathematical calculations.

If we’re talking about advanced algebra or geometry, I probably can’t help with that, unless you want to try creating an IF with Excel.

Inform’s certainly capable of it, like any Turing complete language. I’m not sure what kind of simulation you’re talking about, but if it’s some sort of physics simulator, I don’t think Inform’s especially well-suited to it. It’s not hard to imagine that what you want would end up being obnoxiously slow. And Inform’s not the easiest thing to learn: I wouldn’t recommend taking it on for this problem domain.

But simulation involving math could mean all sorts of things – if you tell us more about what you have in mind, we could give better advice.

1 Like

IF tends to be written in domain-specific languages nowadays, but I think some engine that’s written in a mainstream language will prove better for this. You can plug Box2D into Twine without too much effort, for example, since they’re both built on JavaScript, and put a rigid-body physics simulation in your game. Much harder to do that in Inform or TADS.

Unfortunately, if you want to do specifically parser IF, there aren’t a lot of options for that. I can’t think of any popular parser-IF language that can be easily hooked up to JavaScript/Python/C++/etc libraries. (Maybe Inform with Vorple? Or Inform with the new “compile to C” option?)

But if you want choice-based, there are plenty of options out there; Twine is the most famous, but Ink is designed to be hooked into a larger game engine of some sort (with bindings for Unity, Unreal, plain JavaScript, and probably more).

And of course, if you want to build your own simulation library, basically any modern language will provide the mathematical primitives you need. But, that depends on your willingness to build everything from scratch as opposed to importing a library someone else has already made and refined.

3 Likes

(Hmm…mini-comp where you have to integrate some other kind of simulation into your game…)

2 Likes

AFAICT, TADS has some speed issue in floating-point math, but Inventor200 can be more specific, having researched TADS’s floating-point handling.

I think that as language, Inform isn’t precisely suited for coding complex math.

If your math require player’s input, I think that the unique flexibility of ALAN allow building a formula-based parser (not Octave-grade, but I think that a bc-grade parser IS feasible), but ALAN’s underlying VM (story file format, in IF coding parlance) has only integer math.

Historically, Adventure was written in FORTRAN, a language designed for coding complex calcolations (FORmula TRANslation), so writing math-centered IF was feasible since day 1.

AFAICT, only two IF implemented a calculator, both in TADS:

3+ in TADS3 implements a four-operator calculator
GC: A trashing parity bit implements a basic RPN calculator in TADS2.

This is all I can say from your question so, I concur to others in asking more specific details on your question.

Best regards from Italy,
dott. Piergiorgio.

1 Like

Wasn’t Joey (@inventor200 ) working on simulating orbital mechanics and Jovian atmospheric pressures in TADS a while ago?

EDIT: Don’t know if it’s helpful, but here’s the thread:
Thankful For Mathematics - Authoring / TADS -

3 Likes

Yea, is that I refer in my post. Let’s leave to Joey the honour of narrating his simulating experiment.

Best regards from Italy,
dott. Piergiorgio.

1 Like

Never Gives Up Her Dead (@mathbrush) has a completely (TTBOMK) working calculator, in Inform.

Does it calculate 5318008?

2 Likes

Honestly, I wish I knew what that meant. Do you literally mean the number 5318008, or…?

2 Likes

Lamest example of pre-pubescent schoolboy humour. Type that number into your old-school calculator (with the square numbers), turn it upside down and read it aloud.

Oh how we laughed in grade school! Just like our first forays into the undiscovered realms of the dictionary…

3 Likes

Oh. My. Days.

As soon as you said the words “calculator” and “turn it upside down”… :laughing:

Where is the pained cringe laugh emoji when you need it?!?

3 Likes

Ren’Py can, in theory, do any mathematics that Python can do due to the way it interacts with the Python underneath. In practise, at beginner level, it’s good at the four basic operations, decimals and the sort of algebra where the letters are represented by numerate stats you are tracking (and where everything else is fixed numbers, four basic operations and decimals).

If you want a parser, I suspect several parser-based platforms would be equally accessible (Ren’Py is a choice-based platform) and that it is easier for a beginner to implement basic choice in a parser than a basic parser in choice.

1 Like

I don’t understand. Could you give some examples that describe what you intend?

Thanks! I’m basically playing around for a different project with a simple simulation of the movement of water on things submerged for instance if you drop something in that will sink - say something metalic - how might the flow of water, smoothness of the bottom (bedrock/sand), etc - move.

I’ve been programming a long while (30+ years) and have played with Inform and TADS in the past and wasn’t really seeing how to approach such. For game play, I could use randomness/percentages but was wanting something a bit more indepth.

1 Like

Thanks!

So, in brief, TADS allows you a while amount of precision for math and the ability to completely modify everything down to core functions lets you basically make whatever kind of game you want, and leverage the math for it.

There is a problem, though.

In what I suspect was an effort to make TADS deterministic and cross-platform on a lot of older computer systems, the language does not do non-integer math directly in the CPU, and does not seem to insist on a specific IEEE standard for computation.

As a result, all non-integer (or floating-point) math is done further away from the CPU and deeper inside the TADS runner. Every time a new floating point number is created/calculated/used, a brand-new object is created. This means a lot of objects being thrown into garbage collection. Additionally, the precision of floating point in TADS is absolutely insane sometimes, so computations are laborious under the hood.

All of this means that if you are using non-integer math quit a lot in a single turn, a modern, C+±based TADS interpreter on a beefy computer will be delaying about 5 seconds before the upcoming text prints, and this gets more extreme on other configs.

So what needs to happen is you gotta decide what precision you would like to use for your numbers, and use some fixed-point math tricks with integers to handle your stuff (like they use in Doom), because math performed using integer data is lightning-fast. You basically shift your integer to the right by something like 8 bits, do the math, and then shift it left by 8 bits when you need to simulate a rounding operation.

If you just need the occasional floating-point calculation, it’s fine. But if you’re running maybe a hundred of them in a turn, you’re gonna see slowdown. Fixed-point math using integers will save you.

TADS, overall, has a lot of power and execution tricks for deep simulation, if that’s what you’re looking for.

4 Likes

@inventor200 Thank you for this insight. How did your orbital simulation work out?

I’m fine with fixed point math. I will take a look. There are thoughts where I could just use a bit of randomness instead of a simulation - still working on some of this.

It’s good to know with some limitatons this could be done in TADS. For myself, I was hoping to stay in one of the main system.

1 Like

So I need to preface this by saying I have severe ADHD, and my meds only do so much, so I got far enough to understand that it’s definitely possible. I approached it from a weird direction, regarding its code structure. However, I created a similar system afterward, which can handle extreme distances of thousands of kilometers pretty easily with good precision and no speed cost, but the game that uses that is still a WIP while I wrestle mental demons and life demands.

It is a module, though, so I could post what I have so far to my GitHub, if you’re interested, but again I can’t promise it’ll be actively maintained.

TADS can be a “main system” if more authors and devs see its potential and hop aboard. :grin:

1 Like

Inform 7 has built in floating point math functions. So it certainly could do any simulation you want it to do, the only question is whether it’s efficient enough. And if the performance is poor, it could be improved by dipping into I6 (calling the maths opcodes directly will be more performant than calling them via functions.)

Do you already have in mind what precise simulations you want to run? Is your model something that you’d define with equations but haven’t thought about code yet? Or would you most naturally program it in some other programming language, and converting it to an IF language is the issue? Or would you want to be using something like Box2D, and the lack of simulation libraries is the issue?

1 Like