def _find_moves(state, location, team, type, temp_deleted = []): direction = Teams.direction(team) if type == CheckerType.king(): direction = 0 empty_moves = [] take_moves = [] enemy = Teams.opposite(team) diagonals = _get_diagonals(location, direction) for square in diagonals: new_checker = state.get_checker_from_location(tuple(square)) if new_checker == None or new_checker.location in temp_deleted: empty_moves.append(square) continue elif new_checker.team == enemy: dx = square[0] - location[0] dy = square[1] - location[1] new_square = (square[0] + dx, square[1] + dy) if not _valid_square(new_square): continue if state.get_checker_from_location(new_square) == None: take_moves.append(new_square) if not len(take_moves) == 0: return take_moves, True return empty_moves, False
def _find_moves(state, location, team, type, temp_deleted=[]): direction = Teams.direction(team) if type == CheckerType.king(): direction = 0 empty_moves = [] take_moves = [] enemy = Teams.opposite(team) diagonals = _get_diagonals(location, direction) for square in diagonals: new_checker = state.get_checker_from_location(tuple(square)) if new_checker == None or new_checker.location in temp_deleted: empty_moves.append(square) continue elif new_checker.team == enemy: dx = square[0] - location[0] dy = square[1] - location[1] new_square = (square[0] + dx, square[1] + dy) if not _valid_square(new_square): continue if state.get_checker_from_location(new_square) == None: take_moves.append(new_square) if not len(take_moves) == 0: return take_moves, True return empty_moves, False
def king_checker(self, location): index = self._get_checker_index_from_location(location) checker = self.get_checker_from_location(location) if not checker: raise ValueError('No checker exists at given location') if checker.type == CheckerType.king(): return if checker.team == Teams.red(): self.red_kings += 1 else: self.black_kings += 1 checker.type = CheckerType.king() current_res = checker.res.res new_res = Resource.Resource(current_res.replace(".png", "_king.png")) checker.res = new_res checker._load_resource() self.checkers[index] = checker
def add_checker(team, location): if location == (4, 0) or location == (7, 0): return red_checker = Resource.Resource("res/checker_red.png") black_checker = Resource.Resource("res/checker_black.png") res = None if team == Teams.red(): res = red_checker else: res = black_checker checker = Checker.Checker(pygame.display.get_surface(), game_objects.board, res) checker.location = location checker.team = team checker.type = CheckerType.men() game_objects.state.add_checker(checker)
def type(self, type): if type != CheckerType.men() and type != CheckerType.king(): raise ValueError('Team must be provided') self.type = type