Week16 4/June/2008
Instructor: I-Hsien Ting
Neural Network
細胞體
樹狀突
軸索
There are about
1011
neurons in a adult’s
brain
Each neuron can be contacted by other 104
neurons
Neural Network for Game
◦
Generally, only about
10
neurons will be used for
digital games
◦
Sometimes, a simple network is very useful for us
to solve problems
◦
Neural Network makes the concept of
“Adapting”
Some digital game applications use the neural
network the entire AI
◦
So-called:
Giant Neural Network
However, neural network is a
time-consuming task
◦
Use Neural Network only for part or special AI
function
Hidden Layer
activation
function
W eight
友軍 容許擊中次數 敵人是否交戰 距離
追逐
群聚
閃躲
0
1
0
0.2
0.9
0.1
0.1
0
1
1
0.2
0.9
0.1
0.1
0
1
0
0.8
0.1
0.1
0.1
0.01 0.5
0
0.2
0.9
0.1
0.1
0
0.25
1
0.5
0.1
0.9
0.1
0
0.2
1
0.2
0.1
0.1
0.9
0.3
0.2
0
0.2
0.9
0.1
0.1
0
0.2
0
0.3
0.1
0.9
0.1
0
1
0
0.2
0.1
0.9
0.1
0
1
1
0.6
0.1
0.1
0.1
0
1
0
0.8
0.1
0.9
0.1
0.1
0.2
0
0.2
0.1
0.1
0.9
0
0.25
1
0.5
0.1
0.1
0.9
0
0.6
0
0.2
0.1
0.1
0.9
A ideal solution for game difficulty
optimization
Based on the evolution theory that defined by
Charles Darwin on 1859
Natural Selection & Fitness
◦
Chromosome (DNA& Protein)
◦
Biological
A
D
Z
Y
R
N
X
E
T
W
H
A
H
D
E
Y
A
W
Z
A
R
D
X
Y
A
D
Z
Y
R
N
X
E
T
W
H
A
H
D
E
Y
A
J
Z
A
R
P
X
Y
void ai_World::Encode(void)
// --- //
{
int
i;
for (i=1;i<kMaxFlowers;i++)
{
temperature[i]=tb_Rnd(1,75);
water[i]=tb_Rnd(1,75);
sunlight[i]=tb_Rnd(1,75);
nutrient[i]=tb_Rnd(1,75);
beneficialInsect[i]=tb_Rnd(1,75);
harmfulInsect[i]=tb_Rnd(1,75);
}
currentTemperature=tb_Rnd(1,75);
currentWater=tb_Rnd(1,75);
currentSunlight=tb_Rnd(1,75);
currentNutrient=tb_Rnd(1,75);
currentBeneficialInsect=tb_Rnd(1,75);
currentHarmfulInsect=tb_Rnd(1,75);
}
// --- //
int ai_World::Fitness(int flower)
// --- //
{
int
theFitness;
theFitness=fabs(temperature[flower]-currentTemperature);
theFitness=theFitness+fabs(water[flower]-currentWater);
theFitness=theFitness+fabs(sunlight[flower]-currentSunlight);
theFitness=theFitness+fabs(nutrient[flower]-currentNutrient);
theFitness=theFitness+fabs(beneficialInsect[flower]-currentBeneficialInsect);
theFitness=theFitness+fabs(harmfulInsect[flower]-currentHarmfulInsect);
return (theFitness);
}
void ai_World::Evolve(void) // --- // { int fitTemperature[kMaxFlowers]; int fitWater[kMaxFlowers]; int fitSunlight[kMaxFlowers]; int fitNutrient[kMaxFlowers]; int fitBeneficialInsect[kMaxFlowers]; int fitHarmfulInsect[kMaxFlowers]; int i; int leastFit=0; int leastFitIndex; for (i=1;i<kMaxFlowers;i++) if (Fitness(i)>leastFit) { leastFit=Fitness(i); leastFitIndex=i; } temperature[leastFitIndex]=temperature[tb_Rnd(1,10)]; water[leastFitIndex]=water[tb_Rnd(1,10)]; sunlight[leastFitIndex]=sunlight[tb_Rnd(1,10)]; nutrient[leastFitIndex]=nutrient[tb_Rnd(1,10)]; beneficialInsect[leastFitIndex]=beneficialInsect[tb_Rnd(1,10)]; harmfulInsect[leastFitIndex]=harmfulInsect[tb_Rnd(1,10)];
for (i=1;i<kMaxFlowers;i++) { fitTemperature[i]=temperature[tb_Rnd(1,10)]; fitWater[i]=water[tb_Rnd(1,10)]; fitSunlight[i]=sunlight[tb_Rnd(1,10)]; fitNutrient[i]=nutrient[tb_Rnd(1,10)]; fitBeneficialInsect[i]=beneficialInsect[tb_Rnd(1,10)]; fitHarmfulInsect[i]=harmfulInsect[tb_Rnd(1,10)]; } for (i=1;i<kMaxFlowers;i++) { temperature[i]=fitTemperature[i]; water[i]=fitWater[i]; sunlight[i]=fitSunlight[i]; nutrient[i]=fitNutrient[i]; beneficialInsect[i]=fitBeneficialInsect[i]; harmfulInsect[i]=fitHarmfulInsect[i]; } for (i=1;i<kMaxFlowers;i++) { if (tb_Rnd(1,100)==1) temperature[i]=tb_Rnd(1,75); if (tb_Rnd(1,100)==1) water[i]=tb_Rnd(1,75); if (tb_Rnd(1,100)==1) sunlight[i]=tb_Rnd(1,75); if (tb_Rnd(1,100)==1) nutrient[i]=tb_Rnd(1,75); if (tb_Rnd(1,100)==1) beneficialInsect[i]=tb_Rnd(1,75); if (tb_Rnd(1,100)==1) harmfulInsect[i]=tb_Rnd(1,75); }}