コード例 #1
0
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