This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mutation.cs
74 lines (73 loc) · 2.61 KB
/
Mutation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
namespace EnemyGenerator
{
/// This class holds the mutation operator.
public class Mutation
{
/// Reproduce a new individual by mutating a parent.
public static Individual Apply(
Individual _parent,
int _chance,
ref Random _rand
) {
Individual individual = _parent.Clone();
// Apply mutation on enemy attributes
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.health = Common.RandomInt(
SearchSpace.Instance.rHealth, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.strength = Common.RandomInt(
SearchSpace.Instance.rStrength, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.attackSpeed = Common.RandomFloat(
SearchSpace.Instance.rAttackSpeed, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.movementType = Common.RandomElementFromArray(
SearchSpace.Instance.rMovementType, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.movementSpeed = Common.RandomFloat(
SearchSpace.Instance.rMovementSpeed, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.activeTime = Common.RandomFloat(
SearchSpace.Instance.rActiveTime, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.enemy.restTime = Common.RandomFloat(
SearchSpace.Instance.rRestTime, ref _rand
);
}
// Apply mutation on weapon attributes
if (_chance > Common.RandomPercent(ref _rand))
{
individual.weapon.weaponType = Common.RandomElementFromArray(
SearchSpace.Instance.rWeaponType, ref _rand
);
}
if (_chance > Common.RandomPercent(ref _rand))
{
individual.weapon.projectileSpeed = Common.RandomFloat(
SearchSpace.Instance.rProjectileSpeed, ref _rand
);
}
return individual;
}
}
}