LeaderOne,
I would have to say that you haven't searched these forums at all, supposively. Because, there are many profound topics on this very subject. However, due to the great excitement and need of the subject, another thread might as well be started on it.
The style, called
Advanced A.I., I believe, is a mixture of several basic a.i. techniques. So, there truly is no
advanced a.i., but just a series of basic intelligence algorithms, in hierarchy, working towards a single goal, or solution.
As you stated, you will need to learn pathfinding. In one other thread, a while back, I had created two programs for an individual to use as a learning tool to simple, not complex, pathfinding. I will show them to you. The programs are in code snippets below, each being a seperate source code, each needing to be copied and paste and ran in your DarkBasic editor.
The first snippet is the path creator. The source you do not need to learn. That is, unless your interested in learning simple 2D graphics and reading and writing of files. It allows you to place circles onto the screen at specific points(coordinates), and then records those points into a formatted text file.
The second, is the file of the source code you should study. It is full of
REM comments to help you understand its processes. It displays a
guard which walks from point to point, his path depending on the path you made. It gives you the option to either have the guard follow the path, in a loop, sequentially(in the order you placed the points in the first program), or randomly(no true order). The guard's destination point is lit in red, with all other points a dull green, I believe.
Copy these into your editor and save them into one folder as two seperate
.dba files. Study the
REM comments thourouly, and ask me if you have any peticular questions that arise, in which you cannot figure out after some time.
Waypoint Generator:
set display mode 800,600,32
sync on
sync rate 60
REM << if file already exist then delete it
if file exist("waypoints.txt") then delete file "waypoints.txt"
REM << open new file to write to
open to write 1,"waypoints.txt"
REM << display instructions on screen
ink rgb(255,255,255),0
print "press left mouse button to record a waypoint at mouse coordinates"
print "press any key to end program"
ink rgb(150,150,150),0
REM <<<<<<<<< main loop >>>>>>>>>>
repeat
REM << record waypoint to file when mouse is clicked
if mouseclick() = 1 and norepeat = 0
norepeat = 1
write string 1,str$(mousex())
write string 1,str$(mousey())
REM << place a circle at mouse coordinate
circle mousex(),mousey(),5
endif
REM << enable waypoint recording if mouse button is let off of
if mouseclick() = 0 then norepeat = 0
sync
until scancode() > 0
close file 1
cls
end
Waypoint Follower:
set display mode 800,600,32
sync on
sync rate 60
REM << read file and store coordinates into array
if file exist("waypoints.txt")
gonext = 1
open to read 1,"waypoints.txt"
REM << figure size of array needed by checking amount of strings within text file
repeat
read string 1,string1$
if string1$ <> "" then inc count
until string1$ = ""
REM << make array at needed capacity
dim coords(count,2)
REM << fill array with coordinates
close file 1
open to read 1,"waypoints.txt"
repeat
inc a
read string 1,string$
coords(a,1) = val(string$)
read string 1,string$
coords(a,2) = val(string$)
until a = count
close file 1
REM << error capture
else
gonext = 0
endif
REM << print error message if needed file does not exist
if gonext = 0
repeat
center text 400,300,"File does not exist!"
center text 400,320,"Press any key to end program"
sync
cls
until scancode() > 0
end
REM << run program normally
else
REM << prompt user for type of movement
repeat
if try = 0 then input "Type 1 for sequential movement. Type 2 for random movement.",type$
if try = 1 then input "Try again:Type 1 for sequential movement. Type 2 for random movement.",type$
if val(type$) < 1 or val(type$) > 2
try = 1
else
try = 0
endif
cls
until try = 0
wait 2000
REM << randomly or sequentially, depending on user choice, initialize guard start coordinates
if type$ = "1"
inc nextpoint
endif
if type$ = "2" then nextpoint = rnd(count / 2)
if nextpoint < 0 then nextpoint = 1
x# = coords(nextpoint,1)
y# = coords(nextpoint,2)
getnextpoint = 1
REM <<<<<<<< main loop >>>>>>>>>
repeat
REM << if guard has reached destination then randomly grab set of coords from array as next waypoint
if getnextpoint = 1
if type$ = "1"
inc nextpoint
if nextpoint > count / 2 then nextpoint = 1
endif
if type$ = "2" then nextpoint = rnd(count / 2)
if nextpoint = 0 then nextpoint = 1
xdest = coords(nextpoint,1)
ydest = coords(nextpoint,2)
REM << get angle between current point and destination point
angle# = atanfull(xdest - x#,ydest - y#)
if angle# < 0 then inc angle#,360
getnextpoint = 0
else
REM << get distance from guard to destination;if within 0.10 units then get next destination
if sqrt((xdest - x#)^2 + (ydest - y#)^2) < 1.50 then getnextpoint = 1
REM << move guard towards destination
x# = x# + (sin(angle#) * 2)
y# = y# + (cos(angle#) * 2)
endif
REM << draw waypoints as small circles to the screen
for t = 1 to count / 2
REM << highlight destination point circle red
if t = nextpoint
ink rgb(255,0,0),0
else
ink rgb(100,100,100),0
endif
circle coords(t,1),coords(t,2),5
next t
REM << draw guard as circle and directional line to screen
ink rgb(0,0,150),0
circle x#,y#,10
line x# + (sin(angle#) * 10),y# + (cos(angle#) * 10),x# + (sin(angle#) * 20),y# + (cos(angle#) * 20)
REM << print instructions to screen
print "Press any key to end program"
sync
cls
until scancode() > 0
end
endif
Don't forget also make use of the
thousands of posts that have already been created on this subject, by many other users.
+NanoBrain+