AI in Game Developement and Physics in Game Development

Download Report

Transcript AI in Game Developement and Physics in Game Development

สั ปดาหที
์ ่ 1 Introduction to AI
อ.เทพฤทธิ ์ สิ นธารงรักษ์ เรียบเรียง
 Artificial
Intelligence (AI) may be
defined as the branch of computer
science that is concerned with the
automation of intelligent behavior
 ซึง
่ ตองมี
พน
ื้ ฐานทีส
่ าคัญของ
้
 Data Structure
 Programming
 Algorithm



ในยุคแรก คอมพิวเตอรมี
่ การคานวณเทานั
้
้ อ
่ น
์ ไวเพื
โดยมีมนุ ษยควบคุ
ม ป้อนคาสั่ งและรอผลลัพธจาก
์
์
คอมพิวเตอร ์ การตัดสิ นใจบางอยางอยู
กั
่
่ บมนุ ษย ์
ตอมามี
แนวคิดทีว่ าจะท
ายังไงให้คอมพิวเตอรมี
่
่
์
ความสามารถสูงขึน
้
จึงมีการปรับเปลีย
่ นการเขียนโปรแกรมโดยใช้อัลกอริทม
ึ
เพือ
่ เพิม
่ ขีดความสามารถของคอมพิวเตอรให
์ ้มี
“กระบวนการคิดทีส
่ มบูรณแบบคล
ายกั
บความคิดของ
้
์
มนุ ษย”์ เรียกวา่ “ปัญญาประดิษฐ ์ หรือ AI”

เป็ นแขนงหนึ่งของวิทยาการคอมพิวเตอร ์ ทีต
่ องการ
้
พัฒนาเครือ
่ งจักรกลตาง
เช่น คอมพิวเตอร ์ หุนยนต
่
่
์
ให้มีความสามารถดานความคิ
ด เช่น เดียวกับมนุ ษย ์
้

1.เกม (Game)
◦ อัลกอริทม
ึ ในการค้นหาเส้นทาง
◦ การตัดสิ นใจ

2.ระบบผู้เชีย่ วชาญ (Expert System)
◦ การจัดการองคความรู
้
์

3.Machine Learning

4.Evolutionary Computing
5.Neural Networks
6.Planning



ใช้ตัดสิ นใจ (Decision)
◦ จาแนกขอมู
้ ล (Classify)

ค้นหา (Search)
◦ แกสมการ
้
◦ หาระยะทาง

พยากรณ ์ (Prediction)
◦ คาดการ
◦ เดาอยางมี
เหตุผล
่


ภาษายุคแรกทีใ่ ช้พัฒนาปัญญาประดิษฐ ์
Lisp (By John Mccharthy)
◦ เป็ นภาษาระดับสูงในสมัยนั้น
◦ ใช้ในการคานวณทางคณิตศาสตร ์

PROLOG (By Alain Colmerauer)
◦ ใช้หลักตรรกะ
◦ Graph, Search




1956 John Mctarthy ไดชั
ั ทัว
่ อเมริกาที่
้ กชวนนักวิจย
สนใจการศึ กษาด้ าน Automata
และ Neural
Network( โครงขายประสาทเที
ยม) มาจัดสั มนาและ
่
กอตั
่ ง้ สาขาวิชานี้วา่ “ปัญญาประดิษฐ”์
1952-1969 ยุคตืน
่ ตัว
1970-1980 ยุคมืด(เนื่องจาก)
1980-ปัจจุบน
ั ยุคเขาสู
้ ่ อุตสาหกรรม
•History -1960's
•First computer games
•Space War! (PDP1, for two human players)
(1962)
•Board games (e.g. chess) against the
• History -1970's
• Pong (early arcade game) (1972)
• Computer controlled opponent in arcade
games
• Space Invaders (1978)
• “AI” takes 1-2% of CPU
•
•
•
•
•
History -1990’s
FPS and RTS games
Games about/with evolution and learning
Graphic cards take the load off the CPU
“AI” takes 10-35% of CPU

Computer games is big
industry
◦ Games sell for about 25 billion
USD per year
◦ Market grows with 16% per year
◦ A game project: 2 years, 8-15
million USD
Less cheating in AI
 Characters are more aware
 Characters collaborate better


