Example #1
0
def new_game():
    from Graphic_Element import draw_graphic_elements
    Globals.do_new_game = False
    Gameboard.random_Gameboard()
    Score.Reset_Score()
    Globals.selected_element = (-1, -1)
    Gameboard.check_availible_moves()
    set_start_time()
    set_game_state(Globals.Game_State.ready)
    Graphic_Element.clear_graphic_elements()
    Seeds.reset()
    while not Globals.do_quit:
        update_ticks()
        Globals.clock.tick()
        Globals.screen.fill((0,0,0))
        draw_background()
        game_loop()
        for x in range(0, Gameboard.Gameboard_size):
            for y in range(0, Gameboard.Gameboard_size):
                obj = Gameboard.Gameboard[x][y]                    
                if (obj is not None):
                    obj.update()
                    obj.draw(x, y)
        if not Globals.selected_element == (-1, -1):
            element = get_selected_element()
            if element is not None:
                element.draw_box(Globals.selected_element)
        draw_score()
        Seeds.draw_seed_interface()
        if Globals.game_state != Globals.Game_State.game_over:
            draw_time_left()
        draw_graphic_elements(get_ticks())
        pygame.display.flip()
        Globals.clock.tick_busy_loop(60)
    Globals.do_quit = False        
Example #2
0
def new_game():
    from Graphic_Element import draw_graphic_elements
    Globals.do_new_game = False
    Gameboard.random_Gameboard()
    Score.Reset_Score()
    Globals.selected_element = (-1, -1)
    Gameboard.check_availible_moves()
    set_start_time()
    set_game_state(Globals.Game_State.ready)
    Graphic_Element.clear_graphic_elements()
    Seeds.reset()
    while not Globals.do_quit:
        update_ticks()
        Globals.clock.tick()
        Globals.screen.fill((0, 0, 0))
        draw_background()
        game_loop()
        for x in range(0, Gameboard.Gameboard_size):
            for y in range(0, Gameboard.Gameboard_size):
                obj = Gameboard.Gameboard[x][y]
                if (obj is not None):
                    obj.update()
                    obj.draw(x, y)
        if not Globals.selected_element == (-1, -1):
            element = get_selected_element()
            if element is not None:
                element.draw_box(Globals.selected_element)
        draw_score()
        Seeds.draw_seed_interface()
        if Globals.game_state != Globals.Game_State.game_over:
            draw_time_left()
        draw_graphic_elements(get_ticks())
        pygame.display.flip()
        Globals.clock.tick_busy_loop(60)
    Globals.do_quit = False
def main():
    print('test')
    seed = 'center9'
    rules = [[a, b, c] for a in range(1, 8) for b in range(a, 8)
             for c in range(a, b)]
    # rules = [[2,4,2,2],[3,4,3,3]]
    for rule in rules:
        mandala = Mandala(N=201)
        seed = Seeds.seed9(Seeds.cent(), mandala)
        print(rule)
        mandala.animate(seed, rule)
Example #4
0
 def delete(self):
     global seed_size
     global game_started
     Score.Add_Match(self.x_length + self.y_length)
     if (self.x_length + self.y_length >= seed_size):
         Seeds.add_seed(get_element_index(self.x, self.y))
     if self.x_length > 0:
         for i in range(0, self.x_length):
             delete_object(self.x + i, self.y)
     elif self.y_length > 0:
         for i in range(0, self.y_length):
             delete_object(self.x, self.y + i)
     ## Grow any seeds on the board
     if game_started:
         grow_seeds()
         Audio.Match()
def alignerSpark(dict,genome, hashDF, sc, dict_map):
    k = 10
    for i in dict_map.keys():
        print ("• Allineamento sequenza n°", i)
        reDF = Seeds.Sparkseeds(dict, i, k, hashDF, sc)
        reDF = reDF.withColumn('ex', F.explode('POS_GEN'))
        reDF = reDF.withColumn('Flag', F.when((F.col('ex') < dict_map[i][1]) & (F.col("ex") > dict_map[i][0] ), 1).otherwise(0))
        reDF = reDF.filter(reDF.Flag == 1).select(reDF.NUM_SEQ, reDF.ID_SEQ, reDF.POS_SEQ, reDF.POS_GEN, reDF.Flag)
        if reDF.count() >= 3:
        #     # print("0 per Allineamento locale")
        #     # print("1 per Allineamento globale")
        #     # scelta = int(input("Scelta tipologia di allineamento: "))
            seedArray = [x["POS_SEQ"] for x in reDF.rdd.collect()]
        #     print("SeedArray finale:", seedArray)
            PG = [x["POS_GEN"] for x in reDF.rdd.collect()]
            optloc = None
            df,min_percentage = best_choice(dict, i, PG, seedArray, genome,sc)
            Gen = [x["GEN"] for x in df.rdd.collect()]
            for gen in Gen:
                D, B = Aligner.createB(dict[i], gen)
                if ((100-min_percentage[0])<60.0):
                #if scelta == 0:
                    A,optloc = Aligner.local_align(dict[i], gen, Aligner.ScoreParam())  # Smith-Waterman
                    bt = Aligner.backtrack(B, optloc, A)
                else:
                    M = Aligner.affine_align(dict[i], gen, Aligner.ScoreParam())  # Needleman-Wunsch
                    bt = Aligner.backtrack(B, optloc, M)
                aligned_word_1, aligned_word_2, operations, line = Aligner.align(gen, dict[i], bt)
                print("Lunghezza sequenze: ", len(dict[i]), "| Numero operazioni: ", len(operations))
                alignment_table = [aligned_word_1, line, operations, line, aligned_word_2]
                print(tb.tabulate(alignment_table, tablefmt="orgtbl"))
                print()
        else:
            print()
