Skip to content

Commit 75a93e6

Browse files
committed
Move some string consts
1 parent 14df3cc commit 75a93e6

File tree

8 files changed

+48
-37
lines changed

8 files changed

+48
-37
lines changed

Runtime/Clonable.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ namespace Activ.GOAP{
22
public interface Clonable<T>{
33

44
T Allocate ();
5-
65
T Clone (T storage);
76

87
}}

Runtime/Details/ActionMap.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using static Activ.GOAP.Strings;
45
#if UNITY_2018_1_OR_NEWER
56
using UnityEngine;
67
#endif
@@ -23,9 +24,7 @@ int frameCount{get{
2324
void ActionHandler.Effect<T>(object action, GameAI<T> client){
2425
switch(action){
2526
case string noArg:
26-
// TODO should be Solver.INIT but move that constant
27-
// somewhere else first
28-
if(noArg == "%init") return;
27+
if(noArg == INITIAL_STATE) return;
2928
Print($"No-arg: {noArg} @{frameCount}");
3029
Map(noArg, client).Invoke(client, NoArg);
3130
return;
@@ -37,7 +36,7 @@ void ActionHandler.Effect<T>(object action, GameAI<T> client){
3736
client.Idle();
3837
return;
3938
default:
40-
throw new ArgumentException($"Unknown arg: " + action);
39+
throw new ArgumentException(UNKNOWN_ARG + action);
4140
}
4241
}
4342

Runtime/Details/NodeSet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using static Activ.GOAP.Strings;
34

45
namespace Activ.GOAP{
56
public class NodeSet<T> : Base{
@@ -19,8 +20,7 @@ public NodeSet(T x, Func<T, float> h, bool sorted = true,
1920
this.capacity = capacity;
2021
this.precision = precision;
2122
states.Add(Assert(x, "Initial state"));
22-
// TODO INIT const
23-
list.Add(new Node<T>("%init", x));
23+
list.Add(new Node<T>(INITIAL_STATE, x));
2424
}
2525

2626
public bool capacityExceeded => count > capacity;

Runtime/Details/Strings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Activ.GOAP{
2+
public class Strings{
3+
4+
internal const string INITIAL_STATE = "%init",
5+
ZERO_COST_ERR = "Zero cost not allowed",
6+
NO_INIT_ERR = "Init state is null",
7+
UNKNOWN_ARG = "Unknown arg: ";
8+
9+
}}

Runtime/Solver.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,17 @@
33
using Ex = System.Exception;
44
using InvOp = System.InvalidOperationException;
55
using S = Activ.GOAP.PlanningState;
6+
using static Activ.GOAP.Strings;
67

78
namespace Activ.GOAP{
89
public class Solver<T> : SolverStats where T : class{
910

10-
public const string INIT = "%init";
11-
const string ZERO_COST_ERR = "Zero cost op is not allowed",
12-
NO_INIT = "Init state is null";
13-
//
14-
public int maxNodes = 1000,
15-
maxIter = 1000;
16-
public float tolerance = 0f;
17-
public bool brfs = false;
18-
public bool cleanActions = true;
11+
public int maxNodes = 1000, maxIter = 1000;
12+
public float tolerance;
13+
public bool brfs, cleanActions = true;
1914
public PlanningState status { get; private set; }
20-
public int fxMaxNodes { get; private set; }
21-
public int I { get; private set; }
15+
public int fxMaxNodes { get; private set; }
16+
public int I { get; private set; }
2217
//
2318
T initialState;
2419
Dish<T> dish;
@@ -28,7 +23,7 @@ public class Solver<T> : SolverStats where T : class{
2823
public bool isRunning => status == S.Running;
2924

3025
public Node<T> Next(T s, in Goal<T> g, int iter=-1){
31-
if(s == null) throw new NullRef(NO_INIT);
26+
if(s == null) throw new NullRef(NO_INIT_ERR);
3227
if(dish == null) dish = (s is Clonable<T> && cleanActions)
3328
? (Dish<T>)new DirtyDish<T>() : new PolyDish<T>();
3429
initialState = s;
@@ -40,7 +35,7 @@ public Node<T> Next(T s, in Goal<T> g, int iter=-1){
4035
}
4136

4237
public Node<T> Iterate(int iter=-1){
43-
if(initialState == null) throw new InvOp(NO_INIT);
38+
if(initialState == null) throw new InvOp(NO_INIT_ERR);
4439
if(status == S.MaxIterExceeded) return null;
4540
if(iter == -1) iter = maxIter;
4641
int i = 0;

Tests/Editor/NodeSetTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System; using NUnit.Framework;
22
using static Activ.GOAP.Solver<Activ.GOAP.Idler>;
3+
using static Activ.GOAP.Strings;
34

45
namespace Activ.GOAP{
56
public class NodeSetTest : TestBase{
@@ -38,7 +39,7 @@ [Test] public void InsertAndSort(){
3839

3940
[Test] public void Pop(){
4041
var z = x.Pop(); o( x.count, 0 ); o( z.state is Idler );
41-
o( z.action, INIT);
42+
o( z.action, INITIAL_STATE);
4243
}
4344

4445
class T{

Tests/Editor/NodeTest.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NUnit.Framework;
33
using NullRef = System.NullReferenceException;
44
using static Activ.GOAP.Solver<Activ.GOAP.Agent>;
5+
using static Activ.GOAP.Strings;
56

67
namespace Activ.GOAP{
78
public class NodeTest : TestBase{
@@ -54,46 +55,52 @@ [Test] public void Path1(){
5455
}
5556

5657
[Test] public void Head2(){
57-
var x = new Node<object>(INIT, new object());
58+
var x = new Node<object>(INITIAL_STATE, new object());
5859
var y = new Node<object>(ACTION_1, new object(), x);
5960
o( y.Head(), ACTION_1);
6061
}
6162

6263
[Test] public void Path2(){
63-
var x = new Node<object>(INIT, new object());
64+
var x = new Node<object>(INITIAL_STATE, new object());
6465
var y = new Node<object>(ACTION_1, new object(), x);
6566
var path = y.Path();
66-
o( path[0].ToString(), "[0.0 :: %init => object]");
67-
o( path[1].ToString(), "[0.0 :: Test => object]");
67+
o( path[0].ToString(),
68+
$"[0.0 :: {INITIAL_STATE} => object]");
69+
o( path[1].ToString(),
70+
"[0.0 :: Test => object]");
6871
}
6972

7073
[Test] public void Head3(){
71-
var x = new Node<object>(INIT, new object());
74+
var x = new Node<object>(INITIAL_STATE, new object());
7275
var y = new Node<object>(ACTION_1, new object(), x);
7376
var z = new Node<object>(ACTION_2, new object(), y);
7477
o( z.Head(), ACTION_1);
7578
}
7679

7780
[Test] public void Path3(){
78-
var x = new Node<object>(INIT, new object());
81+
var x = new Node<object>(INITIAL_STATE, new object());
7982
var y = new Node<object>(ACTION_1, new object(), x);
8083
var z = new Node<object>(ACTION_2, new object(), y);
8184
var path = z.Path();
82-
o( path[0].ToString(), "[0.0 :: %init => object]");
83-
o( path[1].ToString(), "[0.0 :: Test => object]");
84-
o( path[2].ToString(), "[0.0 :: Test => object]");
85+
o( path[0].ToString(),
86+
$"[0.0 :: {INITIAL_STATE} => object]");
87+
o( path[1].ToString(),
88+
"[0.0 :: Test => object]");
89+
o( path[2].ToString(),
90+
"[0.0 :: Test => object]");
8591
}
8692

8793
[Test] public void PathToString(){
88-
var x = new Node<object>(INIT, new object());
94+
var x = new Node<object>(INITIAL_STATE, new object());
8995
var y = new Node<object>(ACTION_1, new object(), x);
9096
var path = y.PathToString();
9197
o(path, "%init\nTest\n");
9298
}
9399

94100
[Test] public void String(){
95-
var x = new Node<object>(INIT, new object());
96-
o( x.ToString(), "[0.0 :: %init => object]" );
101+
var x = new Node<object>(INITIAL_STATE, new object());
102+
o( x.ToString(),
103+
$"[0.0 :: {INITIAL_STATE} => object]" );
97104
}
98105

99106
}}

Tests/Editor/SolverTest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Ex = System.Exception;
44
using InvOp = System.InvalidOperationException;
55
using static Activ.GOAP.Solver<Activ.GOAP.Agent>;
6+
using static Activ.GOAP.Strings;
67

78
namespace Activ.GOAP{
89
public class SolverTest : TestBase{
@@ -46,17 +47,17 @@ [Test] public void Next_no_agent_throws()
4647
() => x.Next((Agent)null, unreachable) );
4748

4849
[Test] public void Next_start_at_goal()
49-
=> o ( (string)x.Next(new Idler(), stasis), INIT );
50+
=> o ( (string)x.Next(new Idler(), stasis), INITIAL_STATE );
5051

5152
[Test] public void Next_start_at_goal_with_heuristic()
5253
=> o ( (string)x.Next( new Idler(),
53-
hStasis), INIT );
54+
hStasis), INITIAL_STATE );
5455

5556
[Test] public void Next_OTPoneyPassThrough()
56-
=> o( (string)x.Next(new OTPoney(), stasis), INIT );
57+
=> o( (string)x.Next(new OTPoney(), stasis), INITIAL_STATE );
5758

5859
[Test] public void Next_HeuristicOTPoneyPassThrough()
59-
=> o( (string)x.Next(new OTPoney(), hStasis), INIT );
60+
=> o( (string)x.Next(new OTPoney(), hStasis), INITIAL_STATE );
6061

6162
[Test] public void Next_use_heuristic(){
6263
bool h = false;

0 commit comments

Comments
 (0)