Esempio n. 1
0
def select_move_prioritizing_capture(player_stone_color, boards, depth):
    '''
    moves =
    [
        [point1, point2, ...] (from oldest to newest)
        ...
    ]
    [[(1,1)], []]
    '''
    rc = RuleChecker()
    most_recent_board = boards[0]
    opponent_stone_color = utils.get_opponent_stone_color(player_stone_color)
    moves = []
    if depth == 1:
        chains = most_recent_board.get_all_chains()
        opponent_chains = [
            chain for chain in chains
            if chain.stone_color == opponent_stone_color
        ]
        for chain in opponent_chains:
            if len(chain.liberties) == 1:
                liberties = list(chain.liberties)
                if rc.check_legality(player_stone_color, liberties[0], boards):
                    moves.append(liberties[0])
    if depth > 1:
        # Idea: define new_move as [point()]
        # all_moves = generate_all_moves_that_d
        # return select_simple_move(boards)
        raise NotImplementedError()
    if moves:
        return sorted(moves)
    else:
        return select_simple_move(player_stone_color, boards)
	def test_straight(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(6, spades)]
		hand_two = [Card(7, clubs), Card(8, diamonds)]
		hand_three = [Card(2, spades), Card(13, hearts)]
		board = [Card(4, hearts), Card(3, diamonds), Card(5, spades)] 
		board_two = [Card(4, hearts), Card(3, diamonds), Card(5, spades), Card(6, hearts)]
		self.assertTrue(rc.is_straight(hand_one, board)[0])
		self.assertEqual(rc.is_straight(hand_one, board)[1], 6)
		self.assertFalse(rc.is_straight(hand_two, board)[0])
		self.assertTrue(rc.is_straight(hand_one, board_two)[0])
		self.assertTrue(rc.is_straight(hand_two, board_two)[0])
		self.assertTrue(rc.is_straight(hand_three, board_two)[0])

		# Ace straight edge cases
		hand_one = [Card(14, spades), Card(2, hearts)]
		board = [Card(4, hearts), Card(3, diamonds), Card(5, spades)] 
		board_two = [Card(13, hearts), Card(12, diamonds), Card(11, spades), Card(10, spades)] 
		self.assertTrue(rc.is_straight(hand_one, board)[0])
		self.assertEqual(rc.is_straight(hand_one, board)[1], 5)
		self.assertTrue(rc.is_straight(hand_one, board_two)[0])
		self.assertEqual(rc.is_straight(hand_one, board_two)[1], 14)

		# Straight on board 
		hand_one = [Card(14, spades), Card(14, hearts)]
		hand_two = [Card(14, diamonds), Card(8, diamonds)]
		board_with_straight = [Card(4, hearts), Card(3, diamonds), Card(5, spades), Card(6, hearts), Card(7, clubs)]
		self.assertTrue(rc.is_straight(hand_one, board_with_straight)[0])
		self.assertEqual(rc.is_straight(hand_one, board_with_straight)[1], 7)
		self.assertEqual(rc.is_straight(hand_two, board_with_straight)[1], 8)
	def test_straight_flush(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(5, spades)]
		hand_two = [Card(2, spades), Card(14, spades)]
		board = [Card(4, spades), Card(3, spades), Card(6, spades), Card(10, spades)]
		self.assertTrue(rc.is_straight_flush(hand_one, board)[0])
		self.assertFalse(rc.is_straight_flush(hand_two, board)[0])
	def test_full_house(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(6, spades)]
		hand_two = [Card(2, spades), Card(7, diamonds)]
		board = [Card(2, diamonds), Card(2, hearts), Card(6, clubs), Card(5, diamonds)]
		self.assertEqual(rc.is_full_house(hand_one, board)[1], 2)
		self.assertEqual(rc.is_full_house(hand_one, board)[2], 6)
		self.assertFalse(rc.is_full_house(hand_two, board)[0])
	def test_pair(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(10, spades)]
		hand_two = [Card(6, spades), Card(11, clubs)]
		board = [Card(2, diamonds), Card(5, diamonds), Card(11, hearts)]
		self.assertEqual(rc.is_pair(hand_one, board)[1], 2)
		self.assertEqual(rc.is_pair(hand_one, board)[2][0], 11)
		self.assertEqual(rc.is_pair(hand_two, board)[1], 11)
	def test_quads(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(6, spades)]
		hand_two = [Card(2, spades), Card(3, spades)]
		board = [Card(2, diamonds), Card(2, hearts), Card(2, clubs), Card(5, diamonds)]
		self.assertTrue(rc.is_quads(hand_one, board)[0])
		self.assertEqual(rc.is_quads(hand_one, board)[1], 2)
		self.assertEqual(rc.is_quads(hand_one, board)[2], 6)
		self.assertEqual(rc.is_quads(hand_two, board)[2], 5)
	def test_flush(self):
		rc = RuleChecker()
		hand_one = [Card(2, clubs), Card(5, clubs)]
		hand_two = [Card(3, spades), Card(4, diamonds)]
		hand_three = [Card(8, diamonds), Card(10, clubs)]
		board = [Card(4, clubs), Card(6, clubs), Card(10, clubs), Card(5, spades)]
		board_with_flush = [Card(4, spades), Card(3, spades), Card(6, spades), Card(10, spades), Card(13, spades)]
		self.assertTrue(rc.is_flush(hand_one, board)[0])
		self.assertFalse(rc.is_flush(hand_two, board)[0])
		self.assertTrue(rc.is_flush(hand_three, board_with_flush)[0])
