Example #1
0
    def test_bear_off_and_hit(self):
        board = Board(
            repeat_point(22) + [Point(1, Color.White)] +
            [Point(1, Color.Black)])
        board.apply_move(Move(Color.White, 23, 1))
        self.assertEqual(board.bar[Color.Black.value], 1)
        board.apply_move(Move(Color.White, 24, 1))

        self.assertEqual(board.off[Color.White.value], 1)
Example #2
0
 def test_single_valid_move(self):
     board = Board(
         repeat_point(10) + [Point(1, Color.White)] +
         [Point(2, Color.White)] + repeat_point(12, 2, Color.Black))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(1, 3)))),
         set([
             (Move(Color.White, 11, 1), ),
         ]))
Example #3
0
 def test_one_blocked_pip_bear_off(self):
     """Sames as test_one_pip_bear_off but 1 is blocked"""
     board = Board(
         repeat_point(4) + [Point(2, Color.White)] +
         [Point(1, Color.Black)] + repeat_point(18))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.Black,
                                            Dice(roll=(1, 6)))),
         set([
             (Move(Color.Black, 6, 6), ),
         ]))
Example #4
0
 def test_hit_opportunity(self):
     board = Board(
         repeat_point(10) + [Point(1, Color.White)] +
         [Point(1, Color.Black)] + repeat_point(12))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(1, 2)))),
         set([
             (Move(Color.White, 11, 1), Move(Color.White, 12, 2)),
             (Move(Color.White, 11, 2), Move(Color.White, 13, 1)),
         ]))
Example #5
0
 def test_doubles(self):
     board = Board(
         repeat_point(10) + [Point(1, Color.White)] + repeat_point(13))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(2, 2)))),
         set([
             (Move(Color.White, 11, 2), Move(Color.White, 13, 2),
              Move(Color.White, 15, 2), Move(Color.White, 17, 2)),
         ]))
Example #6
0
 def test_single_pip_anywhere(self):
     board = Board(
         repeat_point(10) + [Point(1, Color.White)] + repeat_point(13))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(1, 2)))),
         set([
             (Move(Color.White, 11, 1), Move(Color.White, 12, 2)),
             (Move(Color.White, 11, 2), Move(Color.White, 13, 1)),
         ]))
Example #7
0
 def test_one_pip_bear_off(self):
     board = Board(
         repeat_point(5) + [Point(1, Color.Black)] + repeat_point(18))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.Black,
                                            Dice(roll=(1, 6)))),
         set([
             (
                 Move(Color.Black, 6, 1),
                 Move(Color.Black, 5, 6),
             ),
             # Practically, this move is idenical since the above two
             # moves result in bearing off. However the above move uses
             # both dice, and so is considered correct
             # (Move(Color.Black, 6, 6),),
         ]))
Example #8
0
 def test_two_pip_bear_off(self):
     board = Board(
         repeat_point(19) + [Point(2, Color.White)] + repeat_point(4))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(5, 6)))),
         set([
             # These  movesets are identical to each other because they both bear
             # off and could be deduped, but don't seem harmful, so leaving for now
             (
                 Move(Color.White, 20, 6),
                 Move(Color.White, 20, 5),
             ),
             (
                 Move(Color.White, 20, 5),
                 Move(Color.White, 20, 6),
             ),
         ]))
Example #9
0
 def test_simple_hit(self):
     board = Board([Point(2, Color.White)] + [Point(1, Color.Black)] +
                   repeat_point(22))
     board.apply_move(Move(Color.White, 1, 1))
     self.assertEqual(board.bar[Color.Black.value], 1)
Example #10
0
 def test_simple_move(self):
     board = Board([Point(2, Color.White)] + repeat_point(23))
     board.apply_move(Move(Color.White, 1, 6))
     self.assertEqual(board.point_at_number(1), Point(1, Color.White))
     self.assertEqual(board.point_at_number(7), Point(1, Color.White))
Example #11
0
 def test_cant_bear_off_with_bar(self):
     board = Board(repeat_point(23) + [Point(2, Color.White)], )
     board.add_bar(Color.White)
     self.assertFalse(board.can_bear_off(Color.White))
Example #12
0
 def test_perfect_prime_no_moves(self):
     board = Board([Point(2, Color.White)] +
                   repeat_point(6, 2, Color.Black) + repeat_point(17))
     self.assertEqual(
         extract_moves(board.possible_moves(Color.White,
                                            Dice(roll=(6, 6)))), set())
Example #13
0
    def test_constructor_invalid_inputs(self):
        with self.assertRaises(Exception, msg="Raises for empty board"):
            Board([])

        with self.assertRaises(Exception, msg="Raises for too-large board"):
            Board(default_starting_points + [Point(2, Color.Black)])
Example #14
0
def repeat_point(repeat_count, pips=0, color=None):
    if type(pips) is not int or (color is not None
                                 and type(color) is not Color):
        raise Exception("Invalid args into repeat_point")
    return [Point(pips, color) for i in range(repeat_count)]
Example #15
0
from autogamen.game.board import Board, FrozenBoard
from autogamen.game.types import Color, Dice, Move, Point
from autogamen.ui.match_view import display_board

from .performance import assertRuntime


def repeat_point(repeat_count, pips=0, color=None):
    if type(pips) is not int or (color is not None
                                 and type(color) is not Color):
        raise Exception("Invalid args into repeat_point")
    return [Point(pips, color) for i in range(repeat_count)]


default_starting_points = [
    Point(2, Color.White),
    Point(),
    Point(),
    Point(),
    Point(),
    Point(5, Color.Black),
    Point(0),
    Point(3, Color.Black),
    Point(),
    Point(),
    Point(),
    Point(5, Color.White),
    Point(5, Color.Black),
    Point(),
    Point(),
    Point(),