Implementing Omega Race style AI in BASIC

Basic and Machine Language

Moderator: Moderators

Post Reply
IsaacKuo
Vic 20 Hobbyist
Posts: 147
Joined: Tue Aug 04, 2009 5:45 am

Implementing Omega Race style AI in BASIC

Post by IsaacKuo »

There are two sorts of AI in Omega Race; one of which is generally useful for many games while the other has more limited applicability.

The "useful" one is for bouncing around. I've thought of a compact way of implementing it. First, you have an array of the 8 velocities, including some wraparound:

Code: Select all

dimv(15):fort=0to7:readv(t):v(t+8)=v(t):next:data1,23,22,21,-1,-23,-22,-21
These are the 8 cardinal/diagonal directions (used mainly for rotation of the player's ship). The inclusion of "wraparound" lets you avoid some bulky "7AND" expressions later on.

The bouncing enemy only uses the odd (diagonal) directions.

1) Check for a collision straight ahead
2) If blocked, rotate clockwise 90 degrees (i.e. turn right)
3) If still blocked, rotate another 180 degrees (i.e. turn left)
4) If still blocked, rotate counterclockwise 90 degrees (i.e. turn around)

Code: Select all

10 ifpeek(x+v(d))=wthend=d+2-4*(peek(x+v(d+2))=w):d=7and(v+2*(peek(x+v(d))=w))
The slow enemies have an AI of more limited utility. They just race around the track clockwise. They use the even (cardinal) directions.

Code: Select all

1 poke56,28:clr:poke648,28:?"{clr}":poke648,30:?"{clr}{wht}"
2 fort=0to21:poke37888+t*23,2:poke37909+t*21,2:next
This initialization code results in "1" stored in most of 37888...38394, but along the diagonals it's "2". The enemy AI uses this code:

Code: Select all

d(i)=6and(d(i)+peek(x(i)+30208))
Basically, this will leave d(i) untouched except when x(i) is along a diagonal. If it is along a diagonal, it will rotate the direction by 90 degrees clockwise. Note that by ANDing with "6" instead of "7", the value of "1" might as well be "0". Of course, we're PEEKing from nybble RAM, which means the upper 4 bits may be anything...the AND will squash away any undesired effect of this.

Hopefully someone will find this AI tricks useful for some BASIC games. The "bouncing" AI could be useful for Breakout/Arkanoid type games. The "racing" AI, though...well maybe it could be useful for some sort of racing game, or "Dodge 'Em" type game?
Post Reply