-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGen.cs
More file actions
53 lines (50 loc) · 1.35 KB
/
Gen.cs
File metadata and controls
53 lines (50 loc) · 1.35 KB
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
using System;
using static population.Common;
namespace population
{
class Gen
{
private byte[] gen;
public int capas { get; } = 82;
public Gen(int size)
{
gen = new byte[size];
}
private void Normalize(ref int index)
{
index = (index + gen.Length) % gen.Length;
}
public byte this[int index]
{
get
{
Normalize(ref index);
return gen[index];
}
}
public void LoadValue(byte value)
{
for (int i = 0; i < gen.Length; i++) gen[i] = value;
}
public void LoadRandom()
{
for (int i = 0; i < gen.Length; i++) gen[i] = RandByte(capas);
}
public Gen GetDuplicate(bool mutation)
{
Gen newGen = new Gen(gen.Length);
if(!mutation)
{
for (int i = 0; i < gen.Length; i++) newGen.gen[i] = gen[i];
}
else
{
int where = rand.Next(gen.Length);
newGen.gen[where] = RandByte(capas);
for (int i = 0; i < where; i++) newGen.gen[i] = gen[i];
for (int i = where + 1; i < gen.Length; i++) newGen.gen[i] = gen[i];
}
return newGen;
}
}
}