forked from bluemonkmn/Chess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComputer Player
57 lines (49 loc) · 2.03 KB
/
Computer Player
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
/// This class represents a "comuter" player.
/// It determines moves using minmax decision rules
/// </summary>
public class ComputerPlayer : Player
{
public const int DEFAULT_SEARCH_DEPTH = 3;
/// <summary>
/// Constructs a new computer player. The DEFAULT_SEARCH_DEPTH is used
/// </summary>
/// <param name="name">The name of the player</param>
/// <param name="p">The piece this player is using in the came</param>
public ComputerPlayer(string name, Board.Pieces p) : this(name,
p, DEFAULT_SEARCH_DEPTH)
{
}
/// <summary>
/// Constructs a new computer player
/// </summary>
/// <param name="name">The name of the player</param>
/// <param name="p">The piece the player is using</param>
/// <param name="searchDepth">The depth to search for moves in the game tree.</param>
public ComputerPlayer(string name, Board.Pieces p, int searchDepth) :base(name, p)
{
this.SearchDepth = searchDepth;
}
/// <summary>
/// gets or sets the search depth which is the number of moves
/// the computer player will look ahead to determine it's move
/// Greater values yield better computer play
/// </summary>
public int SearchDepth { get; set; }
/// <summary>
/// Start the computer searching for a move
/// Clients should listen to the OnPlayerMoved event to be notified
/// when the computer has found a move
/// </summary>
/// <param name="gameBoard">The current game board</param>
public override void Move(object gameBoard)
{
Board b = (Board)gameBoard;
Node root = new MaxNode(b, null, null);
root.MyPiece = this.PlayerPiece;
root.Evaluator = new EvaluationFunction();
root.FindBestMove(DEFAULT_SEARCH_DEPTH);
currentMove = root.BestMove;
OnPlayerMoved();
}
...
}