public MiniBoard Copy() { var c = new MiniBoard(); c._state = _state; c._x = _x; c._o = _o; return(c); }
public void TestMiniBoard() { var board = new MiniBoard(); Assert.AreEqual(board.Probability(Player.X), 0.5, 0.05, "a new board has even probability for X"); Assert.AreEqual(board.Probability(Player.O), 0.5, 0.05, "same for O"); var moves = board.Moves(); var expected = Enumerable.Range(0, 9).ToList(); CollectionAssert.AreEqual(expected, moves, "all nine moves are available"); var hash = board.GetHashCode(); Assert.AreEqual(0, hash, "proper hash for an empty board"); var p1 = board.Probability(Player.X); board.MakeMove(4, Player.X); var p2 = board.Probability(Player.X); board.MakeMove(3, Player.X); var p3 = board.Probability(Player.X); board.MakeMove(5, Player.X); var p4 = board.Probability(Player.X); Assert.Greater(p2, p1); Assert.Greater(p3, p2); Assert.Greater(p4, p3); Assert.AreEqual(p4, 1.0, "exact match on a win"); moves = board.Moves(); expected = new List <int> { 0, 1, 2, 6, 7, 8 }; CollectionAssert.AreEqual(expected, moves, "six moves are left"); p1 = board.Probability(Player.O); Assert.AreEqual(0.0, p1); board.MakeMove(6, Player.O); p2 = board.Probability(Player.O); Assert.AreEqual(0.0, p2); board.MakeMove(7, Player.O); p3 = board.Probability(Player.O); Assert.AreEqual(0.0, p3); board.MakeMove(8, Player.O); p4 = board.Probability(Player.O); Assert.AreEqual(0.0, p4); }