Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

Is it just me? It's not a good question, it shows lack of core coding experience.

For example a video game consists of millions of possibilities/results in movement based on environment - it's not approached as a collection of thousands of if/then/else statements.

In fact the movement of cows seems very much like video game coding, it needs a "cow engine".



It's a great question. It expresses a problem from the worldview of a coder with a particular, very common skillset. Which is something that other coders with the same problem and the same skillset will find in their searches. As long as the answers are good, it's a perfect use of the system.


I think it was a really good question. It showed that he had the intuitive instinct that there had to be a better way. He just didn't know how to ask for a "cow engine" by name.


I am not so certain. Note their question is not if there is another way - they are asking how to manage all the statements they are planning to write.

Imagine being given a problem such as "add any two given integers but do not use math operators".

A person without anything but if/then/else knowledge would proceed to try to write

   if (a==1 && b==2) c==3  
and repeat it for every variation until they gave up.

Someone with more core experience and coding instinct would immediately recognize there must be away to set patterns for 0-9 and then analyze each decimal place, apply a matrix, or a number of other approaches.


Certain business logic can not be generalized as neatly as arithmetic. I work in health care. It is a real problem.


i don't see why people downvoted you.

I write AI perception systems for "realtime simulations", and you are exactly correct.

while on the surface it may seem like "if/else" will give you the solution you need, the sheer number of permutations will make it infeasable.

That said, there are "known solutions" and some novel solutions to this problem too. Perhaps if/else is really what this person needs, but there are other potentially better solutions documented.


Last I checked (been a couple years now) Hierarchical Finite State Machines and Behaviour Trees were big for that sort of thing.


Totally agreed -- that's the first thing I thought while reading the question. OOP made this kind of problem easy to tackle long ago.


I really don't see how OOP is going to make it much easier to tackle this kind of problem, care to elaborate how?



How do video games solve it?

Do you have any material one can read to learn more about this?


Often through physics engines. You express a bunch of constraints then let a physics engine solve them on each time step (and sometimes across multiple time steps).

Custom (non-physics) solutions involve declarative sets of constraints being solved by some sort of engine; such solutions often start to resemble physics engines even if the physical rules even if the constraints are not exactly physical.

Learning how to use a physics engine, first, then how those physics engines work, is a good start to understanding these kinds of problems.

Edit: I'm really surprised the stackexchange answers don't mention this.


What would be a good place to start learning about what you're describing here?


I would start with Erin Catto's Box2D.

http://box2d.org/

There are C#, Flash, Java versions if you aren't into C++. Lots of documentation on the web, but the getting started guide is good enough.


Using a physics engine to express an AI problem? That's an interesting solution, but that's certainly the first time I've heard of one being used like this?


But you know, the problem as stated was how a bunch of influences affect...cows. So think of them as a bunch of mechanical cows instead, and the influences are modeled through springs and collisions, things like that.

AI is often cast as constraint solving, and a physics engine is basically a constraint solver. Of course, for real the AI engine runs next to the physics engine. Ah! I should have mentioned Rodney Brooks' work:

http://en.wikipedia.org/wiki/Subsumption_architecture

where you model intelligence as a bunch of simple prioritized reflex-like behaviors. Now, on each step, you have each "entity" execute their reflexes according to the current environment, where some reflexes act to disable others. The reflexes are incredibly simple, you probably couldn't even express A* path finding, but you could have the act as ants following a diffusely scented trail. Also see his paper "Elephant's Don't Play Chess."


If I was given the task to integrate cow herds in a computer game, my first instinct would be BOIDS/flocking, adding in weights for wind velocity and sun. It's fast and lends itself to predictable behaviour which is beneficial to the player.

It may not necessarily be realistic but then most players won't be familiar with cow movements.


I think it's a good question if only for the quality of answer it gained for the rest of us. But it's certainly not what I would expect from a very experienced developer.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: