aboutsummaryrefslogtreecommitdiff
path: root/tests/test_monteCarlo.py
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2022-12-14 15:41:49 +0100
committerInigoGutierrez <inigogf.95@gmail.com>2022-12-14 15:41:49 +0100
commit824d5e3b6954407a694f5739cbeb40f66324c8d7 (patch)
tree2edd317df4a83afbb305e017f3d5afd92b6b5422 /tests/test_monteCarlo.py
parente8b9bf589e698b51e55ae59693b5bb0293f86a26 (diff)
downloadimago-824d5e3b6954407a694f5739cbeb40f66324c8d7.tar.gz
imago-824d5e3b6954407a694f5739cbeb40f66324c8d7.zip
Developing Unit Testing.
Diffstat (limited to 'tests/test_monteCarlo.py')
-rw-r--r--tests/test_monteCarlo.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_monteCarlo.py b/tests/test_monteCarlo.py
index b217cf9..496c073 100644
--- a/tests/test_monteCarlo.py
+++ b/tests/test_monteCarlo.py
@@ -2,6 +2,7 @@
import unittest
+from imago.engine.decisionAlgorithm import DecisionAlgorithm
from imago.gameLogic.gameState import GameState
from imago.engine.monteCarlo import MCTS
from imago.engine.monteCarlo import MCTSNode
@@ -17,6 +18,53 @@ class TestMonteCarlo(unittest.TestCase):
tree = MCTS(state.lastMove)
#print(tree.pickMove().toString())
+ def testForceNextMove(self):
+ """Test forcing next move."""
+
+ # Next move before expansion (no children nodes)
+ state = GameState(TEST_BOARD_SIZE)
+ tree = MCTS(state.lastMove)
+ self.assertEqual(set(), tree.root.children)
+ tree.forceNextMove((0, 1))
+ self.assertEqual(set(), tree.root.children)
+
+ # Next move after expansion (with children nodes)
+ tree.expansions = 2
+ tree.simulationsPerExpansion = 2
+ tree.pickMove()
+ self.assertEqual(tree.expansions, len(tree.root.children))
+ nextMoveCoords = list(tree.root.children)[0].move.coords
+ tree.forceNextMove(nextMoveCoords)
+
+ def testPass(self):
+ """Test passing as next move."""
+ state = GameState(TEST_BOARD_SIZE)
+ tree = MCTS(state.lastMove)
+ self.assertFalse(tree.root.move.isPass)
+ tree.forceNextMove("pass")
+ self.assertTrue(tree.root.move.isPass)
+
+ def testClearBoard(self):
+ """Test clearing board returns root to original and retains information."""
+ state = GameState(TEST_BOARD_SIZE)
+ tree = MCTS(state.lastMove)
+
+ firstMoveCoords = (0,0)
+ secondMoveCoords = (1,0)
+ thirdMoveCoords = (0,1)
+
+ tree.forceNextMove(firstMoveCoords)
+ tree.forceNextMove(secondMoveCoords)
+ tree.forceNextMove(thirdMoveCoords)
+ tree.clearBoard()
+
+ nextNode = list(tree.root.children)[0]
+ self.assertEqual(firstMoveCoords, nextNode.move.coords)
+ nextNode = list(nextNode.children)[0]
+ self.assertEqual(secondMoveCoords, nextNode.move.coords)
+ nextNode = list(nextNode.children)[0]
+ self.assertEqual(thirdMoveCoords, nextNode.move.coords)
+
#def testSimulation(self):
# """Test calculation of group liberties."""
# board = GameBoard(TEST_BOARD_SIZE, TEST_BOARD_SIZE)