forked from bluemonkmn/Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinNode
More file actions
60 lines (49 loc) · 1.89 KB
/
Copy pathMinNode
File metadata and controls
60 lines (49 loc) · 1.89 KB
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
/// <summary>
/// This class represents a MIN node in the game tree
/// </summary>
public class MinNode : Node
{
/// <summary>
/// Constructs a MIN node
/// </summary>
/// <param name="b">The board that this node represents</param>
/// <param name="parent">This node's parent</param>
/// <param name="m">The move that was made from the parent to lead to this node's board</param>
public MinNode(Board b, Node parent, TicTacToeMove m)
:base(b, parent, m)
{
}
// Generates the node's children. MIN nodes have MAX children
protected override void GenerateChildren()
{
int[] openPositions = board.OpenPositions;
foreach (int i in openPositions)
{
Board b = (Board)board.Clone();
TicTacToeMove m = new TicTacToeMove(i, myPiece);
b.MakeMove(i, myPiece);
children.Add(new MaxNode(b, this, m));
}
}
// determines if this node is a winner
// by convention a winning node for a MIN node
// is double.MinValue
protected override bool IsWinningNode()
{
return this.value == double.MinValue;
}
// returns a list of the child nodes in ascending order
// the first node in the list will be the best node for the min node
protected override List<Node> SortChildren(List<Node> unsortedChildren)
{
List<Node> sortedChildren = unsortedChildren.OrderBy(n => n.Value).ToList();
return sortedChildren;
}
/// <summary>
/// evalutes the value of the node using the evaluation function
/// </summary>
protected override void Evaluate()
{
Value = evaluator.Evaluate(board, Board.GetOponentPiece(myPiece));
}
}