-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardEvaluationUtil.cs
85 lines (77 loc) · 2.95 KB
/
BoardEvaluationUtil.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
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace SrcChess {
/// <summary>Utility class creating and holding all board evaluator functions</summary>
public class BoardEvaluationUtil {
/// <summary>List of all board evaluator object</summary>
private List<IBoardEvaluation> m_listBoardEvaluator;
//*********************************************************
//
/// <summary>
/// Class constructor
/// </summary>
//
//*********************************************************
public BoardEvaluationUtil() {
BuildBoardEvaluationList();
}
//*********************************************************
//
/// <summary>
/// Creates all build evaluator objects using reflection to find them
/// </summary>
//
//*********************************************************
protected virtual void BuildBoardEvaluationList() {
Assembly assem;
Type[] arrType;
IBoardEvaluation boardEval;
m_listBoardEvaluator = new List<IBoardEvaluation>(32);
assem = GetType().Assembly;
arrType = assem.GetTypes();
foreach (Type type in arrType) {
if (!type.IsInterface && type.GetInterface("IBoardEvaluation") != null) {
boardEval = (IBoardEvaluation)Activator.CreateInstance(type);
m_listBoardEvaluator.Add(boardEval);
}
}
}
//*********************************************************
//
/// <summary>
/// Returns the list of board evaluators
/// </summary>
//
//*********************************************************
public List<IBoardEvaluation> BoardEvaluators {
get {
return(m_listBoardEvaluator);
}
}
//*********************************************************
//
/// <summary>
/// Find a board evaluator using its name
/// </summary>
/// <param name="strName"> Evaluation method name</param>
/// <returns>
/// Object
/// </returns>
//
//*********************************************************
public IBoardEvaluation FindBoardEvaluator(string strName) {
IBoardEvaluation boardEval = null;
if (strName != null) {
foreach (IBoardEvaluation boardEvalTmp in m_listBoardEvaluator) {
if (String.Compare(boardEvalTmp.Name, strName, true) == 0) {
boardEval = boardEvalTmp;
break;
}
}
}
return(boardEval);
}
}
}