Example #6
0
def Main():
    if __name__ != "__main__":
        return
    global current_ticks
    global cursor_pos
    Audio.Init()
    Globals.init()
    Globals.clock = pygame.time.Clock()
    Globals.screen = pygame.display.set_mode((Globals.screenX, Globals.screenY))
    TextHandler.Init()
    pygame.init()
    load_images()
    create_objects()
    Seeds.seed_init(len(Globals.all_objects))
    while Globals.do_new_game:
        new_game()
    pygame.display.quit()
Example #7
0
def poll_events():
    global selected_seed
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                cleanup()
            elif Globals.game_state == Globals.Game_State.game_over:
                Globals.do_quit = True
                Globals.do_new_game = True
        elif event.type == QUIT:
            Globals.do_quit = True
        elif event.type == MOUSEBUTTONDOWN:
            if event.button == 1:
                if Globals.game_state == Globals.Game_State.game_over:
                    Globals.do_quit = True
                    Globals.do_new_game = True
                    return
                selected_seed = Seeds.get_selected_seed()
                if selected_seed != -1:
                    if (Seeds.can_plant(selected_seed)):
                        pos = mouse_to_coord(pygame.mouse.get_pos())
                        if (pos[0] < 0 or pos[0] > Gameboard.Gameboard_size
                                or pos[1] < 0
                                or pos[1] > Gameboard.Gameboard_size):
                            Seeds.selected_seed = -1
                        else:
                            Gameboard.plant_seed(pos,
                                                 Seeds.get_selected_seed())
                            Seeds.remove_seed(selected_seed)
                    Seeds.selected_seed = -1
                else:
                    try_swap()
                    Seeds.check_seed_click(pygame.mouse.get_pos())
        elif event.type == MOUSEMOTION:
            cursor_pos = pygame.mouse.get_pos()
Example #8
0
def poll_events():
    global selected_seed
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            if event.key == K_ESCAPE:
                cleanup()
            elif Globals.game_state == Globals.Game_State.game_over:
                Globals.do_quit = True
                Globals.do_new_game = True
        elif event.type == QUIT:
            Globals.do_quit = True
        elif event.type == MOUSEBUTTONDOWN:
            if event.button == 1:
                if Globals.game_state == Globals.Game_State.game_over:
                    Globals.do_quit = True
                    Globals.do_new_game = True
                    return
                selected_seed = Seeds.get_selected_seed()
                if selected_seed != -1:
                    if (Seeds.can_plant(selected_seed)):
                        pos = mouse_to_coord(pygame.mouse.get_pos())
                        if (pos[0] < 0 or pos[0] > Gameboard.Gameboard_size or
                            pos[1] < 0 or pos[1] > Gameboard.Gameboard_size):
                            Seeds.selected_seed = -1
                        else:
                            Gameboard.plant_seed(pos, Seeds.get_selected_seed())
                            Seeds.remove_seed(selected_seed)
                    Seeds.selected_seed = -1
                else:
                    try_swap()
                    Seeds.check_seed_click(pygame.mouse.get_pos())
        elif event.type == MOUSEMOTION:
            cursor_pos = pygame.mouse.get_pos()
Example #9
0
def Main():
    if __name__ != "__main__":
        return
    global current_ticks
    global cursor_pos
    Audio.Init()
    Globals.init()
    Globals.clock = pygame.time.Clock()
    Globals.screen = pygame.display.set_mode(
        (Globals.screenX, Globals.screenY))
    TextHandler.Init()
    pygame.init()
    load_images()
    create_objects()
    Seeds.seed_init(len(Globals.all_objects))
    while Globals.do_new_game:
        new_game()
    pygame.display.quit()
Example #10
0
def plant_seed(pos, index):
    global Gameboard
    from Main import make_element
    if not Seeds.can_plant(index):
        return
    x = pos[0]
    y = pos[1]
    obj = make_element(index)
    obj.growth_turn = Globals.current_turn + Globals.growth_time
    obj.grown = False
    Gameboard[x][y] = obj
    def __init__(self):  # todo define clod limets
        """Initialise an instance of seedbed
        :parameter clod_no: the number of each clod - 1 indexed
        :parameter clod_set: the min size of the clod for a grouped lot of clods
        :parameter clod: the clod in this set
        :parameter clod_lims: an array representing the [L,h,l] for a clod
        :parameter clod_serf_prob: the result of a function call to find where the clod is stuck [False,False,False] for [prob_serf, stuck_serf, stuck_soil]
        :parameter Clod: the class that makes a clod object
        :parameter sd: a seed in this sowing
        :parameter Seed: the class that makes a Seed object
        """
        self.setup.sort_clods()
        clod_no = 0  # a unique clod number for each clod
        for clod_set in range(0, len(self.setup.clod_nos)):
            for clod in range(
                    0,
                    Clods.clod_numbers(self.setup.clod_nos[clod_set],
                                       self.setup.plot_xyz)):
                clod_no += 1  # update for each clod
                Write.run_summ("clod " + str(clod_no))
                clod_lims = Clods.clod_size(self.setup.clod_lims, clod_set)
                radi = (sum(clod_lims) / 3.0) / 2.0
                clod_serf_prob = Fun.clod_restriction(
                    self.setup.p_serf[clod_set],
                    self.setup.p_stuck_serf[clod_set],
                    self.setup.p_stuck_soil[clod_set])
                self.clod_bed.append(
                    Clods.Clod(
                        clod_no,
                        Fun.position_calc(
                            self.seed_tray, self.clod_bed,
                            self.setup.plot_xyz[2] - self.setup.sow_depth,
                            self.setup.plot_xyz, True, radi, clod_serf_prob),
                        self.setup.plot_xyz[2], clod_lims))
                #print self.clod_bed[clod]

        for sd in range(0, self.setup.no_seeds):
            self.seed_tray.append(
                Seeds.Seed(
                    sd + 1, self.setup.day_death, self.setup.therm_times,
                    self.setup.base_germ, self.setup.base_elong,
                    self.setup.base_wet,
                    Fun.position_calc(
                        self.seed_tray, self.clod_bed,
                        self.setup.plot_xyz[2] - self.setup.sow_depth,
                        self.setup.plot_xyz, False)))
            Write.run_summ("seed " + str(sd + 1) + " initialised")
            print self.seed_tray[sd]
Example #12
0
def aligner(dict, genome, ht):
    k = 10
    for i in range(0, 1):
        print("• Allineamento sequenza n°", i + 1)
        re = Seeds.seeds(dict, i, k, ht)
        print("SeedArray finale:", re)
        for r in re:
            # print("0 per Allineamento locale")
            # print("1 per Allineamento globale")
            # scelta = int(input("Scelta tipologia di allineamento: "))
            for pos_gen in ht[r[1]]:
                optloc = None
                D, B = createB(
                    dict[i],
                    genome[pos_gen - r[0]:pos_gen - r[0] + len(dict[i])])
                if ((100 -
                     (D[len(D) - 1][len(D) - 1] / float(len(dict[i]))) * 100) <
                        60.0):
                    # if scelta == 0:
                    print(
                        "-",
                        round(
                            100 -
                            (D[len(D) - 1][len(D) - 1] / float(len(dict[i]))) *
                            100, 2), "% ---> Local alignment")
                    A, optloc = local_align(
                        dict[i],
                        genome[pos_gen - r[0]:pos_gen - r[0] + len(dict[i])],
                        ScoreParam())
                else:
                    print(
                        "-",
                        round(
                            100 -
                            (D[len(D) - 1][len(D) - 1] / float(len(dict[i]))) *
                            100, 2), "% ---> Global alignment")
                    M = affine_align(
                        dict[i],
                        genome[pos_gen - r[0]:pos_gen - r[0] + len(dict[i])],
                        ScoreParam())
                if optloc == None:
                    bt = backtrack(B, optloc, M)
                    # edit_distance_table = make_table(dict[i][pos_seq:len(dict[i])-pos_seq], genome[pos_gen:pos_gen+len(dict[i])-pos_seq], D, B, bt)
                    aligned_word_1, aligned_word_2, operations, line = align(
                        genome[(pos_gen - r[0]):(pos_gen - r[0] +
                                                 len(dict[i]))], dict[i], bt)
                    # print(tb.tabulate(edit_distance_table, stralign="right", tablefmt="orgtbl"))
                    print("Lunghezza sequenze: ", len(dict[i]),
                          "| Numero operazioni: ", len(operations))
                    print(dict[i])
                    print(genome[(pos_gen - r[0]):(pos_gen - r[0] +
                                                   len(dict[i]))])
                    alignment_table = [
                        aligned_word_1, line, operations, line, aligned_word_2
                    ]
                    print(tb.tabulate(alignment_table, tablefmt="orgtbl"))
                    print()
                else:
                    bt = backtrack(B, optloc, A)
                    aligned_word_1, aligned_word_2, operations, line = align(
                        genome[(pos_gen - r[0]):(pos_gen - r[0] +
                                                 len(dict[i]))], dict[i], bt)
                    print("Lunghezza sequenze: ", len(dict[i]),
                          "| Numero operazioni: ", len(operations))
                    print(dict[i])
                    print(genome[(pos_gen - r[0]):(pos_gen - r[0] +
                                                   len(dict[i]))])
                    alignment_table = [
                        aligned_word_1, line, operations, line, aligned_word_2
                    ]
                    print(tb.tabulate(alignment_table, tablefmt="orgtbl"))
                    print()
        else:
            print()
    else:
        print()