Results 1 to 2 of 2

Thread: VB Speed Problem

  1. #1
    Guest
    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?

  2. #2
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width