Esempio n. 1
0
class Table:

    def __init__(self, range_cols=20, range_rows=20):
        self._range_cols = range_cols
        self._range_rows = range_rows
        self.grid = [Row(range_cols) for _ in range(range_rows)]

        self.points = set()
        self.figure = None
        self.score = 0

    @RetryOnException(IndexError, BoundCollisionError)
    def spawn_figure(self, shape=None):
        self.figure = Figure(self._range_rows, self._range_cols, shape)
        self.check_block_colision(self.figure.points)
        self.points.update(self.figure.points)
        self.update_frame(self.points, '*')

    def display_frame(self):
        print(f'  {list(range(10))}')
        for index, row in enumerate(self.grid):
            print(f'{index:2d}{row.fields}')

    def update_frame(self, points, value):
        for x, y in points:
            self.grid[y].fields[x].value = value

    def check_block_colision(self, points):
        for point in points:
            if point in self.points:
                print(f'Collision point: {point}')
                raise CollisionError

    def move_or_rotate_figure(self, direction_key):
        try:
            old_points = deepcopy(self.figure.points)
            if direction_key in {'w', 's'}:
                points = self.figure.rotate(direction_key)
            elif direction_key in {'a', 'd'}:
                points = self.figure.move(direction_key)
            else:
                points = self.figure.move_down()

            self.points = self.points.difference(old_points)
            self.check_block_colision(points)
            self.points.update(points)
            self.update_frame(old_points, ' ')
            self.update_frame(self.points, '*')
        except BoundCollisionError:
            raise InvalidInputError

    def check_rows(self):
        for row in self.grid:
            values = [field.value for field in row.fields]
            if ' ' not in values:
                self.grid.remove(row)
                self.grid = [Row(self._range_cols)] + self.grid
                self.score += 1
                print(f'Row Completed! Your Score: {self.score}')
Esempio n. 2
0
 def explain(self):
     
     if self.PERFECTION > 0:
         print(fg_16b('\nThe answer to your question is "yes".\n', 10))
     
     else:
         print(fg_16b('\nThe answer to your question is "no".\n', 9))
     
     print('The querent is described by:')
     figure_info(Figure(self.Querent))
     
     print('The quesited is described by:')
     figure_info(Figure(self.Quesited))
