示例#1
0
 def test_cc_several_moves_ahead(self):
     print "Testing can look a few moves ahead..."
     for n in range(NUMBER_FOR_EACH):
         print "Passed " + str(n)
         inst = AbstractGame(ConnectGame())
         a = inst.move_immutable(3)
         b = a.move_immutable(3)
         c = b.move_immutable(4)
         d = c.move_immutable(4)
         distribution = MCTS(d, iteration_number=700)
         highest = max(distribution)
         highest_index = distribution.index(highest)
         self.assertTrue(highest_index == 5 or highest_index == 2)
示例#2
0
 def test_bb_wants_block_death(self):
     print "Testing can block opponent victory."
     for n in range(NUMBER_FOR_EACH):
         print "Passed " + str(n)
         inst = AbstractGame(ConnectGame())
         a = inst.move_immutable(4)
         b = a.move_immutable(1)
         c = b.move_immutable(4)
         d = c.move_immutable(1)
         e = d.move_immutable(4)
         distribution = MCTS(e, iteration_number=700)
         highest = max(distribution)
         highest_index = distribution.index(highest)
         self.assertTrue(highest_index == 4)
示例#3
0
 def test_aa_wants_wim(self):
     print "Testing can win."
     for n in range(NUMBER_FOR_EACH):
         print "Passed " + str(n)
         inst = AbstractGame(ConnectGame())
         a = inst.move_immutable(4)
         b = a.move_immutable(1)
         c = b.move_immutable(4)
         d = c.move_immutable(1)
         e = d.move_immutable(4)
         f = e.move_immutable(1)
         distribution = MCTS(f, iteration_number=170)
         highest = max(distribution)
         highest_index = distribution.index(highest)
         self.assertTrue(highest_index == 4)
示例#4
0
 def test_dd_wants_center(self):
     print "Testing wants center..."
     for n in range(NUMBER_FOR_EACH):
         print "Passed " + str(n)
         inst = AbstractGame(ConnectGame())
         distribution = MCTS(inst, iteration_number=3000)
         highest = max(distribution)
         highest_index = distribution.index(highest)
         self.assertTrue(highest_index == 3)
示例#5
0
 def test_random_simulation(self):
     total_plays = 100
     win_total = 0
     for n in range(total_plays):
         g = AbstractGame(ConnectGame())
         p = random_simulation(g)
         if p == 1:
             win_total = win_total + 1
         if p == 0:
             win_total = win_total - 1
     self.assertTrue(win_total > -5)
     self.assertTrue(win_total < 50)
 def test_can_play_till_end_mutably(self):
     for creator in game_creators:
         inst = AbstractGame(creator())
         num_moves = 0
         while (not inst.game_over()):
             moves = inst.move_list()
             num_moves = num_moves + 1
             inst.move_mutable(random.choice(moves))
         self.assertTrue(True)
         self.assertTrue(num_moves > 2)
         self.assertTrue(num_moves < 1000)
def game_creator():
    return AbstractGame(ConnectGame())
 def test_board_creation_new(self):
     for creator in game_creators:
         inst = AbstractGame(creator())
         self.assertTrue(True)
示例#9
0
import unittest

from abstractgame import AbstractGame
from connectgame import ConnectGame
from agent import Agent
from mcts import MCTS

#
# Unfortunately, I'd either need to write a gigantic
# stub for AbstractGame, or do integration tests,
# so for now I'm just doing integration test
#

agent_creators = [lambda: Agent(MCTS)]

game_creators = [lambda: AbstractGame(ConnectGame())]


class TestAbstractGame(unittest.TestCase):

    # Can make some kind of instance
    def test_agent_creation_new(self):
        for creator in agent_creators:
            inst = creator()
            self.assertTrue(True)

    def test_can_make_moves(self):
        for a_creator in agent_creators:

            for g_creator in game_creators: