示例#1
0
    def test_fire(self):
        Bg = mark_util.MarkBg
        Fg = mark_util.MarkFg
        Width = 4
        Height = 5
        Area = area.make_empty(Width, Height, Bg)
        AreaDuplicated = area.duplicate(
            Area)  # later we modify Area with burning
        Burning = [(1, 1), (2, 3)]
        area.fire(Area, Burning, [Fg], ["Left"])

        Wanted = ("...." "FF.." "...." "FFF." "....")

        self.assertEqual(Wanted, area.to_string(Area, OneLine=True))

        # The duplicated Area is independent from burning Area, made with deepcopy
        # the duplicated area has to be emtpy, like a new empty area.
        # area is a complex struct, and we made a real duplication, not a shallow copy
        self.assertEqual(area.to_string(area.make_empty(Width, Height, Bg)),
                         area.to_string(AreaDuplicated))

        ##########################################
        Area2 = area.make_empty(Width, Height, Bg)
        Area2[2][1] = "X"
        Burning = [(1, 1), (2, 3)]
        area.fire(Area2, Burning, [Fg, "X"], ["Up"])
        Wanted = (".F.." ".FX." "..F." "..F." "....")

        self.assertEqual(Wanted, area.to_string(Area2, OneLine=True))
示例#2
0
 def test_area_to_string(self):
     Bg = mark_util.MarkBg
     Fg = mark_util.MarkFg
     # there are two columns in the Area
     Area = [[Bg, Bg, Bg], [Bg, Fg, Bg]]
     Wanted = "..\n.O\n.."
     self.assertEqual(Wanted, area.to_string(Area))
示例#3
0
 def test_area_coord_insert(self):
     Bg = mark_util.MarkBg
     Fg = mark_util.MarkFg
     Area = area.make_empty(5, 6, Bg)
     Mark = {"Coords": {(1, 1): 1, (2, 2): 2, (3, 3): 3, (1, 3): 4}}
     area.coords_insert_from_mark(Area, Mark, Fg, Xshift=1, Yshift=1)
     Wanted = (".....\n" ".....\n" "..O..\n" "...O.\n" "..O.O\n" ".....")
     self.assertEqual(Wanted, area.to_string(Area))
示例#4
0
def spirals_display(Prg,
                    Spirals,
                    Width,
                    Height,
                    SleepTime=0,
                    Prefix="",
                    PauseAtEnd=0,
                    PauseAtStart=0,
                    SaveAsFilename=None):
    SaveAsTxt = list()

    CharBg = "🔸"  #small orange diamond
    CharsetColorful = [
        "😎",  # smiling face with sunglasses
        "🔘",  #radio button,
        "🌼",
        "🍀",
        "🐙",
        "🎃",  # jack-o-lantern
        "🐸",  # frog face
        "🎅",  # father christmas
        "🐨",  # koala
        "🎁",  # Wrapped present,
        "🌷",  # tulip
        "🏀",  # basketball and hoop
        "😈",  # smiling face with horns
        "🕐",  # clock face, one o'clock
        "🔴",  #large red circle
        "🔵",  #large blue circle,
        "🔆",  # high brightness symbol
        "💜",  #purple heart
        "🔅",  # low brightness symbol
        "🌑",  # new moon symbol
        "💡",  # electric light bulb
    ]

    Area = area.make_empty(Width, Height, CharBg)
    print(
        area.to_string(Area,
                       Prefix=Prefix,
                       AfterString="\n\n",
                       BeforeString="\n" * 33))
    time.sleep(PauseAtStart)

    for Coords in Spirals.values():
        CharColorful = CharsetColorful.pop(0)
        CharsetColorful.append(
            CharColorful)  # shifting elements in Colorful chars

        for X, Y in Coords:
            Area[X][Y] = CharColorful
            AreaTxt = area.to_string(Area,
                                     Prefix=Prefix,
                                     AfterString="\n\n",
                                     BeforeString="\n" * 33)
            SaveAsTxt.append(AreaTxt)
            print(AreaTxt)
            if SleepTime:
                time.sleep(SleepTime)

    if PauseAtEnd:
        time.sleep(PauseAtEnd)

    if SaveAsFilename:
        util.file_write(Prg, os.path.join(Prg["DirTmpPath"], SaveAsFilename),
                        "".join(SaveAsTxt))
