AI, I hate AI

This week I took it upon myself to do the AI for the enemy fish and the light bulb for the player. While the light bulb was pretty straight forward the AI was a lot harder to put together. I realize this task will take much more time than I expected. It didn’t help that I was stuck in bed the whole week with fever and “puke sickness”.

Image

The light bulb consists of a sprite that’s always drawn just in front of the player and a “light” with a variable radius. I thought it would be easy just to create a class and draw it out. I was wrong, I created the class without problem, but when I tried to give the light bulb its properties it refused to recognize SFML (The library we’re using to do most of the work). This is still a problem as I’m writing this. Everything works fine when I remove all things that have to do with SFML. This is no option for the release version so I will not stop until I get it right.

Image

The AI was a bit scary as it’s the first one I ever try to make. I was right to be scared, it’s hard. The AI consists of three states: Idle, Attacking and Fleeing.

In its Idle state the fish are just swimming around minding its own business. To make it swim around in random directions doing fish-things is a lot harder than you might thing, at least for me.

The Attack state is pretty self-explanatory, the fish attacks the player. The attack state is triggered if the fish is larger or of equal size of the player and if it discovers the player before it gets attracted by the light bulb.

If the fish is smaller and discovers the player before it is caught, it will enter its fleeing state. When it does it will get a speed increase and starts of away from the player.

I solved this in a simple way. If the fish is smaller and behind the player and within a set number of pixels (still tweaking the number) is flees.

And the same thing with the larger fish but it attacks instead of flee.

From the start we wanted fish to eat and flee from other fish and create a sort of ecosystem. But this is a lot more work than we have time or skill for.

Image

2 thoughts on “AI, I hate AI

  1. Hello, i was assigned to comment on your blog this week.

    First of all, regarding your latest blog post. It’s well written but you could probably have put some of the segments at the lower half of the post together. Although i know it can be hard to hit the 400 word limit. I really liked how you made the top paragraph be sort of an intro to the rest of the blog post. I also liked your creative use of images but would like to see more images of your actual work rather than only images related to the subject in general. In the second segment you mention light in the light bulb as “light” but you don’t expand on what you mean by putting it in quotations. In the same paragraph you mention having trouble, an image of your error message would be nice to illustrate the problem you’re having.
    Your description of the AI is pretty bare bone and choppy and could probably be expanded more; maybe some code examples could be used here, or pictures of code.
    It was pretty clear what you did during the week but from what i read at the start you were home sick. When i read home sick, i read that as “not working” so that could be mentioned on since it’s almost contradicts itself.

    I took at look at the rest of your blog and overall i will sat that this blog post was pretty good considering it was the first post with over 400 words, what i like to do is make a post for each day i actually got some work done, that way i won’t have to write as much each time and it was really useful for remembering the work i did during the programming I project.

    That should be all, also i apologize if the layout of this message is a bit off as there was no preview button.

  2. Really well written and interesting except for a few sentences.
    Thou I would like to know more on why there was a problem with the recognition of SFML while working on the bulbs properties.
    The attack state isn’t that straight forward I was wondering if there were different ways they attack or if it’s basically just a chomp or bite and not any form of as a pistol shrimps for an example.

    As well as the idle state what do they do while in the idle state do they just swim around in random directions or do they actively seek out other fish or the player?
    How about the fleeing state does the fleeing fish take off in the opposite direction of the fish it’s fleeing from or is it more complex.

    And for the last point of yours is there not going to be a virtual ecosystem in the game I was really looking forward to seeing that in action working. I see how there wouldn’t be enough time to implement that into the game but it would be really nice to look at it would be one of those things that makes the game stand out. Personally I would maybe if the ecosystem part of the game existed watch that for awhile just to see the ecosystem in play.

Leave a comment