def generate_random_tests(maze): individual_per_generation = [5, 10, 25] steps = [30, 50, 75] rounds = [50, 100, 250, 500] mutation = [0.10, 0.20, 0.30, 0.40] stop_breeding = [30, 50, 150, 350] test_list = [] dict_test = {} id_ = 0 for ind in individual_per_generation: for stp in steps: for rnd in rounds: for mtn in mutation: for stop in stop_breeding: test_list.append(Teste(ind, stp, rnd, mtn, stop)) for index, config in enumerate(test_list): robot = ia.IA(maze, config.ipg, config.steps, config.rounds, config.mutation, config.stop_breeding, 'Fast') robot.make_run() print(f"Testando... {index}/{len(test_list)}")
def main(argv): strategy = soft_strategy.SoftStrategy() strategy = medium_strategy.SoftStrategy() strategy = hard_strategy.HardStrategy() IA = ia.IA(strategy) ''' Test the White move. In the position of the diagram (move 55), there is one move that guarantees the white pieces to win in the next turn, no matter what happens. ''' ''' b = board.BoardState() b.initialize_from_file("../data/test_end.json") res = IA.calculate_move(b) b.print_board() print(res) ''' ''' Test the Black move. In the position of the diagram (move 75) the black pieces can capture the white one or two white stones. At the same time, the king is quite close to arrive to one of the corners. This test allows us to tune the values of the policy. ''' b2 = board.BoardState() b2.initialize_from_file("../data/test_end_black.json") res = IA.calculate_move(b2) b2.print_board() print(res)
def save_all(self, individuals_amount, steps_amount, rounds_amount, mutation_amount, stop_breeding, fast, slow): #self.individuals_per_era(individuals_amount) #self.steps(steps_amount) #self.rounds(rounds_amount) #self.mutation(mutation_amount) if slow == 1: process_option = 'Slow' else: process_option = 'Fast' self.ia = ia.IA(self.maze, int(individuals_amount), int(steps_amount), int(rounds_amount), float(mutation_amount), int(stop_breeding), process_option)
def initialize(self, data): self.game_id = data.get('gameUID', None) self.game = data.get('game', None) self.description = data.get('description', None) try: self.game_config = data['gameConfig'] if self.game_config['AIDifficulty'] == "Soft": self.strategy = soft_strategy.SoftStrategy() elif self.game_config['AIDifficulty'] == "Medium": self.strategy = medium_strategy.SoftStrategy() else: self.strategy = hard_strategy.HardStrategy() except Exception: raise Exception self.IA = ia.IA(self.strategy) self.board_state = board.BoardState() self.board_state.initialize(data) self.is_initialized = True
def __init__(self): self.board = Board() self.winner = None self.IA = ia.IA() self._actual_player = PIECES['PLAYER']
def set_ia(self, near, spontaneous): self.ia = ia.IA(self, near, spontaneous)
Pour marc :9 Indiquer dans la fenetre à qui c'est le tour La fonction board.conquerir doit renvoyer le nombre de pion retourne La deco inutile à faire : Mini animation pour indiquer le dernier pion posé : colorer ses rebord de la couleur NEW_COLOR_PIECES, à ajouter dans les constantes Ajouter les 4 points noirs sur le plateau. Ajouter un menu très basique=>nouvelle class est nouveau fichier .py Pour dossier : expliquer demarche dans cahier de bord Faire mini schema des heritage de classe """ if __name__=="__main__": #Ceci est exécuté uniquement si le fichier est exécuté directement et non depuis un autre fichier. fenetre=Window(taille=[800,800],set=False,fullscreen=False) #Crée une fenêtre. developpeur1=Developpeur() developpeur2=Developpeur() humain=Humain() #Crée un humain. machine1=ia.IA() #Crée une intelligence artificielle. machine2=ia2.IA() machine3=ia2.IA() bruteforce=BruteForce(level=3) #Crée une machine utilisant la force de calcul de la machine, cela est utile pour les tests de niveau des nouvelles intelligences artificielles. jeu=Othello(joueurs=[humain,bruteforce],fenetre=fenetre) #Crée un jeu. jeu() #Lance le jeu.
def test_an_ia_play_in_order(self): ia1 = ia.IA('X') grid = empty_grid() self.assertEqual([0, 0], ia1.play(grid)) grid[0][0] = 'X' self.assertEqual([1, 0], ia1.play(grid))
def test_an_ia_can_play(self): ia1 = ia.IA('X') self.assertEqual([0, 0], ia1.play(empty_grid()))
import Queue import random import os import time import game import ia #/** #* Metodo Main do programa. Onde e gerado um tabuleiro #* aleatorio com a IA e entao utilizada-se da IA com o #* metodo de busca em profundidade ate que seja #* posicionadas as 8 rainhas. #*/ if __name__ == "__main__": start_time = time.time() ia = ia.IA() os.system("clear") print '\t8 Queens' print '\n Busca em Profundidade' print '\n\tFirst Board \n', ia.get_principal() end = "Unsolved" ia.generate_child(ia.get_principal()) while end != "Solved": node = ia.get_queue() a = node.get_queens() if a == 8: end = "Solved" Solution = node.get_board() break else:
def place_cars(self): ''' @brief Situa a todos los jugadores tras la linea de salida ''' rivals = config.Config().get_competitors() player = config.Config().get_player() #Si hemos indicado que la posición es vertical if self.orientation == 'vertical': #Obtenemos una superfice con el ancho de la "carretera" del #circuito como referencia #Situamos al coche según el angulo indicado #A la izquierda de la linea if self.car_angle == 0: #Cuarto self.game_control.add_player( playercar.PlayerCar( self.game_control, player, self.x - self.circuit.get_tile_width() * 3 - 45, self.y + self.circuit.get_tile_height() * 3, 0)) #Primero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[0], self.x - self.circuit.get_tile_width(), self.y + self.circuit.get_tile_height() * 2, 0)) #Segundo self.game_control.add_ia_car( ia.IA(self.game_control, rivals[1], self.x - self.circuit.get_tile_width() - 45, self.y + self.circuit.get_tile_height() * 3, 0)) #Tercero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[2], self.x - self.circuit.get_tile_width() * 3, self.y + self.circuit.get_tile_height() * 2, 0)) #A la derecha de la linea elif self.car_angle == 180: #Cuarto self.game_control.add_player( playercar.PlayerCar( self.game_control, player, self.x + self.circuit.get_tile_width() * 4 + 45, self.y + self.circuit.get_tile_height() * 2, 180)) #Primero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[0], self.x + self.circuit.get_tile_width() * 2, self.y + self.circuit.get_tile_height() * 3, 180)) #Segundo self.game_control.add_ia_car( ia.IA(self.game_control, rivals[1], self.x + self.circuit.get_tile_width() * 2 + 45, self.y + self.circuit.get_tile_height() * 2, 180)) #Tercero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[2], self.x + self.circuit.get_tile_width() * 4, self.y + self.circuit.get_tile_height() * 3, 180)) #Si por el contrario la posición es horizontal else: #Creamos una superficie con el alto de la carretera del circuito #como referencia #Situamos el coche en el angulo adecuado #Debajo de la linea if self.car_angle == 90: #Cuarto self.game_control.add_player( playercar.PlayerCar( self.game_control, player, self.x + self.circuit.get_tile_width() * 3, self.y - self.circuit.get_tile_height() * 4 - 45, 90)) #Primero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[0], self.x + self.circuit.get_tile_width() * 2, self.y - self.circuit.get_tile_height(), 90)) #Segundo self.game_control.add_ia_car( ia.IA(self.game_control, rivals[1], self.x + self.circuit.get_tile_width() * 3, self.y - self.circuit.get_tile_height() - 45, 90)) #Tercero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[2], self.x + self.circuit.get_tile_width() * 2, self.y - self.circuit.get_tile_height() * 4, 90)) #Arriba de la linea elif self.car_angle == 270: #Cuarto self.game_control.add_player( playercar.PlayerCar( self.game_control, player, self.x + self.circuit.get_tile_width() * 3, self.y + self.circuit.get_tile_height() * 4 + 45, 270)) #Primero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[2], self.x + self.circuit.get_tile_width() * 2, self.y + self.circuit.get_tile_height() * 2, 270)) #Segundo self.game_control.add_ia_car( ia.IA(self.game_control, rivals[0], self.x + self.circuit.get_tile_width() * 3, self.y + self.circuit.get_tile_height() * 2 + 45, 270)) #Tercero self.game_control.add_ia_car( ia.IA(self.game_control, rivals[1], self.x + self.circuit.get_tile_width() * 2, self.y + self.circuit.get_tile_height() * 4, 270))