0 Members and 1 Guest are viewing this topic.
.AI.<DATA>.Map bufferdet(768)→GDB0MB.Map[]→GDB0M[000000010000000000010000][000000010000000000010000][000101010000000000010000][000000000000000101010101][000101010101010100000000][000100000000000000000000][000100000000000100000000][000000000000000100000000].Tiles[]→GDB0T[0000000000000000][FFFFFFFFFFFFFFFF].Target[8142241818244281]→Pic0T[8142241818244281].Character[3C4281818181423C]→Pic0C[3C7EFFFFFFFF7E3C].Ally data.Number of characters∆List(2ʳ)→GDB0A.Data: .x position .y position .Max move distance .Other .data .you'll .probably .have∆List(6,1,8,0,0,0,0,0)∆List(1,0,8,0,0,0,0,0).Enemy data.Number of enemies∆List(3ʳ)→GDB0E.Data:∆List(10,6,8,0,0,0,0,0)∆List(3,7,2,0,0,0,0,0)∆List(11,2,8,0,0,0,0,0).<INITIALIZATION>.Draw tilemapGDB0M-1→D0→YWhile -64 0→X While -96 Pt-Off(Y,X,{D+1→D}*8+GDB0T)→GDB0MB X+8→X End Y+8→YEnd.Copy ally data to L₁conj(GDB0A,L₁,258).Copy enemy data to L₁+258conj(GDB0E,L₁+258,258)Fix 5.<MAIN LOOP>Repeat getKey(15) .Advance AI if enter is pressed If getKey(9) .For each enemy For(r₁,1,{L₁+258}ʳ) .Let user know AI is thinking; T=test stage (0=normal, 1=ignore other enemies, 2=ignore walls) Text(0→T,,"THINKING...") .Update screen DispGraph .Pathfinding start Lbl PFS .ᴇ8000=Start of pathfinding map 0→{ᴇ8000}ʳ .Fill pathfinding map with 0s Fill(ᴇ8001,254) .r₃=Iteration, r₂=pointer to enemy data; mark current location with 1 1→r₃→{{r₁*8+L₁+258+2-8→r₂+1}*12+{r₂}+ᴇ8000} .Start of pathfinding loop Lbl PFL .Default to no viable path 0→r₆ .D=Data pointer in pathfinding map ᴇ8000→D .While data pointer is in the map While -ᴇ8000-96 .If tile is not already part of a (shorter) path !If {D} .If tile can be traversed or in test stage 2 If {D-ᴇ8000+GDB0M}=0+(T>1) .If tile borders the end of a path !If sub(PCL) .Check tile (skip pathfinding failed goto) Goto PFC End !If sub(PCR) Goto PFC End !If sub(PCD) Goto PFC End !If sub(PCU) Goto PFC End .Pathfinding failed Goto PFF .Pathfinding check Lbl PFC .If in test stage 0 !If T .If tile is occupied by another character !If sub(PCC) .Pathfinding failed Goto PFF End End .For each allied character For(r₄,1,{L₁}ʳ) .If occupying current tile !If 0sub(O0) .Target found Goto PFE End End .Viable paths exist 1→r₆ .Mark as extension of path r₃+1→{D} End End .Pathfinding fail (tile cannot be traversed) Lbl PFF .Increase data pointer D+1→D End .Increase iteration r₃+1→r₃ .If no viable path was found this iteration !If r₆ .Increase test stage T+1→T .Reset pathfinding Goto PFS End .Continue pathfinding Goto PFL .Pathfinding end Lbl PFE .Length of path 0→{ᴇ8060}ʳ .While not at start of path While r₃-1 .If bordering tile is part of path !If sub(PCL) .Backtrack to tile Goto PFB End !If sub(PCR) Goto PFB End !If sub(PCU) Goto PFB End sub(PCD) .Pathfinding backtrack Lbl PFB r₄→D .Decrease iteration r₃-1→r₃ .If distance to tile is not greater than maximum move distance !If >{r₂+2} .Record tile as part of path D-ᴇ8000→{{ᴇ8060}ʳ+1→{ᴇ8060}ʳ+ᴇ8062-1} End .If tile is occupied by another character !If sub(PCC) .Reset path Goto PFE End .If tile cannot be traversed If {D-ᴇ8000+GDB0M} .Reset path Goto PFE End End .For each element in path For(r₃,1,{ᴇ8060}ʳ) .Move character {{ᴇ8060}ʳ+ᴇ8062-r₃}→r₄^12→{r₂} r₄/12→{r₂+1} sub(D) Pause 256 End End .Wait for user to let go of enter key While getKey(9) End End sub(D)End.<EXIT>Fix 4Return.<SUBROUTINES>.Draw everythingLbl D .Draw map conj(GDB0MB,L₆,768) .Draw allies For(r₅,1,{L₁}ʳ) Plot1({r₅*8+L₁+2-8→r₆}*8,{r₆+1}*8,Pic0T) End .Draw enemies For(r₅,1,{L₁+258}ʳ) Plot1({r₅*8+L₁+258+2-8→r₆}*8,{r₆+1}*8,Pic0C) End .Update screen DispGraphReturn.Pathfinding check tileLbl PCT {→r₄}-r₃Return.Pathfinding check leftLbl PCL Dsub(O1) or (D-1sub(PCT))Return.Pathfinding check rightLbl PCR D+1sub(O1) or (D+1sub(PCT))Return.Pathfinding check upLbl PCU D<ᴇ800C or (D-12sub(PCT))Return.Pathfinding check downLbl PCD ᴇ8053<D or (D+12sub(PCT))Return.Pathfinding check charactersLbl PCC .For each enemy character For(r₄,1,{L₁+258}ʳ) .If occupying current tile !If 258sub(O0) .Tile cannot be traversed Goto PCF End End .Tile can be traversed 1 Return .Pathfinding check fail Lbl PCFReturn.Optimization 0Lbl O0 {+(r₄*8)+1+L₁+2-8→r₅}*12+{r₅-1}+ᴇ8000-DReturn.Optimization 1Lbl O1 -ᴇ8000^12=0Return
@ QwertyIt looks great, too. Hope you also post your source.
Can you post the program source for that so I can study it? Thanks!
Wow, thanks! This is exactly that what I need. Up to 10 seconds sounds kinda much (Btw: 10 Secs on 6Mhz, correct?), though. I will make sure I dont use too big maps with too many enemies. I cant test it for now, since I have to plan at first the development next days.Edit: It seems to have trouble as an application and my game is going to be an app.
Quote from: graphmastur on November 11, 2010, 07:06:49 pmCan you post the program source for that so I can study it? Thanks!I posted the source for people to look at on the first post of this page, here.