Artificial Intelligence (AI)
270 likes | 675 Vues
Artificial Intelligence (AI). สัปดาห์ที่ 6 Chasing and Evading อ.เทพฤทธิ์ สินธำรงรักษ์ เรียบเรียง. Topics. Basic rules of chasing and evading Line of sight chasing Chasing and evading in continuous environments Line of sight chasing in tiled environments
Artificial Intelligence (AI)
E N D
Presentation Transcript
Artificial Intelligence (AI) สัปดาห์ที่ 6Chasing and Evading อ.เทพฤทธิ์ สินธำรงรักษ์ เรียบเรียง
Topics • Basic rules of chasing and evading • Line of sight chasing • Chasing and evading in continuous environments • Line of sight chasing in tiled environments • Line of sight chasing in continuous environments • Intercepting : stopped enemy
Basic Chasing(การไล่ล่า) and Evading(การหนี) If (predatorX > preyX){ predatorX--; } else if (predatorX < preyX){ predatorX++; } If (predatorY> preyY){ predatorY--; } else if (predatorY< preyY){ predatorY++; }
Problem • เมื่อไหร่เราจะเริ่มไล่ล่า (Chasing) และเริ่มหนี (Evading) • หลักการง่ายๆให้คิดระยะทางระหว่างจุดที่ผู้ล่าอยู่ (Predator) กับเหยื่อ (Prey) ถ้าเท่ากับหรือน้อยกว่าระยะสายตาให้ทำการเริ่มไล่ล่า Line of sight Chasing • SQRT เป็นค่าระยะสายตา • โดยการเคลื่อนที่ไปหาเหยื่อจะมีแบบเป็นช่องตาราง (Tile) กับแบบต่อเนื่อง (Continuous)
Line-of-Sight • If the prey is not moving –the path followed is a straight line • Limited of direction • Tile-base movement can appear jaggy
Line-of-Sight • The predator always takes a straight line path towards the prey • The predator always moves towards the prey’s current position • Result: movement appears natural.
Line to move • Simple chase versus line-of-sight chase
Bad Good
Bresenham’s Algorithm Xk+1,Yk+1 Xk,Yk Xk+1,Yk คำถามคือจะเดินผ่านสีส้มหรือสีแดง
Bresenham’s Algorithm (Xk+1,Yk+1) Y=mX+b d2 d1 Y=mX+b (Xk,Yk) (Xk+1,Yk)
Summary • ได้สมการเป็น Pk+1 = Pk + 2ΔY(Xk+1 - Xk) - 2ΔX(Yk+1 - Yk) • ขั้นตอนการคำนวณ • InputFirst Point, End Point • Plot First Point • Cal ΔX,ΔY,2ΔY and 2ΔY- 2ΔX • Cal P0 = 2ΔY- ΔX • Loop Until Xk=XEndPoint If Pk >= 0 Choose (Xk+1,Yk+1) Pk+1 = Pk+ 2ΔY - 2ΔX If Pk < 0 Choose (Xk+1,Yk) Pk+1 = Pk+ 2ΔY
ExampleจงPlot จุดจาก (5,8) ไป (10,11) 11 10 9 8 10 5 6 7 8 9
Digital Differential Analyzer (DDA) • มี 4 กรณี • 1.m <= 1 (และมากกว่า 0) • 2.m > 1 • 3.m <=-1 • 4.m > -1 (และน้อยกว่า 0)
กรณี m <= 1 กรณี M>1 กรณี M>=-1 กรณี M<-1
Type 1: Using delta values • function chasing(){ • deltaX=px2-px1; • deltaY=py2-py1; • px1=px1+deltaX*velocityPredator; • py1=py1+deltaY*velocityPredator; • }
Types 2:Using normalizing vector • delta[0]=Pos_prey[0]-Pos_predator[0]; • delta[1]=Pos_prey[1]-Pos_predator[1]; • deltaManitude=Math.sqrt(Math.pow(delta[0],2)+Math.pow(delta[1],2)); • Pos_predator[0]+=delta[0]/deltaManitude*Vpredator[0]; • Pos_predator[1]+=delta[1]/deltaManitude*Vpredator[1];
Intercepting Predator find/calculate point of intercepting
Types 3:Intercepting Scenario1 • Vr = Vprey – Vpredator ;Vrคือ ความสัมพันธ์ระหว่างความเร็วผู้ล่าและเหยื่อ • Sr = Sprey – Spredator ;Srคือ ระยะทางระหว่างผู้ล่ากับเหยื่อ • tc = |Sr|/|Vr| ;tcคือ เวลาเฉลี่ยที่ผู้ล่าจะวิ่งไปถึงเหยื่อ • St = Sprey + (Vprey)(tc); St คือ จุดที่คาดคะเนที่เหยื่อจะเดินทางไป
References • David M. Bourg and Glenn Seemann. Creating Intelligent behavior in Games. 2004. ISBN: 0-596-00555-5