Skip to content

Commit fb1f6b8

Browse files
committed
removed movepicker class
1 parent 34a3473 commit fb1f6b8

File tree

6 files changed

+22
-41
lines changed

6 files changed

+22
-41
lines changed

NoraGrace/NoraGrace.Engine.Tests/MovegenTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void PerftTest(string fen, int depth, int expectedLeaves, int expectedNod
117117

118118
int nodecount = -1;//start at -1 to skip root node
119119
int leafnodecount = 0;
120-
MovePicker.Stack moveBuffer = new MovePicker.Stack();
120+
MovePicker[] moveBuffer = MovePicker.CreateStack();
121121

122122
PerftSearch(board, 0, moveBuffer, depth, ref nodecount, ref leafnodecount);
123123

@@ -129,7 +129,7 @@ public void PerftTest(string fen, int depth, int expectedLeaves, int expectedNod
129129

130130
}
131131

132-
public void PerftSearch(Board board, int ply, MovePicker.Stack moveBuffer, int depth_remaining, ref int nodecount, ref int leafnodecount)
132+
public void PerftSearch(Board board, int ply, IList<MovePicker> moveBuffer, int depth_remaining, ref int nodecount, ref int leafnodecount)
133133
{
134134
nodecount++;
135135

NoraGrace/NoraGrace.Engine/MovePicker.cs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,16 @@ namespace NoraGrace.Engine
1212
public class MovePicker
1313
{
1414

15-
public class Stack
15+
public static MovePicker[] CreateStack(int max_ply = 50)
1616
{
17-
List<MovePicker> _plyBuffers = new List<MovePicker>();
18-
public readonly MoveHistory History = new MoveHistory();
19-
StaticExchange _see = new StaticExchange();
20-
public Stack(int plyCapacity = 50)
17+
MovePicker[] retval = new MovePicker[max_ply + 1];
18+
MoveHistory history = new MoveHistory();
19+
StaticExchange see = new StaticExchange();
20+
for (int i = 0; i < max_ply + 1; i++)
2121
{
22-
while (_plyBuffers.Count < plyCapacity)
23-
{
24-
_plyBuffers.Add(new MovePicker(History, _see));
25-
}
26-
}
27-
28-
public MovePicker this[int ply]
29-
{
30-
get
31-
{
32-
System.Diagnostics.Debug.Assert(ply >= 0);
33-
if (ply > _plyBuffers.Count)
34-
{
35-
for (int i = 0; i < 10; i++)
36-
{
37-
_plyBuffers.Add(new MovePicker(History, _see));
38-
}
39-
}
40-
return _plyBuffers[ply];
41-
}
22+
retval[i] = new MovePicker(history, see);
4223
}
43-
24+
return retval;
4425
}
4526

4627
public class MoveHistory

NoraGrace/NoraGrace.EvalTune2/BinaryPGN.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@ public static void Write(BinaryPGN pgn, System.IO.BinaryWriter writer)
250250

251251

252252

253-
private static NoraGrace.Engine.MovePicker.Stack _mpsQuiet;
253+
private static IList<MovePicker> _mpsQuiet;
254254
public static bool PositionQuiet(Board board)
255255
{
256-
if (_mpsQuiet == null) { _mpsQuiet = new MovePicker.Stack(); }
256+
if (_mpsQuiet == null) { _mpsQuiet = MovePicker.CreateStack(); }
257257
var x = QSearchQuiet(board, _mpsQuiet);
258258
return x <= 0;
259259
}
260260

261-
private static int QSearchQuiet(Board board, MovePicker.Stack moveStack, int ply = 0)
261+
private static int QSearchQuiet(Board board, IList<MovePicker> moveStack, int ply = 0)
262262
{
263263
if (ply >= 10) { return 0; }
264264
var plyMoves = moveStack[ply];

NoraGrace/NoraGrace.EvalTune2/Fitness.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static double PgnListEParallel(IEnumerable<BinaryPGN> pgnList, Func<Engin
2626
double sum = 0;
2727
int count = 0;
2828
object _resultLock = new object();
29-
Dictionary<System.Threading.Thread, Tuple<Evaluator, MovePicker.Stack>> dic = new Dictionary<System.Threading.Thread, Tuple<Evaluator, MovePicker.Stack>>();
29+
Dictionary<System.Threading.Thread, Tuple<Evaluator, IList<MovePicker>>> dic = new Dictionary<System.Threading.Thread, Tuple<Evaluator, IList<MovePicker>>>();
3030

3131
ParallelOptions parallelOptions = new ParallelOptions();
3232
parallelOptions.MaxDegreeOfParallelism = 5;
@@ -37,13 +37,13 @@ public static double PgnListEParallel(IEnumerable<BinaryPGN> pgnList, Func<Engin
3737
Parallel.ForEach(pgnList, parallelOptions, pgn =>
3838
{
3939
Evaluator myThreadEvaluator = null;
40-
MovePicker.Stack myThreadStack = null;
40+
IList<MovePicker> myThreadStack = null;
4141
lock (_resultLock)
4242
{
4343
System.Threading.Thread currentThread = System.Threading.Thread.CurrentThread;
4444
if (!dic.ContainsKey(currentThread))
4545
{
46-
dic.Add(currentThread, new Tuple<Evaluator, MovePicker.Stack>(fnCreateEval(), new MovePicker.Stack()));
46+
dic.Add(currentThread, new Tuple<Evaluator, IList<MovePicker>>(fnCreateEval(), MovePicker.CreateStack()));
4747
}
4848
myThreadEvaluator = dic[currentThread].Item1;
4949
myThreadStack = dic[currentThread].Item2;
@@ -68,7 +68,7 @@ public static double PgnListEParallel(IEnumerable<BinaryPGN> pgnList, Func<Engin
6868

6969

7070

71-
public static double PgnE(BinaryPGN pgn, Evaluator evaluator, MovePicker.Stack moveStack)
71+
public static double PgnE(BinaryPGN pgn, Evaluator evaluator, IList<MovePicker> moveStack)
7272
{
7373
Board board = new Board(evaluator.PcSq);
7474
GameResult result = pgn.Result;
@@ -94,7 +94,7 @@ public static double PgnE(BinaryPGN pgn, Evaluator evaluator, MovePicker.Stack m
9494
return retval;
9595
}
9696

97-
public static double PosE(Board board, GameResult gameResult, Evaluator evaluator, MovePicker.Stack moveStack)
97+
public static double PosE(Board board, GameResult gameResult, Evaluator evaluator, IList<MovePicker> moveStack)
9898
{
9999
double qscore = qScore(board, evaluator, moveStack);
100100
double retval = TanDiff(qscore, gameResult);
@@ -122,14 +122,14 @@ public static double TanScore(double qscore)
122122
return tan;
123123
}
124124

125-
public static int qScore(Board board, Evaluator evaluator, MovePicker.Stack moveStack)
125+
public static int qScore(Board board, Evaluator evaluator, IList<MovePicker> moveStack)
126126
{
127127
//var playerScore = qSearch(board, evaluator, moveStack);
128128
var playerScore = evaluator.EvalFor(board, board.WhosTurn);
129129
return board.WhosTurn == Player.White ? playerScore : -playerScore;
130130
}
131131

132-
public static int qSearch(Board board, Evaluator evaluator, MovePicker.Stack moveStack, out int resultDepth, int ply = 0, int alpha = Evaluator.MinValue, int beta = Evaluator.MaxValue)
132+
public static int qSearch(Board board, Evaluator evaluator, IList<MovePicker> moveStack, out int resultDepth, int ply = 0, int alpha = Evaluator.MinValue, int beta = Evaluator.MaxValue)
133133
{
134134
resultDepth = 0;
135135
var me = board.WhosTurn;

NoraGrace/NoraGrace.EvalTune2/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NoraGrace.EvalTune2
1212
class Stuff
1313
{
1414
public NoraGrace.Engine.Evaluation.Evaluator Evaluator { get; set; }
15-
public NoraGrace.Engine.MovePicker.Stack MovePickerStack { get; set; }
15+
public IList<MovePicker> MovePickerStack { get; set; }
1616
}
1717
class Program
1818
{

NoraGrace/NoraGrace/Perft.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private static TimeSpan PerftTest(string fen, int nodeCount, bool doEval, bool d
120120
//Console.WriteLine("fen: " + fen);
121121
int depth;
122122
var sw = System.Diagnostics.Stopwatch.StartNew();
123-
MovePicker.Stack buffer = new MovePicker.Stack();
123+
var buffer = MovePicker.CreateStack();
124124
for (depth = 2; nodesDone < nodeCount; depth++)
125125
{
126126
PerftSearch(board,0,buffer, depth, nodeCount, ref nodesDone, doEval, doMoveSort);
@@ -132,7 +132,7 @@ private static TimeSpan PerftTest(string fen, int nodeCount, bool doEval, bool d
132132
return sw.Elapsed;
133133
}
134134

135-
public static void PerftSearch(Board board, int ply, MovePicker.Stack buffer, int depth_remaining, int nodeCount, ref int nodesDone, bool doEval, bool doMoveSort)
135+
public static void PerftSearch(Board board, int ply, IList<MovePicker> buffer, int depth_remaining, int nodeCount, ref int nodesDone, bool doEval, bool doMoveSort)
136136
{
137137
nodesDone++;
138138
if (doEval)

0 commit comments

Comments
 (0)