示例#5
0
    def test_fire_from_side(self):
        Bg = mark_util.MarkBg
        Fg = mark_util.MarkFg
        Width = 6
        Height = 5

        ########### Test from Right #############################
        Area = area.make_empty(Width, Height, Bg)

        # this is a ⊃  math sign, more or less :-)
        Area[2][1] = Fg;    Area[3][1] = Fg;   Area[4][1] = Fg
        pass;                                  Area[4][2] = Fg
        Area[2][3] = Fg;    Area[3][3] = Fg;   Area[4][3] = Fg

        FireInfo = area.fire_from_side(Area, "Right", [Fg])

        Wanted = ("FFFFFF"
                  "FFOOOF"
                  "FF..OF"
                  "FFOOOF"
                  "FFFFFF")

        self.assertEqual(Wanted, area.to_string(Area, OneLine=True))
        self.assertEqual(21, FireInfo["BurntAreaSize"])

        ########### Test from Left#############################
        Area = area.make_empty(Width, Height, Bg)

        # stylized I sign
        Area[2][1] = Fg;    Area[3][1] = Fg;   Area[4][1] = Fg
        pass;               Area[3][2] = Fg
        Area[2][3] = Fg;    Area[3][3] = Fg;   Area[4][3] = Fg

        area.fire_from_side(Area, "Left", [Fg])

        Wanted = ("FFFFFF"
                  "FFOOOF"
                  "FFFO.F"
                  "FFOOOF"
                  "FFFFFF")

        self.assertEqual(Wanted, area.to_string(Area, OneLine=True))


        ########### Test from Top #############################
        Width = 5
        Height = 5

        Area = area.make_empty(Width, Height, Bg)
        Area[0][1] = Fg
        Area[1][1] = Fg
        Area[2][1] = Fg
        Area[3][1] = Fg
        Area[4][1] = Fg

        area.fire_from_side(Area, "Top", [Fg])

        Wanted = ("FFFFF"
                  "OOOOO"
                  "....."
                  "....."
                  ".....")

        self.assertEqual(Wanted, area.to_string(Area, OneLine=True))



        ########### Test from Bottom #############################
        Width = 5
        Height = 5

        Area = area.make_empty(Width, Height, Bg)
        Area[0][1] = Fg
        Area[1][1] = Fg
        Area[2][1] = Fg
        Area[3][1] = Fg
        Area[4][1] = Fg

        area.fire_from_side(Area, "Bottom", [Fg])

        Wanted = ("....."
                  "OOOOO"
                  "FFFFF"
                  "FFFFF"
                  "FFFFF")

        self.assertEqual(Wanted, area.to_string(Area, OneLine=True))
示例#6
0
def mark_area_convex(Prg, Marks, MarkId, MarkStats):
    Mark = Marks[MarkId]
    AreaConvex = mark_util.mark_area_convex(Prg, Mark)
    mark_info_insert(Prg, MarkStats, MarkId,
                     [("mark_area_convex", "\n" + area.to_string(AreaConvex))])