Esempio n. 8
0
    def __init__(self):
        self.rules = RuleChecker()
        self.rules.add_rule('EMPID', "^[A-Z][0-9]{3}$")
        self.rules.add_rule('GENDER', "^(M|F)$")
        self.rules.add_rule('AGE', "^[0-9]{2}$")
        self.rules.add_rule('SALES', "^[0-9]{3}$")
        self.rules.add_rule('BMI', "^(Normal|Overweight|Obesity|Underweight)$")
        self.rules.add_rule('SALARY', "^[0-9]{2,3}$")
        self.rules.add_rule('BIRTHDAY', "^[1-31]-[1-12]-[0-9]{4}$")

        self.attributes = self.rules.get_fields()
        self.number_of_attributes = len(self.attributes)
	def test_trips(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(10, spades)]
		hand_two = [Card(2, spades), Card(6, spades)]
		hand_three = [Card(2, spades), Card(3, spades)]
		board = [Card(2, diamonds), Card(2, hearts), Card(5, diamonds), Card(4, hearts)]
		self.assertTrue(rc.is_trips(hand_one, board)[0])
		self.assertEqual(rc.is_trips(hand_one, board)[1], 2)
		self.assertEqual(rc.is_trips(hand_one, board)[2][0], 10)
		self.assertEqual(rc.is_trips(hand_one, board)[2][1], 5)
		self.assertEqual(rc.is_trips(hand_two, board)[2][0], 6)
		self.assertEqual(rc.is_trips(hand_two, board)[2][1], 5)
		self.assertEqual(rc.is_trips(hand_three, board)[2][0], 5)
		self.assertEqual(rc.is_trips(hand_three, board)[2][1], 4)
Esempio n. 10
0
def select_simple_move(player_stone_color, boards):
    '''
    input: boards
    output:
        if there is a move that self can make,
            returns a point with the lowest column index,
            and then with the lowest row index
        if there isn't,
            returns a string "pass"
    '''
    rc = RuleChecker()
    for point, maybe_stone in iter(boards[0]):
        if maybe_stone == EMPTY:
            if rc.check_legality(player_stone_color, point, boards):
                return str(point)
    return "pass"
	def test_two_pair(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(10, spades)]
		hand_two = [Card(6, spades), Card(6, clubs)]
		board = [Card(2, diamonds), Card(10, hearts), Card(5, diamonds), Card(5, hearts)]
		self.assertTrue(rc.is_two_pair(hand_one, board)[0])
		self.assertEqual(rc.is_two_pair(hand_one, board)[1], 10)
		self.assertEqual(rc.is_two_pair(hand_one, board)[3], 5)
		self.assertTrue(rc.is_two_pair(hand_two, board)[0])
		self.assertEqual(rc.is_two_pair(hand_two, board)[1], 6)
		self.assertEqual(rc.is_two_pair(hand_two, board)[3], 10)

		# same top pair but different bottom pair
		hand_one = [Card(14, spades), Card(14, hearts)]
		hand_two = [Card(13, spades), Card(12, clubs)]
		board = [Card(13, diamonds), Card(12, hearts), Card(2, diamonds), Card(3, hearts), Card(2, hearts)]
		self.assertEqual(rc.is_two_pair(hand_one, board)[1], 14)
		self.assertEqual(rc.is_two_pair(hand_one, board)[3], 13)
		self.assertEqual(rc.is_two_pair(hand_two, board)[1], 13)
		self.assertEqual(rc.is_two_pair(hand_two, board)[3], 3)
Esempio n. 12
0
 def __init__(self, name, stone):
     self.name = name
     self.stone = stone
     self.rule_checker = RuleChecker()
Esempio n. 13
0
 def __init__(self, input_):
     self._verify_input_(input_)
     self.ret_value = RuleChecker(input_).ret()
Esempio n. 14
0
 def __init__(self, name, stone):
     self.name = name
     self.stone = stone
     self.n = 1
     self.opp_stone = self._get_opponent_stone(stone)
     self.rule_checker = RuleChecker()
	def test_analyze_hand(self):
		rc = RuleChecker()
		hand_one = [Card(2, spades), Card(7, spades)]
		board = [Card(4, spades), Card(3, spades), Card(6, spades), Card(10, spades)]
		# TODO write more tests
		hand_two = [Card(2, diamonds), Card(13, hearts)]