เป็ นการน าปัญ ญาประดิษฐ ไปประยุ
กต ใช
์
์ ้ ในซอร ฟแวร
์
์
ด้ านบัน เทิง โดยส่ วนใหญ่จะเป็ นการน าไปใช้ ในการ
เพิ่ม ประสิ ท ธิภ าพให้ เกมมีค วามน่ าสนใจมากขึ้น เป็ น
การเพิ่ม ความท้ าทายให้ กับ ผู้ เล่ น ช่ วยให้ ผู้ เล่ นรู้ สึ ก
เหมือนกับเกมมีระบบความคิดเป็ นของตนเอง

Deep Blue was a chess-playing
computer developed by IBM. On
May 11, 1997, the machine won a
six-game match by two wins to one
with three draws against world
champion Garry Kasparov.









RTS = Real Time Strategy ก็คือเกมแนววางแผนการรบ Red Alert
TBS = Turn-Base Strategy เกมแนววางแผนแบบผลัดกันเล่นคนละตา
Hero
Simulation : Microsoft Flight Simulator
FPS = First Person Shooting มุมมองบุคคลที่ 1Counter Strike.
TPS = Third Person Shooting มุมมองบุคคลที่ 3
Side Scrolling Game : Mario
RPG = Role-Playing Game ไฟนอทแฟนตาซี
MMORPG = Massive Multiplayer Online Role-Playing Game
Sport = Sport Game Winning
◦ Strategically/Tactical Decisions
 Against or with you
 Search for best counter action
 Adaptively
◦ Simulation
 of natural behavior
 for animation (e.g. bird flocks)
◦ Shortest path problems
Introduction : AI in
Computer Games
•AI in various game types
•Role playing games
•AI in enemies, bosses, party members, shopkeeper
and other NPCs, ...
•Conversations (grammar machines)
•Messaging - communicate
•Scripting - story
•FSMs -state
•Quest generators
Introduction : AI in
Computer Games
•AI
in various game types
•Role playing games
•First Person \Third Person Shooters
Introduction : AI in
Computer Games
•AI in various game types
•First Person \Third Person Shooters
•Enemies ,Weapons
•requires a good physics engine
•Cooperative agents
•Attention
•Pathfinding
Introduction : AI in
Computer Games
•AI in various game types
•First Person \Third Person Shooters
Introduction : AI in
Computer Games
•AI
in various game types
•Role playing games
•First Person \Third Person Shooters
•Strategy games
Introduction : AI in
Computer Games
•AI in various game types
•Strategy games
•AI heavy (on both sides)
•Shortest path problems
•Strategical decisions
•Town building and resource management
•Planning
•Life
•Diplomacy
•Know thy enemy (observe and adapt)
Introduction : AI in
Computer Games
•AI in various game types
•Strategy games
Introduction : AI in Computer Games
AI in various game types
Platform and sports games
Platform games
Since 1996 (Mario 64) in 3D
Camera problems
Sports games
Cooperation
Learning
Game balance can be difficult
Camera problems (harder)
Introduction : AI in Computer Games
AI in various game types
Platform and sports games
Introduction : AI in Computer Games
AI in various game types
Role playing games
First Person \Third Person Shooters
Strategy games
Platform and sports games
Racing games
Introduction : AI in
Computer Games
•AI
in various game types
•Racing games
•Track AI
•Traffic (including pedestrians)
•Tuning NPCs and vehicle parameters
•Physics
◦ Math
◦ Finite State Machines (FSM)
 Behavior
◦ A*
 For shortest path problems
◦ Particle methods
 Simulation of flocks, smoke, water, grass,...
◦ Fuzzy Logic
 Decision
◦ Genetic Algorithm
 Search
◦ K-Nearest Neighbor
 Search
◦ Particle Swarm Intelligent
 Search
◦ Artificial Neural Network
 Classify, Predict and Descript Memory

The function of any representation
scheme is to capture the essential feature
of a problem domain and make that
information accessible to a problem
solving procedure
ตัวอย่าThe
ง real number
The decimal equivalent
3.
The floating point
32426|1
The representation in computer memory 11


