def test_no_new_move_on_wrong_column(self): """No new move should be detected when beans falling in the wrong column.""" vision = puyo.Vision(bean_finder=MockBeanFinder(), timing_scheme="relative") board1 = puyo.Board(next_beans=(b'g', b'g')) state = vision.get_state(board1, 5) self.assertFalse(state.new_move) board2 = board1.copy() board2[3][11] = b'g' state = vision.get_state(board2, 5) self.assertFalse(state.new_move)
def test_no_new_move_on_wrong_colors1(self): """No new move should be detected when colors don't match the next bean.""" vision = puyo.Vision(bean_finder=MockBeanFinder(), timing_scheme="relative") board = puyo.Board(next_beans=(b'r', b'g')) state = vision.get_state(board, 5) self.assertFalse(state.new_move) # Yellow bean should not trigger new move tmp_board = board.copy() tmp_board[2][11] = b'y' state = vision.get_state(tmp_board, 5) self.assertFalse(state.new_move)
def test_new_move_on_seen_falling1(self): """New move should be detected when new beans are seen falling.""" vision = puyo.Vision(bean_finder=MockBeanFinder(), timing_scheme="relative") board1 = puyo.Board(next_beans=(b'r', b'g')) state = vision.get_state(board1, 5) self.assertFalse(state.new_move) # Seeing green should trigger a new move board2 = board1.copy() board2[2][11] = b'g' state = vision.get_state(board2, 5) self.assertTrue(state.new_move) # Seeing another should not trigger a new move state = vision.get_state(board2, 5) self.assertFalse(state.new_move)
def assertNewMovesMatchSet(self, recording_filename, new_move_frames): """ Assert that the new moves are detected in the recording only when specified in the set `new_move_frames`. """ vision = puyo.Vision(bean_finder=MockBeanFinder(), timing_scheme="relative") data = read_board_recording(recording_filename) last_time = 0 for i, (board, t) in enumerate(data): state = vision.get_state(board, t - last_time) if state.new_move: self.assertIn(i, new_move_frames, "new_move false positive: frame {}".format(i)) else: self.assertNotIn(i, new_move_frames, "new_move false negative: frame {}".format(i)) last_time = t
def test_new_move_on_next_bean_change(self): """New move should be detected when the next bean changes.""" vision = puyo.Vision(bean_finder=MockBeanFinder(), timing_scheme="relative") board1 = puyo.Board(next_beans=(b'r', b'g')) board2 = puyo.Board(next_beans=(b'b', b'g')) state = vision.get_state(board1, 5) self.assertFalse(state.new_move) # Change in next bean state = vision.get_state(board2, 5) self.assertTrue(state.new_move) # No change state = vision.get_state(board2, 5) self.assertFalse(state.new_move) # Change state = vision.get_state(board1, 5) self.assertTrue(state.new_move)