# Thinking about AI

**URL:** https://forum.revolutionarygamesstudio.com/t/thinking-about-ai/60
**Category:** Theory
**Created:** [June 14, 2015, 4:22pm UTC](https://forum.revolutionarygamesstudio.com/t/thinking-about-ai/60 "2015-06-14T16:22:40Z")
**Posts on this page:** 1
**Showing post:** 35

<div class="post-metadata">

### Author: ![TheCreator](https://thrivedevforum-cdn.b-cdn.net/user_avatar/forum.revolutionarygamesstudio.com/thecreator/32/64_2.png) [@TheCreator](https://forum.revolutionarygamesstudio.com/u/TheCreator)
#### Post date: [July 2, 2015, 3:12pm UTC](https://forum.revolutionarygamesstudio.com/t/thinking-about-ai/60/35 "2015-07-02T15:12:48Z")

</div>

@Seregon Don’t worry, your comments will not offend anyone (at least not me). We all understand that what you wrote is purely constructive criticism. If we would be afraid to point out faults in other people’s ideas we wouldn’t be where we are now. I will now read through your post and answer some questions and comment on your ideas.

> [@Seregon](#):
>
> While I agree that the AI’s response needs to a stimulus needs to change according to it’s internal state, or other information, I don’t like the idea of ‘mode switching’. There are continuous alternatives which could achieve the same result, but with more finesse in it’s response. For example, as you get hungrier you worry less and less about spikes. At first this means you’ll risk going near a predator to eat prey, then you become more willing to eat spiky/well defended prey, and eventually you may even try to attack a predator.

I see your point; however I think the idea of mode switching is in some cases better than a continuous function. For example take antelopes—if it is being chased by a lion, I won’t stop to eat a bush no matter how tasty it might seem. It won’t even slightly divert its path to run close by the bush. I think having a behavioral tree or FSM is the way to go here, but I am open to further discussion.

> [@tjwhale](#):
>
> It would be really cool to have your species start acting how you act without having to explicitly program it.

I think the goal was to give all members of your own species the same memory, so if you, the player, hunt microbes A and B, but run away from C and ignore D, the rest of your species will do the same. But this idea is definitely not flushed out, it was just a benefit of the system described in the same post.

> [@Seregon](#):
>
> We really want to avoid running simulations outside whats going on during the players gameplay, the sheer number of species and interactions going on would make it very difficult to do these in an acceptable amount of time.

This is something I agree with 100%. Although having the memory is good, it should only work for the microbes rendered on screen and should definitely not be calculated off screen while the player is playing the game.

> [@Seregon](#):
>
> I like the idea of simplifying input this way, but it falls down due to the binary response to organelles.

Well, rather than having a single bit for an organelle we could have a byte. This would increase the memory, but would allow us to store more information. Either way, I think that this idea was more or less abandoned, and @tjwhale and I have decided to have a memory that stores outcomes of a couple of fights and then uses this data to deduce a strength value for each cell.

> [@Seregon](#):
>
> As for multiple microbes on the screen, real cells move by looking at food (or poison) gradients. So I thought that for each microbe we could do a simple calculation:  
> Vector2D netMovement = 0;For all enemy microbes on screen{Vector2D movementDirection = CalculateAction( e^(-1\*distanceToMicrobe), typeOfMicrobe );netMovement += movementDirection;}
> 
> This is more the sort of thing I had in mind.

Since you liked this idea (even if you misquoted me), I decided to spend more time working on it. It didn’t work the first time I tried it a while back; however I managed to finally fix it and add it to my prototype (apparently I accidentally divided by zero… again). Keep in mind that the video below is the exact same as my prototype before (it has none of @tjwhale’s stuff, I only focused on adding the exponential function). The change is very minor (maybe I should have used a smaller value than e), but you can notice that now microbes have curved paths, which is IMO great and adds a lot more realism)

[![](https://img.youtube.com/vi/Ss093ipwFWc/maxresdefault.jpg "Thrive AI v3") ](https://www.youtube.com/watch?v=Ss093ipwFWc)

Edit: I changed the video link to a new one where I use 1.1^(-distance) instead of e^(-distance), so the curves are more pronounced. I think that it would even work if I were to use a linear dependency, so that is something I might try next.

> [@Seregon](#):
>
> So for example microbes with spikes: Spikes cannot hurt me if I’m far away so its weighted input is a function of its distance to me as well as number of spiked microbes present. So if there is one far away from me, or two, or ten I won’t run. They’re too far away and I like where I am. Now if one starts getting closer the weight starts increasing, slowly at first. Who cares if it’s 20 meters away or 19 meters away? But what if its 3 meters away then 2 meters away, clearly much more of a threat, hence the non-linear function of distance. This makes it so that 10 far away is not as frightening as one or two really close. This is the main reason why I don’t like the simple +4 scoring system, it doesn’t capture this dynamic.
> 
> This, and the rest of that post, are much more like it, with continuous and interacting responses to stimuli. It still relies on discrete responses, which works fairly well in this system, though still has drawbacks. It would also require as much if not more data to evolve than @tjwhale summary post above.

Unless you are really against using mode switching, I see tjwhale’s system working with this perfectly:

> [@tjwhale](#):
>
> for i in range(number\_of\_animals):…self.distances[i] = (distance1(self,animals[i]))…if i != self.number and i != self.target:…fear += 30\*self.memory\_strength[i]/(self.distances[i] + 0.01)if fear \>= self.memory\_strength[self.number]:…act afraid.
> 
> So basically it adds 30x how strong it thinks the other microbe is divided by the distance to it to it’s fear counter. If the fear counter \> your own strength then it acts afraid and flees (it moves so as to reduce it’s fear as quickly as possible).

Overall, in my opinion the most menacing problem we have in our current algorithms/prototypes is the incompatibility with the CPA system. This is partially because we don’t really have a CPA system at the moment and it is hard to make a good solid fit with something we didn’t write yet. The second reason is… umm, I forgot what the second reason was… I’ll get back to you on that.

Aaannyway, if we could somehow deduce or approximate the strength of a microbe based on its organelles we could solve a lot of problems we have now.

---

_[View the full topic](https://forum.revolutionarygamesstudio.com/t/thinking-about-ai/60)._
