AI for a shooter game reacting with walls

My Project: https://snap.berkeley.edu/project?username=mdegn&projectname=Shooter%20AI%20Testing

I am designing an AI for a top-down 2D shooter game, and I need a proper way for each AI to detect whether it has a clear path/sight on a target. Since pictures are worth a thousand words, let me show you two methods I've thought of, the last one of which is in the project.

Assuming you can see this, each of the pinkish dots represents a check of all of wall points, so this increases exponentially as you add more AIs. You can't just check a line between two AIs because this is what is required.

For this, areas behind walls are cut off. The diagonal shows how sections are cut off on the top, right, bottom and left quadrants around the AI, so the wall is above the AI, but if it were way farther left or right it wouldn't block the AI from shooting above it, but it's in the top quadrant meaning it will. So this second method is what I'm using except that it doesn't quite cut it (better than nothing though). If a target, wall, and the AI are all on a diagonal line in that order, the AI will still try and shoot/follow the target. It gets worse when there are two walls, trapping the AI in a corner. Basically I am trying to find a solution, so please suggest any solutions if you can, and I hope I have kindled your interest.

I'd be inclined to have a hidden sprite, have it draw an (invisible) line to the target, and see if that line crosses anything else.

Good idea! Another idea to check out is the ray length option in the sensing category's _ to_ reporter. comparing the ray length to the wall sprite against the distance to the target should let you determine whether the sight is clear. If the distance to the target is less than the ray length to the wall the target is in clear sight, otherwise it's behind the wall.

I like your AI Concept. It's much better than my Enemy AI I made 1 year ago.

Untitled

Basically what it looks like depending on what direction the wall is from the AI (red lines means targets above that line are disqualified, blue lines mean below; only two lines apply per wall)

Wow, I had no idea about that. @bh's idea is my first picture basically, I have a list of points on the wall, and I thought that would take up too much processing power. I have never used ray length, but I would think it only works for "if touching", right? Right now I'm only using pen and variables so I would think that wouldn't work, but I'll have to try it.

Whoops, I forgot to share the project. I've implemented some more code, and you can see that at least part of it works.