示例#7
0
def mark_area_select_closed_empty_area(Prg, Marks, MarkId, MarkStats):
    Fg = mark_util.MarkFg
    Bg = mark_util.MarkBg

    Mark = Marks[MarkId]
    AreaFired = mark_util.mark_to_area(Mark)

    #                   on right side you can find the closed empty areas:
    #     ....OOOOOOO...       signed with '.' chars,                         FFFFOOOOOOOFFF
    #     ..OOOOOOOOOO..       F means: fired/reached from outside            FFOOOOOOOOOOFF
    #     .OOOOOOOOOOOO.                                                      FOOOOOOOOOOOOF
    #     .OOOOO..OOOOO.        the closed block size = 14 in this case:      FOOOOO..OOOOOF
    #     OOOO......OOOO                                                      OOOO......OOOO
    #     OOOO......OOOO                                                      OOOO......OOOO
    #     OOOOOOOOOOOOOO   all direction is important here, because:          OOOOOOOOOOOOOO
    #     OOOOOOOOOOOOOO                                                      OOOOOOOOOOOOOO
    #     OOO...........  in case of letter e, if you fire from right         OOOFFFFFFFFFFF
    #     OOOO..........  the *** chars will be empty because Bottom Fire     OOOOFFFFFFFFFF
    #     OOOO..........  can't go down basically,                            OOOOFFFFFFFFFF
    #     .OOOOOO***OOO.  and it fills the area with F sign                   FOOOOOOFFFOOOF
    #     .OOOOOOOOOOOO.  and can't fill *** with F so in this situation      FOOOOOOOOOOOOF
    #     ..OOOOOOOOOOO.  when starts a fire, it can spread                   FFOOOOOOOOOOOF
    #     ....OOOOOOOO..  into any direction                                  FFFFOOOOOOOOFF

    CharFire = "F"  # Directions: not all, because if there is only 1 pixel wide frame around
    Directions = ["Left", "Right", "Up",
                  "Down"]  # the closed area, the fire can enter into it

    area.fire_from_side(AreaFired,
                        "Top", [Fg],
                        Directions=Directions,
                        CharFire=CharFire)
    area.fire_from_side(AreaFired,
                        "Bottom", [Fg],
                        Directions=Directions,
                        CharFire=CharFire)
    area.fire_from_side(AreaFired,
                        "Left", [Fg],
                        Directions=Directions,
                        CharFire=CharFire)
    area.fire_from_side(AreaFired,
                        "Right", [Fg],
                        Directions=Directions,
                        CharFire=CharFire)

    AreaFiredInConvex = area.mask_with_convex_shape(
        AreaFired, mark_util.mark_area_convex(Prg, Mark), Fg, Bg)

    AreaStr = area.to_string(AreaFiredInConvex)
    mark_info_insert(Prg, MarkStats, MarkId,
                     [("mark_area_open_in_convex", "\n" + AreaStr)])

    NumOfClosedEmptyPixels = area.pattern_count(AreaFired, [Bg])

    MarkNumOfPixels = len(Mark.keys())
    MarkAreaClosedEmptyRatio = NumOfClosedEmptyPixels[Bg] / MarkNumOfPixels
    mark_info_insert(
        Prg, MarkStats, MarkId,
        [("mark_area_closed_empty_ratio", str(MarkAreaClosedEmptyRatio))])

    # TODO: num of closed area (above some %)
    # TODO: ratio of open area
    BlockVolume, BlockSizes = area.count_separated_blocks(
        AreaFired, Bg, [Fg, CharFire])
    mark_info_insert(Prg, MarkStats, MarkId,
                     [("separated_blocks_volume", str(BlockVolume))])
    mark_info_insert(Prg, MarkStats, MarkId,
                     [("separated_blocks_sizes", str(BlockSizes))])
示例#8
0
    def test_mark_area_convex(self):
        Mark = {
            "Coords": {
                (1, 1): 1,
                (2, 2): 2,
                (3, 3): 3,
                (1, 3): 4
            },
            "Width": 3,
            "Height": 3,
            "Xmin": 1,
            "Ymin": 1,
            "Xmax": 3,
            "Ymax": 3
        }
        AreaConvexGenerated = mark_util.mark_area_convex(Prg, Mark)
        AreaWanted = ("O..\n" "OO.\n" "OOO")
        self.assertEqual(AreaWanted, area.to_string(AreaConvexGenerated))

        ####################################
        Mark = {
            "Coords": {
                (1, 1): 11,
                (2, 1): 21,
                (3, 1): 31,
                (1, 2): 12,
                (1, 3): 13,
                (1, 4): 14,
                (1, 5): 15,
                (2, 5): 25,
                (3, 5): 35,
                (4, 5): 45,
                (5, 5): 55
            },
            "Width": 5,
            "Height": 5,
            "Xmin": 1,
            "Ymin": 1,
            "Xmax": 5,
            "Ymax": 5
        }

        AreaConvexGenerated = mark_util.mark_area_convex(Prg, Mark)
        AreaWanted = ("OOO..\n" "OOOO.\n" "OOOO.\n" "OOOO.\n" "OOOOO")
        self.assertEqual(AreaWanted, area.to_string(AreaConvexGenerated))

        ################## + sign convex area test ###################

        Mark = {
            "Coords": {
                (3, 2): 32,
                (3, 3): 33,
                (3, 4): 34,
                (0, 5): 5,
                (1, 5): 15,
                (2, 5): 25,
                (3, 5): 35,
                (4, 5): 45,
                (5, 5): 55,
                (6, 5): 65,
                (3, 6): 36,
                (3, 7): 37,
                (3, 8): 38
            },
            "Width": 7,
            "Height": 7,
            "Xmin": 0,
            "Ymin": 2,
            "Xmax": 6,
            "Ymax": 8
        }
        AreaConvexGenerated = mark_util.mark_area_convex(Prg, Mark)
        AreaWanted = ("...O...\n"
                      "..OOO..\n"
                      ".OOOOO.\n"
                      "OOOOOOO\n"
                      ".OOOOO.\n"
                      "..OOO..\n"
                      "...O...")
        self.assertEqual(AreaWanted, area.to_string(AreaConvexGenerated))
示例#9
0
def mark_to_string(Mark):
    return area.to_string(mark_to_area(Mark))