Esempio n. 3
0
    def __init__(self, target_image: Image, figures=None, score=None):
        self.relevant_image = False
        self.__img = None
        self.target_image = target_image

        with MeasureTime('creating one gen', level='debug'):
            if figures:
                self.figures = figures
            else:
                self.figures = []
                for i in range(INDIVIDUAL_SIZE):
                    x1 = (i %
                          (SIZE[0] // DNA_IMAGE_SIZE[0])) * DNA_IMAGE_SIZE[0]
                    y1 = (i //
                          (SIZE[1] // DNA_IMAGE_SIZE[1])) * DNA_IMAGE_SIZE[1]
                    x2 = x1 + DNA_IMAGE_SIZE[0]
                    y2 = y1 + DNA_IMAGE_SIZE[1]

                    fragmet_to_cmp = np.array(
                        self.target_image.crop((x1, y1, x2, y2)))
                    fig = Figure((x1, y1),
                                 img=None,
                                 fragmet_to_cmp=fragmet_to_cmp)

                    self.figures.append(fig)

        self.score = score or sum(map(lambda f: f.score, self.figures))
Esempio n. 4
0
    def __init__(self):
        self.pos = np.array([5.0, 4.9])

        self.target = np.array([0.0, 0.0])
        self.targetTrackCenter = np.array([5.0, 5.0])
        self.targetTrackRadius = 3.0
        self.targetAngle = 1.5 * math.pi
        self.targetAngleDelta = -math.pi / 20.0
        self.moveTarget()

        border = Figure([(0.0, 0.0), (0.0, 10.0), (10.0, 10.0), (10.0, 0.0)],
                        close=True)
        obstacle = Figure([(4.0, 5.0), (4.0, 6.0), (9.0, 6.0), (9.0, 5.0)],
                          close=True)

        self.constraints = CompoundFigure([border, obstacle])
Esempio n. 5
0
    def defining_figures(self):
        settings.translating_colors()

        figures = [[] for x in range(0, len(settings.color_names))]

        for i in range(0, len(settings.color_names)):
            for j in range(1, self.number_of_figures + 1):
                figures[i].append(
                    Figure(
                        j,
                        Tile(0,
                             color=settings.color_names[i],
                             home=True,
                             finishing=False), Tile(i, finishing=False),
                        settings.color_names[i]))

        self.figures = figures
Esempio n. 6
0
def paint_figure(painter: QPainter, figure: Figure, style: str):
    """Paint points and segments.
    Style may be 'basic', 'selected' or 'created'.
    """

    coo = figure.get_base_representation()
    if isinstance(figure, Point):
        if style == 'basic':
            paint_point(painter, coo, 5, Qt.darkCyan)
        elif style == 'selected':
            paint_point(painter, coo, 6, Qt.cyan)
        elif style == 'created':
            paint_point(painter, coo, 6, Qt.green)
    elif isinstance(figure, Segment):
        if style == 'basic':
            paint_segment(painter, coo, 2, Qt.darkBlue)
        elif style == 'selected':
            paint_segment(painter, coo, 3, Qt.blue)
        elif style == 'created':
            paint_segment(painter, coo, 3, Qt.green)
    else:
        raise RuntimeError(f'Unexpected figure type {type(figure)}')
Esempio n. 7
0
fixed_line = Line(label="fixed", data=fixed_lr, color="blue")
lines.append(fixed_line)

base_lr = 0.5
step_lr = base_lr * (0.969**np.floor(iters / 2.))
step_line = Line(label="step", data=step_lr, color="red")
lines.append(step_line)

exp_lr = base_lr * (0.98**(iters - 1))
exp_line = Line(label="exp", data=exp_lr, color="green")
lines.append(exp_line)

inv_lr = 2.0 * ((1 + 1.009**(iters - 1))**(-2))
inv_line = Line(label="inv", data=inv_lr, color="magenta")
lines.append(inv_line)

multi_step_lr = base_lr * (0.126**np.floor(iters / 100.))
multi_step_line = Line(label="multi-step", data=multi_step_lr, color="cyan")
lines.append(multi_step_line)

poly_lr = base_lr * ((1 - iters / np.max(iters))**0.75)
poly_line = Line(label="poly", data=poly_lr, color="orange")
lines.append(poly_line)

sigmoid_lr = base_lr / (1 + np.exp(-0.02 * (iters - 200)))
sigmoid_line = Line(label="sigmoid", data=sigmoid_lr, color="purple")
lines.append(sigmoid_line)

fig = Figure(figure_name="lr_policy", xlabel="Epoch", ylabel="Learning rate")
fig.draw(lines)
Esempio n. 8
0
 def spawn_figure(self, shape=None):
     self.figure = Figure(self._range_rows, self._range_cols, shape)
     self.check_block_colision(self.figure.points)
     self.points.update(self.figure.points)
     self.update_frame(self.points, '*')
Esempio n. 9
0
 def __init__(self, numbers):
     'Make Figure object from a list of numbers and assign them position names in the chart.'
     
     self.CompleteFigures = list()
     for item in numbers:
         self.CompleteFigures.append(Figure(item))
     
     self.M1, self.M2, self.M3, self.M4 = self.CompleteFigures[0:4]
     self.D1, self.D2, self.D3, self.D4 = self.CompleteFigures[4:8]
     self.N1, self.N2, self.N3, self.N4 = self.CompleteFigures[8:12]
     self.WR = self.CompleteFigures[12]
     self.WL = self.CompleteFigures[13]
     self.JU = self.CompleteFigures[14]
     self.RC = self.CompleteFigures[15]
     
     # Via Puncti
     self.VP_SCORE = 0
     self.VP_TABLE = list()
     for i in range(15): self.VP_TABLE.append(False)
     
     # Right witness score +1
     if self.JU.number[0] == self.WR.number[0]:
         self.VP_SCORE += 1
         self.VP_TABLE[0] = True
         
         # Niece 1 score +3
         if self.JU.number[0] == self.N1.number[0]:
             self.VP_SCORE += 3
             self.VP_TABLE[2] = True
             
             # Mother 1
             if self.JU.number[0] == self.M1.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[6] = True
             
             # Mother 2
             if self.JU.number[0] == self.M2.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[7] = True
         
         # Niece 2 score +3
         if self.JU.number[0] == self.N2.number[0]:
             self.VP_SCORE += 3
             self.VP_TABLE[3] = True
             
             # Mother 3
             if self.JU.number[0] == self.M3.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[8] = True
             
             # Mother 4
             if self.JU.number[0] == self.M4.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[9] = True
     
     # Left witness
     if self.JU.number[0] == self.WL.number[0]:
         self.VP_SCORE += 1
         self.VP_TABLE[1] = True
         
         # Niece 3
         if self.JU.number[0] == self.N3.number[0]:
             self.VP_SCORE += 3
             self.VP_TABLE[4] = True
             
             # Daughter 1
             if self.JU.number[0] == self.D1.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[10] = True
             
             # Daughter 2
             if self.JU.number[0] == self.D2.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[11] = True
         
         # Niece 4
         if self.JU.number[0] == self.N4.number[0]:
             self.VP_SCORE += 3
             self.VP_TABLE[5] = True
             
             # Daughter 3
             if self.JU.number[0] == self.D3.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[12] = True
             
             # Daughter 4
             if self.JU.number[0] == self.D4.number[0]:
                 self.VP_SCORE += 15
                 self.VP_TABLE[13] = True