-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operator.cs
74 lines (70 loc) · 2.71 KB
/
Operator.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.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Operator : Node {
public override void Mutate(int range, float probability)
{
Debug.Assert(probability >= 0 && probability <= 1);
if(false)//change operator to another operator or an operand
{
//Debug.Log("from this view: " + this.Parent.GetType() + " " + this.GetType() + " " + this.Child1.GetType() + " " + this.Child2.GetType());
// Debug.Log("from parent: " + this.Parent.Child1.GetType());
//Debug.Log("from child view: " + this.Child2.Parent.GetType() + " " + this.Child2.Parent.GetType());
float decide = Random.Range(0.0f, 8.0f);
if(decide < 0)
{
//Debug.Log("changing operator to add");
Node newNode = new Add_Operator();
this.replaceNode(newNode);
}else if(decide < 1)
{
//Debug.Log("changing operator to minus");
Node newNode = new Minus_Operator();
this.replaceNode(newNode);
}else if(decide < 2)
{
//Debug.Log("changing operator to mult");
Node newNode = new Multiply_Operator();
this.replaceNode(newNode);
}else if(decide < 3)
{
//Debug.Log("changing operator to divide");
Node newNode = new Divide_Operator();
this.replaceNode(newNode);
}else if(decide < 4)
{
//Debug.Log("changing operator to cos");
Node newNode = new Cosine_Operator();
this.replaceNode(newNode);
}else if(decide < 5)
{
//Debug.Log("changing operator to sin");
Node newNode = new Sin_Operator();
this.replaceNode(newNode);
}else if(decide < 6)
{
//Debug.Log("changing operator to exponent");
Node newNode = new Exponent_Operator();
this.replaceNode(newNode);
}else if(decide < 7)
{
//Debug.Log("changing operator to operand");
Node newNode = new Operand(Random.Range(-range, range));
this.replaceNode(newNode);
}else if(decide < 8)
{
//Debug.Log("changing operator to variable");
Node newNode = new Variable();
this.replaceNode(newNode);
}
}
if (Child1 != null)
{
Child1.Mutate(range, probability);
}
if(Child2 != null)
{
Child2.Mutate(range, probability);
}
}
}