Пример #1
0
 def test_init(self):
     """ test init """
     game = Pentago()
     str(game)
     for y in range(6):
         for x in range(6):
             self.assertEqual(game.getpoint(x, y), game.VOID)
Пример #2
0
 def test_play(self):
     """ test play """
     game = Pentago()
     game.play(3, 0, 0, 1)
     self.assertEqual(game.getpoint(3, 0), game.WHITE)
     game.play(4, 1, 1, 0)
     self.assertEqual(game.getpoint(3, 0), game.VOID)
     self.assertEqual(game.getpoint(5, 0), game.WHITE)
     self.assertEqual(game.getpoint(4, 1), game.BLACK)
Пример #3
0
    def test_set_get(self):
        """ test set get """
        mat = [[1, 2, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 1, 1, 0, 0, 0],
               [0, 1, 1, 0, 2, 0], [0, 1, 1, 0, 2, 0], [0, 1, 1, 0, 2, 0]]

        game = Pentago()
        # set
        for y, line in enumerate(mat):
            for x, value in enumerate(line):
                if value != game.VOID:
                    game.setpoint(x, y, value)
        # get
        for y, line in enumerate(mat):
            for x, value in enumerate(line):
                self.assertEqual(game.getpoint(x, y), value)
Пример #4
0
 def test_win_eq(self):
     """ test win eq """
     game = Pentago()
     for pos in winpos[0]:
         game.setpoint(*pos, game.BLACK)
     for pos in winpos[1]:
         game.setpoint(*pos, game.WHITE)
     game.check_win()
     self.assertEqual(game.winner, game.VOID)
Пример #5
0
 def test_win_all_combinations(self):
     """ test win """
     for color in (Pentago.BLACK, Pentago.WHITE):
         for poss in winpos:
             game = Pentago()
             for pos in poss:
                 game.setpoint(*pos, color)
             game.check_win()
             self.assertEqual(game.winner, color)
Пример #6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Entry point
"""

from pentago import Pentago


def get_play_cmd():
    """ get user cmd """
    try:
        print("x[0, 5]\ny[0, 5]\nquad[0, 3]\nsens[0, 1]")
        dat = tuple([int(input()) for _ in range(4)])
        assert 0 <= dat[0] <= 5
        assert 0 <= dat[1] <= 5
        assert 0 <= dat[2] <= 3
        assert 0 <= dat[3] <= 1
        print("x={} y={} quad={} sens={}".format(*dat))
        return dat
    except:
        print("Error entry")


if __name__ == '__main__':
    game = Pentago()
    print(game)
    while game.run:
        game.play(*get_play_cmd())
        print(game)
Пример #7
0
 def test_rotate(self):
     """ test rotate """
     game = Pentago()
     # init
     game.setpoint(0, 0, 1)
     self.assertEqual(game.getpoint(0, 0), 1)
     # rotate
     game.rotate(0, 1)  # trigo
     self.assertEqual(game.getpoint(0, 2), 1)
     self.assertEqual(game.getpoint(0, 0), game.VOID)
     # rotate
     game.rotate(0, 0)  # anti trigo
     self.assertEqual(game.getpoint(0, 0), 1)
     self.assertEqual(game.getpoint(0, 2), game.VOID)
Пример #8
0
    from connect_four import ConnectFour
    from otrio import Otrio
    from pentago import Pentago
    from players import RandomPlayer, HumanPlayer
    from advised_monte_carlo_player import AdvisedMonteCarloPlayer
    from basic_monte_carlo_player import BasicMonteCarloPlayer
    from solve_player import SolvePlayer
    from sizeable_connect_x import SizeableConnectX
    from onitama import Onitama, PawnCountingEvaluator
    from onitama import move_to_string as onitama_move_to_string

    # game
    # start_game = SizeableConnectX(4, 4, 4)
    # start_game = Otrio()
    # start_game = Onitama()
    start_game = Pentago()

    # player 1
    # p1 = HumanPlayer()
    # p1 = AdvisedMonteCarloPlayer(2, 2, 2)
    # p1 = BasicMonteCarloPlayer()
    # p1 = RandomPlayer()
    # Connect4 plays with AdvisedMonteCarloPlayer(7, 2, 4)
    # the 4 layers of lookahead is too far, and 7 is too much position evaluation
    # p1 = AdvisedMonteCarloPlayer(7, 2, 4)
    # visible progress, but monte carlo simulations are still too slow
    # p1 = AdvisedMonteCarloPlayer(4, 7, 2)
    # just barely playable
    p1 = AdvisedMonteCarloPlayer(8, 20, 1)

    # player 2