def change_side(self): self.canvas.delete("all") self.side = ((self.side - 1) % 3) + 2 print(self.side) self.morpion = mp.Morpion(self.dim, self.side) self.canvas.config(width=self.width(), height=self.height()) self.canvas.pack() self.initialize()
def __init__(self, parent): self.morpion = mp.Morpion(self.dim, self.side) self.active_cell = None # the cell clicked by the player self.number_of_players = 0 # the computer plays again itself # graphical elements self.frame = tk.Frame(parent) self.frame.pack() self.buttonPanel = tk.Frame(self.frame) self.buttonPanel.pack() self.button1 = tk.Button(self.buttonPanel, text="resume", background="red", command=self.resume) self.button1.pack(side=tk.LEFT) self.button2 = tk.Button(self.buttonPanel, text="dimension", background="red", command=self.change_dimension) self.button2.pack(side=tk.LEFT) self.button3 = tk.Button(self.buttonPanel, text="side", background="red", command=self.change_side) self.button3.pack(side=tk.LEFT) self.button4 = tk.Button(self.buttonPanel, text="players", background="red", command=self.change_players) self.button4.pack(side=tk.LEFT) self.label = tk.Label(self.buttonPanel, text=self.number_of_players) self.label.pack(side=tk.LEFT) self.canvas = tk.Canvas(self.frame, width=self.width(), height=self.height(), bg="blue") self.canvas.bind("<Button-1>", self.callback) self.canvas.pack(side=tk.TOP) self.initialize() self.change_players()
def change_players(self): self.number_of_players = (self.number_of_players + 1) % 3 if self.number_of_players == 0: self.player1 = Player(self, "CPU") self.player2 = Player(self, "CPU") elif self.number_of_players == 1: self.player1 = Player(self, "human") self.player2 = Player(self, "CPU") elif self.number_of_players == 2: self.player1 = Player(self, "human") self.player2 = Player(self, "human") self.label.configure(text=str(self.number_of_players)) self.canvas.delete("all") self.morpion = mp.Morpion(self.dim, self.side) self.canvas.config(width=self.width(), height=self.height()) self.canvas.pack() self.initialize()
def simulation(m=10,side=3,dim=2): n = side**dim X = np.zeros(shape=(0,n)) y = np.zeros(shape=(0,1)) # play until it gets m features while(True): mo = mp.Morpion(dim,side) mo.initialize_board() while(True): mo.play_random() if mo.is_game_over: break if not mo.who_is_winner()=="": [X_1,y_1] = get_features_label(mo) X = np.vstack((X,X_1)) y = np.vstack((y,y_1)) if X.shape[0]>m : break # returns exactly m features return X[:m,:],y[:m]
scores = model.evaluate(X, Y, verbose=1) print("Accuracy (training): %.2f%%" % (scores[1]*100)) scores = model.evaluate(X_val, Y_val, verbose=1) print("Accuracy (validation): %.2f%%" % (scores[1]*100)) # # nombre_parties=1000 playerX="AI" # random or AI playerO="random" countX = 0 # games won by X countO = 0 # games won by O morp = mp.Morpion(dim=dim,side=side) morp.starter =1 for games in range(nombre_parties): # morp.starter = 1 # the cross starts morp.initialize_board() morp.starter = 1 # the cross starts while True: player = morp.who_is_playing() if player == "X": if playerX == "random" : morp.play_random() elif playerX == "AI" : playAI(morp,model)
#!E:/Python27/python.exe #-*- coding: UTF-8 -*- import morpion while (True): theMorpion = morpion.Morpion() while (theMorpion.run): theMorpion.play() raw_input()
def resume(self): self.morpion = mp.Morpion(self.dim, self.side) self.initialize() self.active_cell = None self.draw_board()
def change_dimension(self): self.dim = ((self.dim - 1) % 3) + 2 self.morpion = mp.Morpion(self.dim, self.side) self.canvas.config(width=self.width(), height=self.height()) self.canvas.pack() self.initialize()