PDA

Click to See Complete Forum and Search --> : VB Speed Problem


Jun 15th, 2000, 11:54 PM
I'm trying to make an AI program for a game. Basically, what it does is superimposes a 25*25 grid over the form, and then checks each square for certain things (ie, walls and the player) using a recursive function, and assigns a numerical value to each square, with the man's square being 0, each adjacent square 1, etc, and walls being 1000; it then moves the computer player into the adjacent square with the lowest number. Now, this works great and all--only it takes forever, with the recursive function checking 625 squares, and using two 2-dimensional arrays for the coordinates (one keeping track of the value assigned to the square, the other keeping track of whether a square's been checked) and everything. Basically, my question is this: is there any way to speed up the operations without using a completely different AI program?

Sastraxi
Jun 17th, 2000, 10:32 PM
Try this:

option expicit
const MinX=1
const MinY=1
const MaxX=25
const MaxY=25

sub Check(playerposX,playerposY)
dim x
dim y

for x=playerposx-1 to playerposx+1
for y=playerposy-1 to playerposx+1
if x=playerposx and y = playerposy then
elseif x=minX-1 then
elseif y=minY-1 then
elseif y=maxX+1 then
elseif x=maxY+1 then
else
'enter normal code here
end if
next y
next x
end sub

This will only check the squares around you, and if you are on the border, it will stop from checking invalid squares.