ปัญหาส่วนมากในโลกนั้นไมได
างที
ช
่ ด
ั เจน
่ อยู
้ ในโครงสร
่
้
เช่น ทาไมผู้หญิงคนนี้ถงึ สวย ทาไมผู้ชายคนนีถ
้ งึ หลอ
่
เราจึงตองแปลงปั
ญหาเหลานี
ปแบบของ
้
่ ้ให้อยูในรู
่
โครงสราง
เพือ
่ ให้ปัญญาประดิษฐสามารถเรี
ยนรูได
้
้ ้
์
ปัญห
า
กระบวนกา
รแปลง
ปัญหา
โครงสราง
้
ขอมู
้ ล
อัลกอริทม
ึ
ปัญห
า
กระบวนกา
รแปลง
ปัญหา
ทาไมผู้หญิง
สวย
กระบวนกา
รแปลง
ปัญหา
โครงสราง
้
ขอมู
้ ล
อัลกอริทม
ึ
ความขาว
ของผิว
อัตราส่วนระหวางความสู
ง
่
กับ นน.
Fuzzy Logic



ปัญหาดานปั
ญญาประดิษฐ ์ แบงเป็
้
่ น 2 ประเภท คือ
1.ปัญหาของเลน
่ ี
่ (Toy Problem) เป็ นปัญหาทีม
รายละเอียดสั้ น ชัดเจนไมซั
่ บซ้อน เช่น เกม และ
ปัญหาเล็กๆ ทัว่ ไป
2.ปัญหาในโลกของความเป็ นจริง (Real-World
Problem) เป็ นปัญหาทีม
่ ค
ี วามซับซ้อนและรายละเอียด
มาก เช่น ปัญหาการเดินทางของพนักงานขาย
(Traveling Salesman Problem : TSP) ปัญหาการ
จัดลาดับการผลิต (Sequencing)

การแก้ ไขปั ญ หาเป็ นการน าปั ญ หามาวิ เ คราะห ์ เป็ น
ขัน
้ ตอน เพือ
่ ค้นหาเป้าหมายทีต
่ ้องการ โดยการแกไข
้
ปั ญ หาในด้ านปั ญ หาประดิษ ฐ จะมองปั
ญ หาให้ อยู่ ใน
์
รู ป แบบของการค้ นหา เพื่อ ให้ เราได้ สรุ ป ประเด็ น ของ
ปัญหาและคาตอบรวมถึงปัจจัยควบคุมอืน
่ ๆ นั้นก็คอ
ื การ
Mapping Input/Output
“เราจะจัดการน้ายังไงให้น้าไมท
งเทพ”
่ วมกรุ
่
“เราปิ ดและเปิ ดประตูน้ายังไงให้น้าไมท
งเท
่ วมกรุ
่
“เราปิ ดและเปิ ดประตูน้ายังไงให้น้าไหลลงสู่ทะเ



Goal Formulation
กาหนดเป้าหมายซึง่ มี
ความสาคัญมากทีส
่ ุดและ
จะตองอยู
ในขอบเขตที
ต
่ ง้ั ไว้
้
่
Problem Formulation การอธิบายปัญหาให้อยูใน
่
รูปแบบ
มาตราฐาน Well – Defined Problem
Select Algorithm
ปัญหา
เป็ นการเลือกเทคนิคในการแกไข
้

Initial State
ปัญหา
 Successor
กาหนดสถานะเริม
่ ตนของ
้
Functions
กาหนดเซตของการ
กระทาทัง้ หมดทีเ่ ป็ นไปได้
 Goal State
กาหนดสถานะเป้าหมายที่
เป็ นไปได้
 Path Cost
กาหนดคาใช
อ
่
้จายหรื
่
ทรัพยากรทีใ่ ช้ทัง้ หมด
การจาก
แกไขปั
ญหา
้

หุ่ นยนต จะท
าหน้ าที่ข จัด สิ่ งปรกโดยการดู ด (Suck)
์
ดวยอุ
ปกรณท
กาหนดให้
้
์ าความสะอาดของหุ่นยนตเอง
์
มีห้องจานวนสองห้องทีห
่ ุ่นยนตต
์ ้องทาความสะอาด คือ
ห้องฝั่งซ้าย(Left)และห้องฝั่งขวา(Right) โดยกาหนดให้
สถานะเริม
่ ตนคื
อยู
้ อ ตาแหน่งของหุนยนต
่
่ ่ งซ้าย
์ ฝั
เครื่อง
ดูด
หุ่นยน
ต์




