-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomLoop.cs
56 lines (49 loc) · 1.67 KB
/
RandomLoop.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hawk_Dove
{
internal class RandomLoop
{
// random that creates seeds for each random run
// makes sure that it is re-creatable
public readonly int masterSeed;
readonly Random masterRandom;
const int antiRandomIterations = 100;
// fixed values
public readonly int initialAggresionAgent1;
public readonly int initialAggresionAgent2;
public RandomLoop(int seed, int ia1, int ia2)
{
masterSeed = seed;
masterRandom = new Random(masterSeed);
initialAggresionAgent1 = ia1;
initialAggresionAgent2 = ia2;
}
public double RandomFlatLineMean()
{
// algorithm
int[] resultIndexes = new int[antiRandomIterations];
// Collection of runs
InnerLoop[] runs = new InnerLoop[antiRandomIterations];
for (int i = 0; i < antiRandomIterations; i++)
{
int innerLoopSeed = masterRandom.Next(0, int.MaxValue);
InnerLoop run = new(initialAggresionAgent1
, initialAggresionAgent2
, innerLoopSeed
, i);
runs[i] = run;
}
foreach (var currentElement in runs)
{
int i = currentElement.runNum;
int result = currentElement.FlatLineIndex();
resultIndexes[i] = result;
}
return resultIndexes.Average();
}
}
}