Exemplo n.º 1
0
            def task_division(block_index, block_pos):
                def bum(cond):
                    return MIN_BLOCK_SPACE if cond else 0

                block = task[block_index]
                block_end = block_pos + block
                left_bum = bum(block_index > 0)
                right_bum = bum(block_index < (len(task) - 1))

                left_edge = block_pos - left_bum
                right_edge = block_end + right_bum

                if (left_edge < 0 or right_edge > len(field_line) or
                    (field_line[left_edge:block_pos] == Cell.FILLED).any() or
                    (field_line[block_end:right_edge] == Cell.FILLED).any()):
                    return None

                left_result, right_result, total_count = self.run_sides(
                    left=CollapseRun(task[:block_index],
                                     field_line[:left_edge]),
                    right=CollapseRun(task[block_index + 1:],
                                      field_line[right_edge:]))

                if total_count == 0:
                    return None

                return CollapseResult.join(*left_result.line,
                                           *Cells.x(left_bum),
                                           *Cells.f(block),
                                           *Cells.x(right_bum),
                                           *right_result.line,
                                           count=total_count)
Exemplo n.º 2
0
            def task_division(i):
                left_result, right_result, total_count = self.run_sides(
                    left=CollapseRun(task[:i], field_line[:x_start]),
                    right=CollapseRun(task[i:], field_line[x_end:]))

                if total_count == 0:
                    return None

                return CollapseResult.join(*left_result.line,
                                           *Cells.x(x_end - x_start),
                                           *right_result.line,
                                           count=total_count)