def test_add(): add_point_list = [ Point(-1, 0), Point(+1, 0), Point(0, -1), Point(0, +1), ] for i in range(10): for j in range(22): for add_point in add_point_list: point = Point(i, j) assert point.add(add_point).equals( Point(i + add_point.x, j + add_point.y))
def rotate_ccw(self): """Rotate the tetromino by 90 degrees, counterclockwise.""" # the point of rotation, relative to the board origin abs_rotation_pt = self.origin.add(ROTATION_POINTS[self.id]) for i in range(len(self.squares)): # the square's position relative to the point of rotation current_square = Point( self.squares[i].x, self.squares[i].y).subtract(abs_rotation_pt) # the square's bottom right point, which will be the new # square origin after the rotation top_left = current_square.add(Point(0, 1)) # x -> y and y -> -x for rotation about the origin new_point = Point(-top_left.y, top_left.x).add(abs_rotation_pt) # replace the old square with the new square point = Point(int(new_point.x), int(new_point.y)) self.squares[i] = Square(point, self.color) self.state = self.state.prev()