Initial State :
กาหนดให้ตาแหน่งหุ่นยนตอยู
์ ่
ฝั่งซ้าย
Successor Function: เซตการกระท าเป็ นไปได้ 3
ทาง
{Left, Right, Suck}
Goal State
:
พืน
้ ของทุกห้องสะอาด
Path Cost
:
จ านวนการเคลื่อ นที่แ ต่ละครั้ง
สถานะเริม
่ ตน
้
3 2 6
5
7
8 4 1




สถานะเป้าหมาย
1 2 3
4 5 6
7 8
Initial State :
ส ถ า น ะ เ ริ่ ม ต้ น รู ป
ทางดานซ
้
้ายมือ
Successor Function:
4
ทางได้แก่
{Left, Right, Up, Down}
Goal State
:
ส ถ า น ะ เ ป้ า ห ม า ย
ทางดานรู
ปขวา
้
Path Cost
:
จานวนการเคลือ
่ นทีแ
่ ต่




Initial State :
สถานะเริม
่ ตนรู
้ ปทางดานซ
้
้ายมือ
Successor Function:
เ พิ่ ม จ า น ว น Queen
(จุดสี แดง)ลงในช่องวาง
่
Goal State
:
ตาแหน่งของ Queen ทัง้ 8
ตัวทีว่ างอยูบนกระดาน
หมาก
่
รุก จะตองไม
มี
่ ามารถโจมตีกน
ั ได้
้
่ Queen ตัวใดทีส
Path Cost
:
เวลาในการคานวณ
I
A
B
D
C
J
E
F
F
H


Initial State :
สถานะเริ่ม ต้ นรู ป
ดังรูป
Successor Function:
สามารถ
เดินทางระหวางเมื
องได้
่
I
A
B
D
C
J
E
F
F
H

Eucedian
distance
 Completeness
สามารถคนหา
้
คาตอบไดหรื
้ อไม่
 Optimality
สามารถคาหา
้
คาตอบทีด
่ ท
ี ส
ี่ ด
ุ ได้
 Time Complexity
เวลาทีใ่ ช้ใน
การคานวณ
 Space Complexity
พืน
้ ที่
หน่วยความจาทีใ่ ช้
 อางอิ
งจาก Russell and Norvig, 2003
้
 การเขียนโปรแกรมแบบ
For Loop
 การเขียนโปรแกรมแบบ Recursive
 สามารถหาคาตอบไดเหมื
อนกัน?
้
กวากั
 แลวแบบไหนดี
่ น
้
◦ ภาษา มีคนอางว
ยนแบบ Recursive
้ าการเขี
่
อานง
ายกว
า่ Loop
่
่
◦ ปัญหา
คือ ฟังกชั
่ ทีเ่ รียกใช้ตัวเ
์ น
ใช้ในการคานวณทางคณิต
1. n!
= n * (n – 1) !
= n * (n – 1) * (n – 2) !
= n * (n – 1) * (n – 2) * (n – 3
2.0! = 1
4!
= 4 * (4 – 1)!
= 4 * 3 * (3 – 1)!
= 4 * 3 * 2 * (2 – 1)!
= 4 * 3 * 2 * 1 * (1 – 1)!
= 4 * 3 * 2 * 1 * 0!
ดังนั้น
4! = 4 * 3 * 2 * 1 = 24
Loop
//Factorial by Forloop
class Fac_For
{
public static void
main(String[] args)
{
int n=4;
int result=1;
for (int i=1;i<=n ;i++ )
{
result =result*i;
}
System.out.println(result);
}
}
Recursive
//Factorail by Recursive
class Fac_Recursive
{
public static void main(String[]
args)
{
int ans;
ans=Fac(5);
System.out.println(ans);
}
public static int Fac(int n)
{
int result=0;
if (n==0)
{
return 1;
}
else
{
return n*Fac(n-1);
}
}
}
http://www.youtube.com/watch?v=P0tLbl5LrJ8

สมการ
และ