Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Good resources for architecting simulation games?
15 points by SeanAnderson on Sept 5, 2022 | hide | past | favorite | 9 comments
I recently made an attempt at building a simulation game. I found it challenging even though I'm a seasoned software developer. I was finding that my experience in building out web apps, dashboards, and crud stacks didn't immediately lend itself to architecting a game properly. It feels like everything is business logic and it has been tough to see ways to tease out and modularize concepts. I don't know if I am making good trade-offs w.r.t performance and immutability. I find myself copying an entire "world" structure with every loop in an attempt to represent the world immutably, but I also seem to need to process changes serially as entities interact with one another inside the world. It doesn't matter that the world is immutable, I can't easily parallelize the simulation. Perhaps immutability is only making things harder, then?

I'm not too concerned about graphics or 3D math. I'm working in a 2D space with the most amateur of graphics. I'm interested in having some looming trade-offs pointed out to me so that I can make decisions with my architecture to best receive those trade-offs. I'm interested in design patterns that allow me to modularly enrich the complexity of my simulation.

If you're curious, https://github.com/MeoMix/antfarm/blob/main/src/util.ts Here is a file that became quite the dumping ground. I am not proud of this code. I had intended to tease out some utility methods which take a world and return a cloned and updated world. It's easy enough to separate out view concepts, and it's easy enough to separate out constructors, but all of the "interesting" simulation logic found its way to this dumping ground.

One book I am going to purchase is https://tynansylvester.com/book/ as it's by the developer of RimWorld which is a world-class simulation game. I don't think this will approach technical trade-offs, though, only functional.

Another resource I found is the development blog for Sandspiel, https://maxbittker.com/making-sandspiel This is actually quite a useful resource and I think I would do well to internalize it more, but it also focuses heavily on particle physics and automata-driven simulations. These are good concepts to explore and ones I should strive to master, but they aren't the only ways to slice a simulation game.




Are you confident at building simple effeciently-written games? Making computer games is harder than doing CRUD apps. And making simulations games is as twice as hard. My advice is to learn to make simple games at first because even simple games "simulate" some aspects. Instead of making one big very complex simulation game, build many simple simulations with increasing complexity for every new game. In the process you would see many problems you need to solve so that game uses resources effeciently, etc. ... I know this is not what you wanted to hear, I am sorry. :-) I think not any single book can answer your question, but rather many-many books.


Answer by OpenAI: One resource that may be helpful is the book "Game Programming Patterns" by Robert Nystrom. This book covers a variety of topics related to game programming, including architecture, design patterns, and optimization. Also, the blog "Gamasutra" has a section devoted to game programming, which may have articles that discuss simulation game architecture.


This answer is a good example of GPT-3 approach limitations - while it superficially covers the subject, the recommended book is not actually going to help that much for writing simulation code. But, in order to know that, OpenAI would actually need to read the book, understand it, and reason about how it applied to the domain in question. Instead, it's just mindlessly repeating and jumbling together things it overheard on the Internet, like some retarded village gossip.

(This post was not written by GPT-3).


Answer by OpenAI? Good advice tbh.


It is quite a different paradigm from regular web programming - I can remember the mental shift I had to make when I rebuilt my homepage as a clone of the classic lander game (I was actually going to build a clone of an old Amiga game called "Gravity Power", https://www.richardson.co.nz/ was as far as I got!)

Did you use a game engine? These will often encourage you to follow a particular pattern when writing code. If you didn't, then I'd encourage you to look into entity component systems (which I also used for my homepage). It's quite a light weight pattern and it really lent itself to programming in a game loop (as opposed to say, MVC which fits the request/response cycle of web programming better)


Tynan's book is one of my favourites for gamedev. I'll have to re-read some of it through the lens of Rimworld to see if it might be useful to someone who wants to develop a simulation game (e.g. the Balance chapter), as I'm keen to start a colony sim / base building game next year.

As FragrantRiver also already said, start small. Think of the smallest scope possible, then reduce it even more. Perhaps consider a game engine, so your programming efforts are focused on the economy side, then the ants can be event driven, and graphics are easier to handle/implement. (I started a Universal Paperclip clone a while back, using cljs, and had bags of fun making the tech tree and economy logic, but then got bored when I had to build a UI finally.)


Immutability sounds like a thing to absolutely avoid - it will kill the performance as soon as the simulation gets bigger or more complex.


If you aren't familiar with the Actor Model, it's worth investigating. It avoids a lot of problems you will experience with other paradigms. https://www.brianstorti.com/the-actor-model/


This talk is pretty good:

https://www.youtube.com/watch?v=eZfj7LEFT98

But other than that, it's like building most types of software. It's scary when you start and don't know where to go. Start with a small loop. Implement it. Extend it. Refactor it.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: