Results 1 to 3 of 3
- 12-13-2012, 08:36 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 37
- Rep Power
- 0
Explain how this simple A.I works and post alternatives
I don't understand how this A.I works, it's a pathfinder for monsters to follow blocks that are road.
This is how I read it with direction set to left and I will need to go up after one step.
for one unit of time
move right pixel by pixel until one complete step
when step complete increase block coordinate to signal one step made to the right and set postLeft to true
!postup is true, check if there is ground down
no there is not
!postdown is true, check there is ground up
yes there is, set direction to up
!postLeft is false ignore
!postRight is true, check there is ground left
yes there is, set direction left
and so I would think that instead of going up on the corner I would head back the way I came... but this is not so as the code works fine. what can't I see?
and for fun and because A.I is very interesting and I would like to compare, please post different solutions to learn from.
Java Code:public void physic() { if( walkFrame >= walkSpeed ) { if( direction == up ) { y -= 1; } else if( direction == right ) { x += 1; } else if ( direction == down ) { y += 1; } else if (direction == left ) { x -= 1; } progressToNextStep += 1; if( progressToNextStep == screen.room.blockSize) { if( direction == up ) { myY -= 1; postUp = true; } else if( direction == right ) { myX += 1; postRight = true; } else if ( direction == down ) { myY += 1; postDown = true; } else if (direction == left ) { myX -=1; postLeft = true; } if( !postUp ) { try { if( screen.room.block[myY + 1][myX].groundID == Sprite.groundRoad) { direction = down; } } catch(Exception e) { } } if(!postDown) { try { if( screen.room.block[myY - 1][myX].groundID == Sprite.groundRoad) { direction = up; } } catch(Exception e) { } } if(!postLeft) { try { if( screen.room.block[myY][myX + 1].groundID == Sprite.groundRoad) { direction = right; } } catch(Exception e) { } } if(!postRight) { try { if( screen.room.block[myY][myX - 1].groundID == Sprite.groundRoad) { direction = left; } } catch(Exception e) { } } if(screen.room.block[myY][myX].airID == Sprite.airSandwich) { deleteMonster(); damage(); } postUp = false; postRight = false; postDown = false; postRight = false; progressToNextStep = 0; } walkFrame = 0; } else { walkFrame +=1; } }
- 12-14-2012, 09:38 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Explain how this simple A.I works and post alternatives
It's hard to tell without the other data, but it looks to me like some sort of patrolling AI.
In other words, keep the beastie moving.
It's not a "goto" one, that is the monster doesn't seem to have a target to get to.
And I have no idea what airSandwich is...:)Please do not ask for code as refusal often offends.
- 12-14-2012, 07:38 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 37
- Rep Power
- 0
Re: Explain how this simple A.I works and post alternatives
yeah the monsters just follow a road to the end... think tower defence. It works but I'm just not sure how, because with my logic (above) they would go back the way they came.
the goal at the end of the path is a sandwich. Because I wanted to make it realistic... don't you hate it when you make a sandwich and then an army of monsters try to steel it and you must set up lasers. hate it when that happens.
Similar Threads
-
for loop -anyone can explain me how it works
By zanetti77 in forum New To JavaReplies: 6Last Post: 07-21-2012, 02:37 PM -
Question dealing with a simple object (hard to explain)
By Lanuk in forum New To JavaReplies: 8Last Post: 01-10-2012, 04:40 AM -
First post-Simple question help please
By Teesea in forum New To JavaReplies: 2Last Post: 08-11-2011, 01:03 PM -
Please explain how this bit of code works.
By Allspark in forum New To JavaReplies: 4Last Post: 09-03-2010, 03:56 AM -
Explain how to troubleshoot simple java pg
By senthil in forum Advanced JavaReplies: 2Last Post: 09-01-2009, 01:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks