Esempio n. 1
0
 def __init__(self):
     self.board = Board(ROWS, COLUMNS)
     self.gui = GUI(ROWS, COLUMNS, SIZE, self.board)
     self.rules = Rules()
     self.cursor = Cursor()
     self.player1 = Player(1)
     self.player2 = AIPlayer(2, self.rules, self.board)
     self.currentPlayer = self.assign_player()
     self.gameOver = False
     self.menuFlag = False
Esempio n. 2
0
 def begin(self):
     # Get controller inputs from current states
     # Run integrator threads, update quadcopter states
     # Wait until maximum of threads finished or dt hit
     # Update gui
     # Repeat
     simulate = multiprocessing.Process(None,
                                        self.integration,
                                        args=(self.queue, ))
     simulate.start()
     self.GUI = GUI(model=self.models[-1]["model"], queue=self.queue)
Esempio n. 3
0
 def moderate(self):
     loader_back = Loader('Orchestrator/Back/dist')
     loader_front = Loader('Orchestrator/Front/dist')
     core = Core()
     core.verify_rulers()
     gui = GUI()
     gui.get_data()
     gui.show()
     gui2 = GUI2()
     gui2.get_data()
     gui2.show()
     notification = Notification()
     notification.notify()
Esempio n. 4
0
    def run(self):
        gui = GUI(WIN_WIDTH, WIN_HEIGHT, GRID_SIZE)

        if self.gui_active:
            gui.start()

        while True:
            grid = Grid(GRID_SIZE)

            if not grid.read_grid(self.sudoku_file):
                msg = "Sudoku not in valid format"

                if self.gui_active:
                    gui.print_message(msg)
                else:
                    print(msg)

                break

            msg = "Initial sudoku grid"
            if self.gui_active:
                if not gui.initial_screen(grid, msg):
                    break
            else:
                print(msg)
                grid.print()

            # Perform constraint propagation
            grid.propagate_constraints_all_cells()

            msg = "After constraint propagation"
            if self.gui_active:
                if not gui.screen_with_message(grid, msg):
                    break
            else:
                print(msg)
                grid.print()

            # Try deducing values of some cells
            grid.deduce_vals_all_cells()

            msg = "After deducing values"
            if self.gui_active:
                if not gui.screen_with_message(grid, msg):
                    break
            else:
                print(msg)
                grid.print()

            if grid.not_solvable():
                msg = "Sudoku not solvable"

                if self.gui_active:
                    if gui.final_screen(msg):
                        continue
                    else:
                        break
                else:
                    print(msg)

            if grid.all_cells_fixed():
                msg = "Sudoku solved"

                if self.gui_active:
                    if gui.final_screen(msg):
                        continue
                    else:
                        break
                else:
                    print(msg)

            # Solve using ant colony system
            msg = "Ant colony system"
            if self.gui_active:
                gui.print_message(msg)
            else:
                print(msg)

            solver = AntSolver(grid, GLOBAL_PHER_UPDATE, BEST_PHER_EVAPORATION,
                               NUM_OF_ANTS, gui, self.gui_active)
            solution = solver.solve(LOCAL_PHER_UPDATE, GREEDINESS)

            if solution.is_valid():
                msg = "Sudoku solved!"

                if self.gui_active:
                    if gui.final_screen(msg):
                        continue
                    else:
                        break
                else:
                    print(msg)
                    break
            else:
                msg = "Sudoku solution not valid"

                if self.gui_active:
                    if gui.final_screen(msg):
                        continue
                    else:
                        break
                else:
                    print(msg)
                    break

        if self.gui_active:
            gui.end()
Esempio n. 5
0
    logger.debug('Starting main')

    simon = SimplePlayer
    human = SimpleHumanPlayer
    nanny = NNSimpleGamePlayer
    #    nanny = NeuralNetwork

    player1 = human()
    player2 = nanny()
    # player1 = randy()
    # player1 = simon('simon')

    human = None
    for player in [player1, player2]:
        if type(player) is SimpleHumanPlayer:
            human = player
        if player.requires_model_load:
            player.load_model()

    player1_wins = 0
    player2_wins = 0

    game = SimpleGame(player1, player2)

    if human is not None:
        human.UI = GUI(game, human)
        human.UI.mainloop()

    else:
        GameHelpers.play_automated_games(game, 1000)
Esempio n. 6
0
def main():
    json = JSON() 
    congress = json.Read() # Called the json reading method to insert the data in the tree
    GUI(congress) # Called the GUI, passing him the class with the tree 
Esempio n. 7
0
def main():
    base = 3
    automaton = Automaton()
    comb = automaton.createBase(base)
    automaton.createCell(comb, 10, base - 1, ['Bajo', 'Guitarra', 'Voz'])
    GUI(automaton)
Esempio n. 8
0
def main():
    json = JSON()
    graph = json.Read()
    GUI(graph)
from GUI.GUI import GUI

window = GUI()
window.run()
Esempio n. 10
0
 def __init__(self):
     self.gui = GUI(self, list(self.selection_methods.keys()), list(self.mutation_methods.keys()),
                    list(self.crossing_methods.keys()))
Esempio n. 11
0
class Genetic:
    selection_methods = {
        "The best of selection": (TheBestOfSelection,),
        "Roulette selection": (RouletteSelection,),
        "Tournament Selection": (TournamentSelection,)
    }
    crossing_methods = {
        "One point crossing": (PointCrossover, ("points", 1)),
        "Two point crossing": (PointCrossover, ("points", 2)),
        "Three point crossing": (PointCrossover, ("points", 3)),
        "Uniform crossing": (UniformCrossover,),
        "Arithmetic crossing": (ArithmeticCrossover,),
        "Heuristic crossing": (HeuristicCrossover,)
    }
    mutation_methods = {
        "One point mutation": (PointMutation, ("points", 1)),
        "Two point mutation": (PointMutation, ("points", 2)),
        "Three point mutation": (PointMutation, ("points", 3)),
        "Edge mutation": (EdgeMutation,),
        "Uniform mutation": (UniformMutation,)
    }

    def __init__(self):
        self.gui = GUI(self, list(self.selection_methods.keys()), list(self.mutation_methods.keys()),
                       list(self.crossing_methods.keys()))

    def run(self):
        self.gui.show()

    @staticmethod
    def create_strategy(config):
        strategy = config[0]()
        for dict_element in config[1:]:
            strategy[dict_element[0]] = dict_element[1]
        return strategy

    def start_work(self, x_value, digits_count, population_size, generations_number, elite_strategy_value,
                   inversion_probability, crossing_probability, mutation_probability, selection_method_name,
                   tournament_size, mutation_method_name, crossing_method_name, minimum, k_selection):
        file = open("result.txt", "w")

        elite_strategy_count = round(population_size * elite_strategy_value)
        variables_names = ['x', 'y']
        chromosome_size = calculate_the_number_of_genes(x_value) + digits_count
        population = make_random_population(population_size, chromosome_size, variables_names)

        precisions = {"x": digits_count, "y": digits_count}

        if minimum:
            fitness_function = partial(ackley_function_minimum_fitness_funtion, precisions)
        else:
            fitness_function = partial(ackley_function_maximum_fitness_funtion, precisions)

        selection_strategy = self.create_strategy(self.selection_methods[selection_method_name])
        selection_strategy["count"] = round(population_size - elite_strategy_count)
        selection_strategy["fitness_function"] = fitness_function
        selection_strategy["tournament_size"] = tournament_size
        selection_strategy.check_required_parameters()

        mutation_strategy = self.create_strategy(self.mutation_methods[mutation_method_name])
        mutation_strategy["chromosomes"] = variables_names
        mutation_strategy["probability"] = mutation_probability
        mutation_strategy["min"] = -x_value
        mutation_strategy["max"] = x_value - 1
        mutation_strategy["precision"] = digits_count
        mutation_strategy["fill"] = chromosome_size
        mutation_strategy.check_required_parameters()

        crossing_strategy = self.create_strategy(self.crossing_methods[crossing_method_name])
        crossing_strategy["chromosomes"] = variables_names
        crossing_strategy["probability"] = crossing_probability
        crossing_strategy["k_selection_function"] = lambda: k_selection
        crossing_strategy["precisions"] = precisions
        crossing_strategy["fills"] = {"x": chromosome_size, "y": chromosome_size}
        crossing_strategy.check_required_parameters()

        inversion_strategy = Inversion()
        inversion_strategy["chromosomes"] = variables_names
        inversion_strategy["probability"] = inversion_probability
        inversion_strategy.check_required_parameters()

        elite_strategy = EliteStrategy()
        elite_strategy["count"] = elite_strategy_count
        elite_strategy["fitness_function"] = fitness_function
        elite_strategy["tournament_size"] = tournament_size
        elite_strategy.check_required_parameters()

        simulation = Simulation(population, generations_number, selection_strategy, crossing_strategy,
                                mutation_strategy, fitness_function, elite_strategy, inversion_strategy, minimum)
        result_params, result_value, value_history = simulation.simulate()
        self.gui.show_result(result_params, result_value)
        PlotGenerator().generate(value_history, minimum)
        for epoch in value_history:
            file.write(str(epoch) + '\n')
        file.close()
Esempio n. 12
0
from GUI.GUI import GUI

if __name__ == '__main__':
    GUI()
Esempio n. 13
0
class Game:
    def __init__(self):
        self.board = Board(ROWS, COLUMNS)
        self.gui = GUI(ROWS, COLUMNS, SIZE, self.board)
        self.rules = Rules()
        self.cursor = Cursor()
        self.player1 = Player(1)
        self.player2 = AIPlayer(2, self.rules, self.board)
        self.currentPlayer = self.assign_player()
        self.gameOver = False
        self.menuFlag = False

    def assign_player(self):
        a = random.randint(0, 1)
        if a == 0:
            self.gui.next_move_message(self.player1.get_id())
            return self.player1
        else:
            self.gui.next_move_message(self.player2.get_id())
            return self.player2

    def switch_players(self):
        if self.currentPlayer == self.player1:
            self.currentPlayer = self.player2
        else:
            self.currentPlayer = self.player1
        self.gui.next_move_message(self.currentPlayer.get_id())

    def reset(self):
        self.menuFlag = False
        self.board.reset()

    def change_rules(self, rule):
        if rule == 1:
            self.rules = Rules()
        elif rule == 2:
            self.rules = DiagonalOnly()
        else:
            self.rules = RowsColumnsOnly()
        self.reset()

    def update_cursor(self, event):
        x = event.pos[0]
        y = event.pos[1]
        self.cursor.update(x, y)

    def mouse_motion(self):
        if self.gameOver is False and self.menuFlag is False:
            if self.gui.are_buttons_hovered(self.cursor.gety()):
                self.gui.buttons_hovered(self.cursor.getx())
            else:
                self.gui.draw_gui(self.board)
        elif self.menuFlag:
            if self.gui.are_rules_hovered(self.cursor.getx(),
                                          self.cursor.gety()):
                self.gui.rules_hovered(self.cursor.getx(), self.cursor.gety())
            else:
                self.gui.draw_gui(self.board)

    def move_made(self):
        if self.rules.winning_move(self.board.get_board(),
                                   self.currentPlayer.get_id(),
                                   self.board.get_columns(),
                                   self.board.get_rows()):
            self.gameOver = True
            self.gui.winning_move_message(self.currentPlayer.get_id())
        elif self.board.is_full():
            self.gui.draw_message()
            self.gameOver = True
        else:
            self.switch_players()
        #print(self.board.get_board())

    def mouse_clicked(self):
        if self.gameOver is False and self.menuFlag is False:
            if self.gui.are_buttons_hovered(self.cursor.gety()):
                col = int(math.floor(self.cursor.getx() / self.gui.get_size()))
                if self.currentPlayer.make_move(self.board, col):
                    self.move_made()
                else:
                    self.gui.not_valid_loc_message(self.currentPlayer.get_id())
            self.gui.draw_gui(self.board)
        elif self.menuFlag:
            if self.gui.are_rules_hovered(self.cursor.getx(),
                                          self.cursor.gety()):
                rule = self.gui.get_rule(self.cursor.getx(),
                                         self.cursor.gety())
                self.change_rules(rule)
                self.gui.shut_rules()
                self.gameOver = self.menuFlag = False
                self.reset()
        if self.gui.reset_hovered(self.cursor.getx(), self.cursor.gety()):
            self.board.reset()
            self.assign_player()
            self.gameOver = self.menuFlag = False
        if self.gui.are_options_hovered(self.cursor.getx(),
                                        self.cursor.gety()):
            self.gui.options_hovered(self.menuFlag)
            self.menuFlag = not self.menuFlag
        self.gui.draw_gui(self.board)

    def start_game(self):
        while True:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
                if self.currentPlayer.get_type() == "player":
                    if event.type == pygame.MOUSEMOTION:
                        self.update_cursor(event)
                        self.mouse_motion()
                    elif event.type == pygame.MOUSEBUTTONDOWN:
                        self.update_cursor(event)
                        self.mouse_clicked()
                elif self.currentPlayer.get_type() == "AI":
                    if not self.gameOver and not self.menuFlag:
                        if self.currentPlayer.make_move(self.board, 0):
                            self.move_made()
                        else:
                            self.gui.not_valid_loc_message(
                                self.currentPlayer.get_id())
                        self.gui.draw_gui(self.board)
                    else:
                        self.currentPlayer = self.player1
Esempio n. 14
0
def main():
    automaton = Automaton()
    automaton.AddRoot(4, 0, [], 'L')
    GUI(automaton)