Jump to content
  • entries
    39
  • comments
    0
  • views
    820

AI: Overview


Piledriver

23 views

All throughout this project I thought it would be cool to have an AI opponent.  I figured the game would be played 100x more if it contained a good 1 player mode.  I also thought that would be impossible to implement unless I only had computer opponents in an empty arena.  Today I want to talk about the long path to Oh Shoot AI!

The game has 2 basic modes that affect AI - MANUAL flight (fly in any direction) and AUTO flight (horizontal speed is constant).  I figured it would be much easier to implement MANUAL flight AI so I started there.

 

MANUAL FLIGHT AI

I needed two basic things... a way to move the AI ship around in interesting ways.  I also needed the ship to detect if a move will result in crashing into the playfield and taking appropriate action.

 

The "interesting movement" I call "state management".  The basic idea is the ship moves in a constant direction for some random number of frames.  Then it will pick another direction and a new number of frames.  This continues a few times and then the ship can change modes ("meander" in completely random directions, "vertical intercept" - move vertically to align with the opponent).

 

This worked ok but the ship would constantly crash into playfield obstacles.  I added horizontal and vertical "bumpers".  If a bumper detects an obstacle immediately vertical to the ship the ship's vertical input will be nullified, likewise for the horizontal bumpers.  If a ship's motion is completely nullified by the bumpers the ship goes into "meander" mode and picks a new direction - this reduces the time an AI ship is stuck on an obstacle.  This bumper approach as opposed to hardware sprite/playfield collision detection allows for smooth sliding along walls as opposed to the more jerky bump into walls and bounce back approach.

 

The bumpers are invisible in the game, but you can see them in these mockups.  They are points adjacent to the ships bounding box that defines a span of tiles that need to be scanned for playfield obstacles.  Notice how the ship is aligned with the tiles determines how many blocks need to be scanned (orange zone).  Here are some of the cases for the manual bumpers:

 

Horizontal bumper with ship vertically aligned.

ManualRightBumperAxisAligned.png.31590f37a38b0919c4f5f42df3dc524c.png

 

Horizontal bumper with ship not vertically aligned.

ManualRightBumperNotAxisAligned.png.1bc4892c2d66a2c7dfd84a18d4150db1.png

 

Vertical bumper with ship horizontally aligned.

ManualTopBumperAxisAligned.png.4154fe57f3ee23188dddf0be660ac30d.png

 

Vertical bumper with ship not horizontally aligned.

ManualTopBumperNotAxisAligned.png.c9a879960a7d6d338cffb1d8b0687dd7.png

 

Here the bumper scan has detected an obstacle so movement in that direction is nullified to prevent crashing.

TopBumperObstructionDetected.png.0dd80682b78f0f84d859b55a94c822f9.png

 

In this case because the ship is already in the same tile column as the bumpers there is no need to scan for anything.

NoNeedForBumper.png.25917c6ed3b3db8310343f946a973671.png

 

AUTO FLIGHT AI

This case is more difficult because the ship has to detect playfield obstacles in advance and then respond appropriately to them.  In the game these scan zones are invisible, but here in the mockup you can see the ship scanning a 4 block wide region ahead of it.  I call this a "front scan".  The green bands are "corridors".  A corridor is a band of screen with nothing in it.  It must be a minimum of two tiles tall to be considered a corridor.

AutoBIG.png.920c7295731f0ac1b35da3fcf67746f8.png

 

Here the  front scan has detected an obstacle!  On its next turn(*) it will determine the shortest direction to a corridor. 

FrontScanObstructionDetected.png.91aa3c517563d62131d9e55893c4c0f6.png

 

In subsequent frames the ship will continue to move vertically in the direction of the nearest corridor until it fully enters the corridor.

 

This mode also makes use of bumpers, but vertical bumpers only, and these vertical bumpers are extended to always cover 4 tiles when in a corridor.  This prevents the ship from moving into oncoming playfield obstacles.

AutoFlightBumper.png.3351776fc0802ad4c78798695393b468.png

This is the AI simplified a fair bit.  There's other aspects to the AI as well such as avoiding missiles, avoiding incoming player in AUTO mode, firing logic, etc.  I also let the human players use some aspects of the AI such as bumpers, front scans and auto playfield avoidance, as well as auto missile dodging.  I call AI for human players "Assistance".

 

One detail I wanted to point out is that when a human player with "assistance" is moving vertically the front scan width is cut in half.  This makes it much easier for a human to maneuver through complex playfields without triggering an unwanted auto playfield evacuation.

 

There are two major details I didn't cover - how to scan a bunch of blocks for playfield obstacles FAST and how to find the nearest corridor FAST!

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...