예제 #1
0
	def quick_evaluation(self,color):
		if color==2:
			answer=self.play_white()
		else:
			answer=self.play_black()
		
		all_moves=self.get_all_leela_zero_moves()
		print all_moves[0]
		for e in all_moves[0]:
			print "\t",e
		if answer.lower()=="pass":
			self.undo()
			return _("That game is won")
		elif answer.lower()=="resign":
			self.undo_resign()
			return _("That game is lost")
		else:
			self.undo()
			sequence_first_move,one_sequence,one_value_network,one_policy_network,one_nodes = all_moves[0]
			if color==1:
				black_win_rate=str(one_value_network)+'%'
				white_win_rate=str(100-one_value_network)+'%'
			else:
				black_win_rate=str(100-one_value_network)+'%'
				white_win_rate=str(one_value_network)+'%'
			return _("black/white win probability for this variation: ")+black_win_rate+'/'+white_win_rate
예제 #2
0
    def save(self):
        bot = self.name
        log("Saving " + bot + " settings")
        Config = configparser.ConfigParser()
        Config.read(config_file)

        Config.set(bot, "SlowCommand", self.SlowCommand.get())
        Config.set(bot, "SlowParameters", self.SlowParameters.get())
        Config.set(bot, "SlowTimePerMove", self.SlowTimePerMove.get())
        Config.set(bot, "FastCommand", self.FastCommand.get())
        Config.set(bot, "FastParameters", self.FastParameters.get())
        Config.set(bot, "FastTimePerMove", self.FastTimePerMove.get())

        value = {
            _("Slow profile"): "slow",
            _("Fast profile"): "fast",
            _("Both profiles"): "both",
            _("None"): "none"
        }

        Config.set(bot, "AnalysisBot", value[self.analysis_bot.get()])
        Config.set(bot, "LiveanalysisBot", value[self.liveanalysis_bot.get()])
        Config.set(bot, "LivePlayerBot", value[self.liveplayer_bot.get()])
        Config.set(bot, "ReviewBot", value[self.review_bot.get()])

        Config.write(open(config_file, "w"))
예제 #3
0
    def save(self):
        log("Saving GnuGo settings")
        Config = ConfigParser.ConfigParser()
        Config.read(config_file)

        bot = "GnuGo"

        Config.set(bot, "SlowCommand", self.SlowCommand.get())
        Config.set(bot, "SlowParameters", self.SlowParameters.get())
        Config.set(bot, "Variations", self.Variations.get())
        Config.set(bot, "Deepness", self.Deepness.get())
        Config.set(bot, "FastCommand", self.FastCommand.get())
        Config.set(bot, "FastParameters", self.FastParameters.get())

        value = {
            _("Slow profile"): "slow",
            _("Fast profile"): "fast",
            _("Both profiles"): "both",
            _("None"): "none"
        }

        Config.set(bot, "AnalysisBot", value[self.analysis_bot.get()])
        Config.set(bot, "LiveanalysisBot", value[self.liveanalysis_bot.get()])
        Config.set(bot, "LivePlayerBot", value[self.liveplayer_bot.get()])
        Config.set(bot, "ReviewBot", value[self.review_bot.get()])

        Config.write(open(config_file, "w"))
예제 #4
0
	def update_black_white_options(self):
		i=self.selected_black_index()
		self.black_options=[_("Human"),_("Bot used for analysis")+" ("+self.bot_selection.get()+")"]+self.bots_names
		self.black_menu.pack_forget()
		self.black_menu=apply(OptionMenu,(self.black_selection_wrapper,self.black_selection)+tuple(self.black_options))
		self.black_menu.pack()
		self.black_selection.set(self.black_options[i])

		j=self.selected_white_index()
		self.white_options=[_("Human"),_("Bot used for analysis")+" ("+self.bot_selection.get()+")"]+self.bots_names
		self.white_menu.pack_forget()
		self.white_menu=apply(OptionMenu,(self.white_selection_wrapper,self.white_selection)+tuple(self.white_options))
		self.white_menu.pack()
		self.white_selection.set(self.white_options[j])
		
		if i==1:
			black=self.bot_selection.get()
		else:
			black=self.black_selection.get()
			
		if j==1:
			white=self.bot_selection.get()
		else:
			white=self.white_selection.get()
			
		self.filename.delete(0, END)
		filename=datetime.now().strftime('%Y-%m-%d_%H:%M_'+black+'_vs_'+white+'.sgf')
		self.filename.insert(0, filename)
예제 #5
0
    def save(self):
        bot = self.name
        log("Saving " + bot + " settings")

        grp_config.set(bot, "SlowCommand", self.SlowCommand.get())
        grp_config.set(bot, "SlowParameters", self.SlowParameters.get())
        grp_config.set(bot, "SlowTimePerMove", self.SlowTimePerMove.get())
        grp_config.set(bot, "FastCommand", self.FastCommand.get())
        grp_config.set(bot, "FastParameters", self.FastParameters.get())
        grp_config.set(bot, "FastTimePerMove", self.FastTimePerMove.get())

        value = {
            _("Slow profile"): "slow",
            _("Fast profile"): "fast",
            _("Both profiles"): "both",
            _("None"): "none"
        }

        grp_config.set(bot, "AnalysisBot", value[self.analysis_bot.get()])
        grp_config.set(bot, "LiveanalysisBot",
                       value[self.liveanalysis_bot.get()])
        grp_config.set(bot, "LivePlayerBot", value[self.liveplayer_bot.get()])
        grp_config.set(bot, "ReviewBot", value[self.review_bot.get()])

        if self.parent.parent.refresh != None:
            self.parent.parent.refresh()
예제 #6
0
    def save(self):
        log("Saving GnuGo settings")

        bot = "GnuGo"

        grp_config.set(bot, "SlowCommand", self.SlowCommand.get())
        grp_config.set(bot, "SlowParameters", self.SlowParameters.get())
        grp_config.set(bot, "Variations", self.Variations.get())
        grp_config.set(bot, "Deepness", self.Deepness.get())
        grp_config.set(bot, "FastCommand", self.FastCommand.get())
        grp_config.set(bot, "FastParameters", self.FastParameters.get())

        value = {
            _("Slow profile"): "slow",
            _("Fast profile"): "fast",
            _("Both profiles"): "both",
            _("None"): "none"
        }

        grp_config.set(bot, "AnalysisBot", value[self.analysis_bot.get()])
        grp_config.set(bot, "LiveanalysisBot",
                       value[self.liveanalysis_bot.get()])
        grp_config.set(bot, "LivePlayerBot", value[self.liveplayer_bot.get()])
        grp_config.set(bot, "ReviewBot", value[self.review_bot.get()])

        if self.parent.parent.refresh != None:
            self.parent.parent.refresh()
예제 #7
0
	def quick_evaluation(self,color):
		if color==2:
			answer=self.play_white()
		else:
			answer=self.play_black()
		
		position_evaluation=self.get_all_leela_moves()

		if answer.lower()=="pass":
			self.undo()
		elif answer.lower()=="resign":
			self.undo_resign()
		else:
			self.undo()
		txt=""
		try:
			if color==1:
				black_win_rate=position_evaluation["variations"][0]["win rate"]
				white_win_rate=opposite_rate(black_win_rate)
			else:
				white_win_rate=position_evaluation["variations"][0]["win rate"]
				black_win_rate=opposite_rate(white_win_rate)
			txt+= _("black/white win probability for this variation: ")+black_win_rate+'/'+white_win_rate
			txt+="\n\n"+_("Score estimation for this variation: %s")%self.get_leela_final_score()
		except:
			txt+=_("Score estimation for this variation: %s")%self.get_leela_final_score()

		return txt
	def save(self):
		global lang, translations
		log("Saving GRP settings")
		for lang2, language in available_translations.iteritems():
			if language==self.Language.get():
				if lang!=lang2:
					grp_config.set("General","Language",lang2)
				break
		grp_config.set("Review","FuzzyStonePlacement",self.FuzzyStonePlacement.get())
		grp_config.set("Review","RealGameSequenceDeepness",self.RealGameSequenceDeepness.get())
		#grp_config.set("Review","GobanScreenRatio",self.GobanScreenRatio.get())
		grp_config.set("Analysis","MaxVariations",self.MaxVariationsToRecord.get())
		grp_config.set("Analysis","SaveCommandLine",self.SaveCommandLine.get())
		grp_config.set("Analysis","StopAtFirstResign",self.StopAtFirstResign.get())
		grp_config.set("Review","MaxVariations",self.MaxVariationsToDisplay.get())
		coloring={_("Win rate > 50% in blue"):"blue_for_winning",_("The best variation in blue"):"blue_for_best",_("Variations better than actual game move in blue"):"blue_for_better"}
		grp_config.set("Review","VariationsColoring",coloring[self.VariationsColoring.get()])
		grp_config.set("Review","InvertedMouseWheel",self.InvertedMouseWheel.get())
		grp_config.set("Analysis","NoVariationIfSameMove",self.NoVariationIfSameMove.get())
		labeling={_("Letters"):"letter",_("Percentages"):"rate"}
		grp_config.set("Review","VariationsLabel",labeling[self.VariationsLabel.get()])
		
		
		
		if self.refresh!=None:
			self.refresh()
예제 #9
0
    def save(self):
        log("Saving Ray settings")
        Config = ConfigParser.ConfigParser()
        Config.read(config_file)

        bot = "Ray"

        Config.set(bot, "SlowCommand", self.SlowCommand.get())
        Config.set(bot, "SlowParameters", self.SlowParameters.get())
        Config.set(bot, "FastCommand", self.FastCommand.get())
        Config.set(bot, "FastParameters", self.FastParameters.get())

        value = {
            _("Slow profile"): "slow",
            _("Fast profile"): "fast",
            _("Both profiles"): "both",
            _("None"): "none"
        }

        Config.set(bot, "AnalysisBot", value[self.analysis_bot.get()])
        Config.set(bot, "LiveanalysisBot", value[self.liveanalysis_bot.get()])
        Config.set(bot, "LivePlayerBot", value[self.liveplayer_bot.get()])
        Config.set(bot, "ReviewBot", value[self.review_bot.get()])

        Config.write(open(config_file, "w"))

        if self.parent.parent.refresh != None:
            self.parent.parent.refresh()
예제 #10
0
    def click_button(self, bot):
        dim = self.dim
        self.display_queue.put(3)
        self.display_queue.put(2)
        color = self.next_color
        move = bot.click(color)

        if move not in ["PASS", "RESIGN"]:
            i, j = gtp2ij(move)

            self.history.append(
                [copy(self.grid),
                 copy(self.markup), (move, color)])

            place(self.grid, i, j, color)
            self.display_queue.put((i, j))

            self.grid[i][j] = color
            self.markup = [["" for r in range(dim)] for c in range(dim)]
            self.markup[i][j] = 0
            self.next_color = 3 - color
        else:
            bot.undo()
            if color == 1:
                self.display_queue.put(bot.name + " (" + _("Black") + "): " +
                                       move)
            else:
                self.display_queue.put(bot.name + " (" + _("White") + "): " +
                                       move)

            self.do_nothing()
            return

        if self.white_autoplay and self.black_autoplay:
            if move not in ["PASS", "RESIGN"]:
                log("SELF PLAY")
                self.display_queue.put(2)
                one_thread = threading.Thread(
                    target=self.click_button,
                    args=(self.menu_bots[self.selected_bot.get()], ))
                self.after(0, one_thread.start)
                return
            else:
                log("End of SELF PLAY")
                self.display_queue.put(4)
                self.display_queue.put(1)
                self.do_nothing()

                return
        else:
            self.display_queue.put(4)
            self.display_queue.put(1)
            return
예제 #11
0
	def start(self):
		#bots={bot['name']:bot for bot in bots_for_analysis}
		#analyser=bots[self.bot_selection.get()]
		value={"slow":" (%s)"%_("Slow profile"),"fast":" (%s)"%_("Fast profile")}
		bots={bot['name']+value[bot['profile']]:bot for bot in get_available("LiveAnalysisBot")}
		analyser=bots[self.bot_selection.get()]
		
		bots={bot['name']+value[bot['profile']]:bot for bot in get_available("LivePlayerBot")}
		
		b=self.selected_black_index()
		if b==0:
			black="human"
		elif b==1:
			black="analyser"
		else:
			print "=========="
			print bots.keys()
			print "=========="
			black=bots[self.black_selection.get()]
		
		w=self.selected_white_index()
		if w==0:
			white="human"
		elif w==1:
			white="analyser"
		elif w==b:
			white="black"
		else:
			white=bots[self.white_selection.get()]
		
		Config = ConfigParser.ConfigParser()
		Config.read(config_file)
		
		komi=float(self.komi.get())
		dim=int(self.dim.get())
		handicap=int(self.handicap.get())
		
		Config.set("Live","komi",komi)
		Config.set("Live","size",dim)
		Config.set("Live","handicap",handicap)
		
		Config.set("Live","analyser",self.bot_selection.get().encode("utf"))
		Config.set("Live","black",self.black_selection.get().encode("utf"))
		Config.set("Live","white",self.white_selection.get().encode("utf"))
		
		Config.write(open(config_file,"w"))
		 
		filename=os.path.join(Config.get("General","livefolder"),self.filename.get())
		self.withdraw()
		popup=LiveAnalysis(self.parent,analyser,black,white,dim=dim,komi=komi,handicap=handicap,filename=filename,overlap_thinking=not self.no_overlap_thinking.get(),color=self.color.get())
		self.parent.add_popup(popup)
		self.close()
예제 #12
0
	def pause(self):
		if self.pause_button.cget("relief")!=SUNKEN:
			log("Pausing the game")
			self.pause_button.config(relief=SUNKEN)
			self.pause_button.config(text=_("Resume"))
			self.pause_lock.acquire()
			log("Game paused")
		else:
			log("Resuming the game")
			self.pause_button.config(relief=RAISED)
			self.pause_button.config(text=_("Pause"))
			self.pause_lock.release()
			log("Game resumed")
예제 #13
0
    def quick_evaluation(self, color):
        if color == 2:
            answer = self.play_white()
        else:
            answer = self.play_black()

        all_moves = self.get_all_aq_moves()

        if answer.lower() == "pass":
            self.undo()
        elif answer.lower() == "resign":
            self.undo_resign()
        else:
            self.undo()

        txt = ""
        try:
            if color == 1:
                black_win_rate = str(all_moves[0][2]) + "%"
                white_win_rate = opposite_rate(black_win_rate)
            else:
                white_win_rate = str(all_moves[0][2]) + "%"
                black_win_rate = opposite_rate(white_win_rate)
            txt += _(
                "Value network black/white win probability for this variation: %s"
            ) % (black_win_rate + '/' + white_win_rate)
        except:
            pass

        return txt
예제 #14
0
    def display_settings(self):
        if self.setting_frame:
            self.setting_frame.pack_forget()

        settings_dict = {
            "GRP": self.display_GRP_settings,
            "AQ": AQSettings,
            "GnuGo": GnuGoSettings,
            "Leela": LeelaSettings,
            "Ray": RaySettings,
            "Leela Zero": LeelaZeroSettings
        }

        self.setting_frame = Frame(self.right_column)
        self.setting_frame.parent = self
        key = self.setting_mode.get()
        new_settings = settings_dict[key](self.setting_frame)
        new_settings.grid(row=0, column=0, padx=5, pady=5)
        self.current_settings = new_settings
        Button(self.setting_frame,
               text=_("Save settings"),
               command=new_settings.save).grid(row=1,
                                               column=0,
                                               padx=5,
                                               pady=5,
                                               sticky=W)

        self.setting_frame.pack()
        self.focus()
예제 #15
0
	def update_overlap_thinking_option(self):
		i=self.selected_black_index()
		j=self.selected_white_index()
		if i<=1 and j<=1:
			nb_bots=1
		elif (i>1 and j<=1) or (j>1 and i<=1):
			nb_bots=2
		elif (i>1 and j>1 and i==j):
			nb_bots=2
		elif (i>1 and j>1 and i!=j):
			nb_bots=3
		
		for widget in self.overlap_thinking_widgets:
				widget.grid_forget()
		self.overlap_thinking_widgets=[]
		
		if nb_bots>1:
			row=0
			widget=Label(self.overlap_thinking_wrapper,text="")
			widget.grid(row=row,column=1)
			self.overlap_thinking_widgets.append(widget)
			
			row+=1
			widget=Label(self.overlap_thinking_wrapper,text=_("No overlap thinking time"))
			widget.grid(row=row,column=1,sticky=W)
			self.overlap_thinking_widgets.append(widget)
			
			widget=Checkbutton(self.overlap_thinking_wrapper, text="", variable=self.no_overlap_thinking,onvalue=True,offvalue=False)
			widget.grid(row=row,column=2,sticky=W)
			self.overlap_thinking_widgets.append(widget)
예제 #16
0
	def remove_bot(self,bot):
		self.bots_menubutton.menu.delete(bot)
		self.actions_menubutton.config(state="disabled")
		del self.menu_bots[bot]
		if len(self.menu_bots)==0:
			self.bots_menubutton.config(state="disabled")
		self.current_bot=_("No bot")
예제 #17
0
	def close(self):
		log("Closing analyser bot")
		self.game_label.config(text=_("Now closing, please wait"))
		self.analysis_label.config(text=_("Now closing, please wait"))
		self.analyser.update_queue.put(None)
		if type(self.black)!=type("abc"):
			log("Closing black bot")
			self.black.close()
		if type(self.white)!=type("abc"):
			log("Closing white bot")
			self.white.close()
		
		self.analyser.bot.close()

		
		self.popup.destroy()
예제 #18
0
	def __init__(self,parent,bot_gtp,bot_command_line):
		Toplevel.__init__(self,parent)
		self.parent=parent
		self.protocol("WM_DELETE_WINDOW", self.close)
		try:
			self.bot=bot_gtp(bot_command_line)
		except Exception, e:
			show_error(_("Could not run the program:")+"\n"+str(e),self.parent)
예제 #19
0
	def close(self):
		log("Closing analyser bot")
		self.game_label.config(text=_("Now closing, please wait"))
		self.analysis_label.config(text=_("Now closing, please wait"))
		log("Sending None msg to analyser")
		self.analyser.update_queue.put((0,None))
		if type(self.black)!=type("abc"):
			log("Closing black bot")
			self.black.close()
		if type(self.white)!=type("abc"):
			log("Closing white bot")
			self.white.close()
		
		self.analyser.bot.close()

		self.destroy()
		self.parent.remove_popup(self)
예제 #20
0
	def undo(self):
		log("Let's wait for the analyser to stop")
		self.analyser.cpu_lock.acquire()
		log("Analyser is now stopped")
		log("Adding a new branch to the SGF tree")
		self.g.lock.acquire()
		new_branch=self.latest_node.parent.parent.parent.new_child(0)
		self.g.lock.release()
		
		move2undo=self.current_move-2
		
		log("Let's clean the analyser update_queue from requests for moves following move",move2undo)
		nb_request=self.analyser.update_queue.qsize()
		requests=[]
		for r in range(nb_request):
			priority,msg=self.analyser.update_queue.get()
			if type(msg)==type(123):
				if msg<=move2undo:
					log("keeping",(priority,msg))
					requests.append((priority,msg))
					#self.analyser.update_queue.put((priority,msg))
				else:
					log("discarding",(priority,msg))
			else:
				log("keeping",(priority,msg))
				requests.append((priority,msg))
		for r in requests:
			self.analyser.update_queue.put(r)
		
		log("Sending a priority request to undo move",move2undo,"and beyong to analyser")
		msg1=(1./move2undo,"undo "+str(move2undo))
		self.analyser.update_queue.put(msg1)
		log("Releasing the analyser")
		self.analyser.cpu_lock.release()
		
		self.latest_node=new_branch
		if type(self.black)!=type("abc"):
			#black is a bot
			self.black.undo()
			self.black.undo()
		if type(self.white)!=type("abc"):
			#white is a bot
			self.white.undo()
			self.white.undo()
		self.history.pop()
		self.grid,self.markup=self.history.pop()
		self.current_move-=2
		self.game_label.config(text=_("Currently at move %i")%self.current_move)
		write_rsgf(self.rsgf_filename,self.g)
		
		log("waiting for echo")
		t0=time.time()
		msg2=None
		while msg2!=msg1:
			msg2=self.analyser.best_moves_queue.get()
			log("...............",msg2)
		log("echo received after",time.time()-t0,"s")
		self.parent.after(10,self.after_undo) #enough time for analyser to grab the process lock and process the queue
예제 #21
0
	def __init__(self,parent):
		Frame.__init__(self,parent)
		self.parent=parent
		log("Initializing Ray setting interface")
		
		bot="Ray"
		
		row=0
		Label(self,text=_("%s settings")%bot, font="-weight bold").grid(row=row,column=1,sticky=W)
		row+=1
		Label(self,text="").grid(row=row,column=1)
		
		row+=1
		Label(self,text=_("Slow profile parameters")).grid(row=row,column=1,sticky=W)
		row+=1
		Label(self,text=_("Command")).grid(row=row,column=1,sticky=W)
		SlowCommand = StringVar() 
		SlowCommand.set(grp_config.get(bot,"SlowCommand"))
		Entry(self, textvariable=SlowCommand, width=30).grid(row=row,column=2)
		row+=1
		Label(self,text=_("Parameters")).grid(row=row,column=1,sticky=W)
		SlowParameters = StringVar() 
		SlowParameters.set(grp_config.get(bot,"SlowParameters"))
		Entry(self, textvariable=SlowParameters, width=30).grid(row=row,column=2)
		row+=1
		Button(self, text=_("Test"),command=lambda: self.parent.parent.test(Ray_gtp,"slow")).grid(row=row,column=1,sticky=W)
		
		row+=1
		Label(self,text="").grid(row=row,column=1)
		row+=1
		Label(self,text=_("Fast profile parameters")).grid(row=row,column=1,sticky=W)
		row+=1
		
		row+=1
		Label(self,text=_("Command")).grid(row=row,column=1,sticky=W)
		FastCommand = StringVar() 
		FastCommand.set(grp_config.get(bot,"FastCommand"))
		Entry(self, textvariable=FastCommand, width=30).grid(row=row,column=2)
		row+=1
		Label(self,text=_("Parameters")).grid(row=row,column=1,sticky=W)
		FastParameters = StringVar() 
		FastParameters.set(grp_config.get(bot,"FastParameters"))
		Entry(self, textvariable=FastParameters, width=30).grid(row=row,column=2)
		row+=1
		Button(self, text=_("Test"),command=lambda: self.parent.parent.test(Ray_gtp,"fast")).grid(row=row,column=1,sticky=W)

		self.SlowCommand=SlowCommand
		self.SlowParameters=SlowParameters
		self.FastCommand=FastCommand
		self.FastParameters=FastParameters
예제 #22
0
	def click(self,event):
		if self.locked:
			return
		dim=self.dim
		#add/remove black stone
		#check pointer location
		i,j=self.goban.xy2ij(event.x,event.y)
		color=self.next_color
		if 0 <= i <= dim-1 and 0 <= j <= dim-1:
			#inside the grid
			#what is under the pointer ?
			
			if self.grid[i][j] not in (1,2):
				#nothing, so we add a stone			
	
				self.history.append([copy(self.grid),copy(self.markup)])
				
				place(self.grid,i,j,color)
				self.grid[i][j]=color
				
				self.markup=[["" for r in range(dim)] for c in range(dim)]
				self.markup[i][j]=0
					
				self.goban.display(self.grid,self.markup)
				if color==1:
					self.goban.black_stones[i][j].shine()
				else:
					self.goban.white_stones[i][j].shine()
				self.stone_sound()
				self.next_color=3-color
				
				self.g.lock.acquire()
				node = self.latest_node
				if color==1:
					node_set(node,"b", (i,j))
				else:
					node_set(node,"w", (i,j))
				self.g.lock.release()
				
				
				self.current_move+=1
				self.game_label.config(text=_("Currently at move %i")%self.current_move)
				
				if self.next_color==1:
					self.white_just_passed=False
					if type(self.black)!=type("abc"):
						#black is a bot
						log("Asking black (%s) to play the game move"%self.black.bot_name)
						self.black.place_white(ij2gtp((i,j)))
					self.black_to_play()
				else:
					self.black_just_passed=False
					if type(self.white)!=type("abc"):
						#white is a bot
						log("Asking white (%s) to play the game move"%self.white.bot_name)
						self.white.place_black(ij2gtp((i,j)))
					self.white_to_play()
예제 #23
0
 def r2sgf(self):
     filename = open_rsgf_file(parent=self.parent)
     if not filename:
         return
     rsgf2sgf(filename)
     show_info(
         _("The file %s as been converted to %s") %
         (os.path.basename(filename), os.path.basename(filename) + ".sgf"),
         parent=self.parent)
예제 #24
0
	def __init__(self,parent,bot="GnuGo"):
		Frame.__init__(self,parent)
		self.parent=parent
		self.bot=bot
		self.profiles=get_bot_profiles(bot,False)
		profiles_frame=self
		
		self.listbox = Listbox(profiles_frame)
		self.listbox.grid(column=10,row=10,rowspan=10)
		self.update_listbox()
		
		row=10
		Label(profiles_frame,text=_("Profile")).grid(row=row,column=11,sticky=W)
		self.profile = StringVar()
		Entry(profiles_frame, textvariable=self.profile, width=30).grid(row=row,column=12)

		row+=1
		Label(profiles_frame,text=_("Command")).grid(row=row,column=11,sticky=W)
		self.command = StringVar() 
		Entry(profiles_frame, textvariable=self.command, width=30).grid(row=row,column=12)
		
		row+=1
		Label(profiles_frame,text=_("Parameters")).grid(row=row,column=11,sticky=W)
		self.parameters = StringVar()
		Entry(profiles_frame, textvariable=self.parameters, width=30).grid(row=row,column=12)

		row+=1
		Label(profiles_frame,text=_("Maximum number of variations")).grid(row=row,column=11,sticky=W)
		self.variations = StringVar()
		Entry(profiles_frame, textvariable=self.variations, width=30).grid(row=row,column=12)
		
		row+=1
		Label(profiles_frame,text=_("Deepness for each variation")).grid(row=row,column=11,sticky=W)
		self.deepness = StringVar()
		Entry(profiles_frame, textvariable=self.deepness, width=30).grid(row=row,column=12)
		

		row+=10
		buttons_frame=Frame(profiles_frame)
		buttons_frame.grid(row=row,column=10,sticky=W,columnspan=3)
		Button(buttons_frame, text=_("Add profile"),command=self.add_profile).grid(row=row,column=1,sticky=W)
		Button(buttons_frame, text=_("Modify profile"),command=self.modify_profile).grid(row=row,column=2,sticky=W)
		Button(buttons_frame, text=_("Delete profile"),command=self.delete_profile).grid(row=row,column=3,sticky=W)
		Button(buttons_frame, text=_("Test"),command=lambda: self.parent.parent.test(self.bot_gtp,self.command,self.parameters)).grid(row=row,column=4,sticky=W)
		self.listbox.bind("<Button-1>", lambda e: self.after(100,self.change_selection))
		
		self.index=-1
		
		self.bot_gtp=GnuGo_gtp
예제 #25
0
	def __init__(self,parent,bot="GnuGo"):
		Frame.__init__(self,parent)
		self.parent=parent
		self.bot=bot
		self.profiles=get_bot_profiles(bot,False)
		profiles_frame=self
		
		self.listbox = Listbox(profiles_frame)
		self.listbox.grid(column=10,row=10,rowspan=10)
		self.update_listbox()
		
		row=10
		Label(profiles_frame,text=_("Profile")).grid(row=row,column=11,sticky=W)
		self.profile = StringVar()
		Entry(profiles_frame, textvariable=self.profile, width=30).grid(row=row,column=12)

		row+=1
		Label(profiles_frame,text=_("Command")).grid(row=row,column=11,sticky=W)
		self.command = StringVar() 
		Entry(profiles_frame, textvariable=self.command, width=30).grid(row=row,column=12)
		
		row+=1
		Label(profiles_frame,text=_("Parameters")).grid(row=row,column=11,sticky=W)
		self.parameters = StringVar()
		Entry(profiles_frame, textvariable=self.parameters, width=30).grid(row=row,column=12)

		row+=1
		Label(profiles_frame,text=_("Maximum number of variations")).grid(row=row,column=11,sticky=W)
		self.variations = StringVar()
		Entry(profiles_frame, textvariable=self.variations, width=30).grid(row=row,column=12)
		
		row+=1
		Label(profiles_frame,text=_("Deepness for each variation")).grid(row=row,column=11,sticky=W)
		self.deepness = StringVar()
		Entry(profiles_frame, textvariable=self.deepness, width=30).grid(row=row,column=12)
		

		row+=10
		buttons_frame=Frame(profiles_frame)
		buttons_frame.grid(row=row,column=10,sticky=W,columnspan=3)
		Button(buttons_frame, text=_("Add profile"),command=self.add_profile).grid(row=row,column=1,sticky=W)
		Button(buttons_frame, text=_("Modify profile"),command=self.modify_profile).grid(row=row,column=2,sticky=W)
		Button(buttons_frame, text=_("Delete profile"),command=self.delete_profile).grid(row=row,column=3,sticky=W)
		Button(buttons_frame, text=_("Test"),command=lambda: self.parent.parent.test(self.bot_gtp,self.command,self.parameters)).grid(row=row,column=4,sticky=W)
		self.listbox.bind("<Button-1>", lambda e: self.after(100,self.change_selection))
		
		self.index=-1
		
		self.bot_gtp=GnuGo_gtp
예제 #26
0
	def __init__(self,parent,bot_gtp,bot_command_line):
		Toplevel.__init__(self,parent)
		self.parent=parent
		self.protocol("WM_DELETE_WINDOW", self.close)
		try:
			self.bot=bot_gtp(bot_command_line)
		except Exception, e:
			self.close()
			show_error(_("Could not run the program:")+"\n"+unicode(e),self.parent)
			return
예제 #27
0
	def close(self):
		log("closing tab")
		if self.current_bot!=_("No bot"):
			self.menu_bots[self.current_bot].close()
		try:
			self.display_queue.put(0, False)
		except:
			pass
		self.destroy()
		log("done")
예제 #28
0
	def change_bot(self):
		
		if self.current_bot!=_("No bot"):
			log("Bot changed from '"+self.current_bot+"' to '"+self.selected_bot.get()+"'")
			log("Terminating",self.current_bot)
			previous_bot=self.menu_bots[self.current_bot]
			previous_bot.close()
			self.current_bot=_("No bot")
		else:
			log("Bot selected:",self.selected_bot.get())
		
		if self.selected_bot.get()==_("No bot"):
			self.current_bot=_("No bot")
			self.actions_menubutton.config(state="disabled")
			return
		
		
		new_bot=self.menu_bots[self.selected_bot.get()]
		
		new_bot.start(silentfail=False)
		if not new_bot.okbot:
			self.remove_bot(self.selected_bot.get())
			self.selected_bot.set(_("No bot"))
			self.change_bot()
			return
			
		
		grp_config.set("Review", "LastBot",self.selected_bot.get() )
		
		gameroot=self.sgf.get_root()
		m=0
		for m in range(1,self.move):
			one_move=get_node(gameroot,m)
			if one_move==False:
				log("(0)leaving because one_move==False")
				break
			ij=one_move.get_move()[1]
			if one_move.get_move()[0]=='b':
				color=1
			else:
				color=2
			if not new_bot.place(ij2gtp(ij),color):
				self.remove_bot(self.current_bot)
				self.selected_bot.set(_("No bot"))
				self.change_bot()
				return
		
		
		for __,__,move in self.history:
			if not new_bot.place(move[0],move[1]):
				self.remove_bot(self.current_bot)
				self.selected_bot.set(_("No bot"))
				self.change_bot()
				return
		
		self.current_bot=self.selected_bot.get()
		self.actions_menubutton.config(state="normal")
예제 #29
0
	def __init__(self,command):
		self.c=1
		self.command_line=command[0]+" "+" ".join(command[1:])
		
		leela_zero_working_directory=command[0][:-len(ntpath.basename(command[0]))]
		command=[c.encode(sys.getfilesystemencoding()) for c in command]
		leela_zero_working_directory=leela_zero_working_directory.encode(sys.getfilesystemencoding())
		if leela_zero_working_directory:
			log("Leela Zero working directory:",leela_zero_working_directory)
			log(command)
			#self.process=subprocess.Popen(command,cwd=leela_zero_working_directory, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
			self.process=subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		else:
			self.process=subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		self.size=0
		
		self.stderr_starting_queue=Queue.Queue(maxsize=100)
		self.stderr_queue=Queue.Queue()
		self.stdout_queue=Queue.Queue()
		
		threading.Thread(target=self.consume_stderr).start()
		
		log("Checking Leela Zero stderr to check for OpenCL SGEMM tuner running")
		delay=60
		while 1:
			try:
				err_line=self.stderr_starting_queue.get(True,delay)
				
				delay=10
				if "Started OpenCL SGEMM tuner." in err_line:
					log("OpenCL SGEMM tuner is running")
					show_info(_("Leela Zero is currently running the OpenCL SGEMM tuner. It may take several minutes until Leela Zero is ready."))
					break
				elif "Loaded existing SGEMM tuning.\n" in err_line:
					log("OpenCL SGEMM tuner has already been runned")
					break
				elif "Could not open weights file" in err_line:
					show_info(err_line.strip())
					break
				elif "A network weights file is required to use the program." in err_line:
					show_info(err_line.strip())
					break
				elif "Weights file is the wrong version." in err_line:
					show_info(err_line.strip())
					break
				elif "BLAS Core:" in err_line:
					log("Could not find out, abandoning")
					break
			except:
				log("Could not find out, abandoning")
				break
		
		self.free_handicap_stones=[]
		self.history=[]
예제 #30
0
	def follow_analysis(self):
		msg=None
		try:
			msg=self.analyser.label_queue.get(False)
			if type(msg)==type(123):
				self.analysis_label.config(text=_("Currently at move %i")%msg)

			else:
				self.analysis_label.config(text=_("Waiting for next move"))
				
			if msg>2 and len(self.review_bouton_wrapper.children)==0:
				Button(self.review_bouton_wrapper,text=_("Start review"),command=self.start_review).pack(fill=X)
			
		except:
			pass
		
		if msg==None:
			self.parent.after(500,self.follow_analysis)
		else:
			self.parent.after(10,self.follow_analysis)
예제 #31
0
    def __init__(self, parent):
        Toplevel.__init__(self, parent)
        self.parent = parent

        bg = self.cget("background")

        self.popups = []

        self.control_frame = Frame(self)

        label = Label(self.control_frame,
                      text=_("This is GoReviewPartner"),
                      font="-weight bold")
        label.pack(padx=5, pady=5)

        self.analysis_bouton = Button(self.control_frame,
                                      text=_("Run a SGF file analysis"),
                                      command=self.launch_analysis)
        self.analysis_bouton.pack(fill=X, padx=5, pady=5)

        self.download_bouton = Button(
            self.control_frame,
            text=_("Download a SGF file for analysis"),
            command=self.download_sgf_for_review)
        self.download_bouton.pack(fill=X, padx=5, pady=5)

        self.live_bouton = Button(self.control_frame,
                                  text=_("Run a live analysis"),
                                  command=self.launch_live_analysis)
        self.live_bouton.pack(fill=X, padx=5, pady=5)

        review_bouton = Button(self.control_frame,
                               text=_("Open a RSGF file for review"),
                               command=self.launch_review)
        review_bouton.pack(fill=X, padx=5, pady=5)

        r2sgf_bouton = Button(self.control_frame,
                              text=_("Convert RSGF file to SGF file"),
                              command=self.r2sgf)
        r2sgf_bouton.pack(fill=X, padx=5, pady=5)

        bouton = Button(self.control_frame,
                        text=_("Settings"),
                        command=self.launch_settings)
        bouton.pack(fill=X, padx=5, pady=5)

        self.control_frame.pack(fill=X, side=BOTTOM)

        self.logo_frame = Frame(self)

        logo = Canvas(self.logo_frame, bg=bg, width=5, height=5)
        logo.pack(fill=BOTH, expand=1)
        logo.bind("<Configure>", lambda e: draw_logo(logo, e))
        self.logo_frame.pack(fill=BOTH, side=BOTTOM, expand=1)

        self.protocol("WM_DELETE_WINDOW", self.close)
예제 #32
0
class Terminal(Toplevel):
    def __init__(self, parent, bot_gtp, bot_command_line):
        Toplevel.__init__(self, parent)
        self.parent = parent
        self.protocol("WM_DELETE_WINDOW", self.close)
        try:
            self.bot = bot_gtp(bot_command_line)
        except Exception, e:
            self.close()
            show_error(
                _("Could not run the program:") + "\n" + unicode(e),
                self.parent)
            return

        threading.Thread(target=self.bot.consume_stdout).start()

        stdin_frame = Frame(self)
        stdin_frame.grid(row=1, column=1)

        self.gtp_command = StringVar()
        self.gtp_command.set("genmove black")
        entry = Entry(stdin_frame, textvariable=self.gtp_command)
        entry.grid(row=1, column=1, sticky=W)
        entry.bind("<Return>", self.send_gtp_command)

        Button(stdin_frame,
               text=_("Send GTP command"),
               command=self.send_gtp_command).grid(row=1, column=2, sticky=W)

        stdout_frame = Frame(self)
        stdout_frame.grid(row=2, column=1, sticky=N + S + E + W)
        self.stdout = Text(stdout_frame,
                           width=60,
                           height=10,
                           bg="black",
                           fg="white")
        self.stdout.pack(side="left", fill="both", expand=True)

        stderr_frame = Frame(self)
        stderr_frame.grid(row=3, column=1, sticky=N + S + E + W)
        self.stderr = Text(stderr_frame,
                           width=60,
                           height=20,
                           bg="black",
                           fg="white")
        self.stderr.pack(side="left", fill="both", expand=True)

        self.grid_columnconfigure(1, weight=1)
        self.grid_rowconfigure(2, weight=1)
        self.grid_rowconfigure(3, weight=1)

        self.follow_stdout()
        self.follow_stderr()
예제 #33
0
	def __init__(self,command):
		self.c=1
		self.command_line=command[0]+" "+" ".join(command[1:])
		
		leela_zero_working_directory=command[0][:-len(ntpath.basename(command[0]))]
		command=[c.encode(sys.getfilesystemencoding()) for c in command]
		leela_zero_working_directory=leela_zero_working_directory.encode(sys.getfilesystemencoding())
		if leela_zero_working_directory:
			log("Leela Zero working directory:",leela_zero_working_directory)
			self.process=subprocess.Popen(command,cwd=leela_zero_working_directory, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		else:
			self.process=subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		self.size=0
		
		self.stderr_starting_queue=Queue.Queue(maxsize=100)
		self.stderr_queue=Queue.Queue()
		self.stdout_queue=Queue.Queue()
		
		threading.Thread(target=self.consume_stderr).start()
		
		log("Checking Leela Zero stderr to check for OpenCL SGEMM tuner running")
		delay=60
		while 1:
			try:
				err_line=self.stderr_starting_queue.get(True,delay)
				
				delay=10
				if "Started OpenCL SGEMM tuner." in err_line:
					log("OpenCL SGEMM tuner is running")
					show_info(_("Leela Zero is currently running the OpenCL SGEMM tuner. It may take several minutes until Leela Zero is ready."))
					break
				elif "Loaded existing SGEMM tuning.\n" in err_line:
					log("OpenCL SGEMM tuner has already been runned")
					break
				elif "Could not open weights file" in err_line:
					show_info(err_line.strip())
					break
				elif "A network weights file is required to use the program." in err_line:
					show_info(err_line.strip())
					break
				elif "Weights file is the wrong version." in err_line:
					show_info(err_line.strip())
					break
				elif "BLAS Core:" in err_line:
					log("Could not find out, abandoning")
					break
			except:
				log("Could not find out, abandoning")
				break
		
		self.free_handicap_stones=[]
		self.history=[]
예제 #34
0
	def __init__(self,parent):
		Toplevel.__init__(self,parent)
		self.parent=parent
		
		bg=self.cget("background")


		self.popups=[]

		self.control_frame = Frame(self)
		
		label = Label(self.control_frame, text=_("This is GoReviewPartner"), font="-weight bold")
		label.pack(padx=5, pady=5)

		self.analysis_bouton=Button(self.control_frame, text=_("Run a SGF file analysis"), command=self.launch_analysis)
		self.analysis_bouton.pack(fill=X,padx=5, pady=5)
		
		self.download_bouton=Button(self.control_frame, text=_("Download a SGF file for analysis"), command=self.download_sgf_for_review)
		self.download_bouton.pack(fill=X,padx=5, pady=5)
		
		self.live_bouton=Button(self.control_frame, text=_("Run a live analysis"), command=self.launch_live_analysis)
		self.live_bouton.pack(fill=X,padx=5, pady=5)
		
		review_bouton=Button(self.control_frame, text=_("Open a RSGF file for review"), command=self.launch_review)
		review_bouton.pack(fill=X,padx=5, pady=5)
		
		r2sgf_bouton=Button(self.control_frame, text=_("Convert RSGF file to SGF file"), command=self.r2sgf)
		r2sgf_bouton.pack(fill=X,padx=5, pady=5)
		
		r2csv_bouton=Button(self.control_frame, text=_("Convert RSGF file to CSV file"), command=self.r2csv)
		r2csv_bouton.pack(fill=X,padx=5, pady=5)
		
		bouton=Button(self.control_frame, text=_("Settings"), command=self.launch_settings)
		bouton.pack(fill=X,padx=5, pady=5)

		self.control_frame.pack(fill=X, side=BOTTOM)
		
		self.logo_frame = Frame(self)

		logo = Canvas(self.logo_frame,bg=bg,width=5,height=5)
		logo.pack(fill=BOTH, expand=1)
		logo.bind("<Configure>",lambda e: draw_logo(logo,e))
		self.logo_frame.pack(fill=BOTH, side=BOTTOM, expand=1)

		self.protocol("WM_DELETE_WINDOW", self.close)
예제 #35
0
	def __init__(self,command):
		self.c=1
		self.command_line=command[0]+" "+" ".join(command[1:])
		command=[c.encode(sys.getfilesystemencoding()) for c in command]
		self.process=subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
		self.size=0
		
		self.stderr_starting_queue=Queue.Queue(maxsize=100)
		self.stderr_queue=Queue.Queue()
		self.stdout_queue=Queue.Queue()
		threading.Thread(target=self.consume_stderr).start()
		
		log("Checking Ray stderr to check for OpenCL SGEMM tuner running")
		delay=60
		while 1:
			try:
				err_line=self.stderr_starting_queue.get(True,delay)
				delay=10
				if "Started OpenCL SGEMM tuner." in err_line:
					log("OpenCL SGEMM tuner is running")
					show_info(_("Ray is currently running the OpenCL SGEMM tuner. It may take several minutes until Ray is ready."))
					break
				elif "Loaded existing SGEMM tuning.\n" in err_line:
					log("OpenCL SGEMM tuner has already been runned")
					break
				elif "BLAS Core:" in err_line:
					log("Could not find out, abandoning")
					break
				elif "Could not open weights file" in err_line:
					show_info(err_line.strip())
					break
				elif "Weights file is the wrong version." in err_line:
					show_info(err_line.strip())
					break

			except:
				log("Could not find out, abandoning")
				break
		
		
		self.free_handicap_stones=[]
		self.history=[]
예제 #36
0
	def r2csv(self):
		filename = open_rsgf_file(parent=self.parent)
		if not filename:
			return
		rsgf2csv(filename)
		show_info(_("The file %s has been converted to %s")%(os.path.basename(filename),os.path.basename(filename)+".csv"),parent=self.parent)
예제 #37
0
	def run_analysis(self,current_move):
		
		one_move=go_to_move(self.move_zero,current_move)
		player_color=guess_color_to_play(self.move_zero,current_move)
		
		gnugo=self.gnugo
		log()
		log("==============")
		log("move",str(current_move))
		
		final_score=gnugo.get_gnugo_estimate_score()
		#linelog(final_score)

		es=final_score.split()[0]
		
		
		if es[0]=="B":
			lbs="B%+d"%(-1*float(final_score.split()[3][:-1]))
			ubs="B%+d"%(-1*float(final_score.split()[5][:-1]))
		else:
			ubs="W%+d"%(float(final_score.split()[3][:-1]))
			lbs="W%+d"%(float(final_score.split()[5][:-1]))
		
		node_set(one_move,"ES",es)
		node_set(one_move,"UBS",ubs)
		node_set(one_move,"LBS",lbs)
		

		if player_color in ('w',"W"):
			log("gnugo plays white")
			top_moves=gnugo.gnugo_top_moves_white()
			answer=gnugo.play_white()
		else:
			log("gnugo plays black")
			top_moves=gnugo.gnugo_top_moves_black()
			answer=gnugo.play_black()

		log("====","Gnugo answer:",answer)
		node_set(one_move,"CBM",answer)
		
		log("==== Gnugo top moves")
		for one_top_move in top_moves:
			log("\t",one_top_move)
		log()
		top_moves=top_moves[:min(self.nb_variations,self.maxvariations)]
		if (answer not in ["PASS","RESIGN"]):
			gnugo.undo()
			
			while len(top_moves)>0:
				all_threads=[]
				for worker in self.workers:
					worker.need_undo=False
					if len(top_moves)>0:
						one_top_move=top_moves.pop(0)
						
						if player_color in ('w',"W"):
							worker.place_white(one_top_move)
							one_thread=threading.Thread(target=get_full_sequence_threaded,args=(worker,'b',self.deepness))
						else:
							worker.place_black(one_top_move)
							one_thread=threading.Thread(target=get_full_sequence_threaded,args=(worker,'w',self.deepness))
						worker.need_undo=True
						one_thread.one_top_move=one_top_move
						one_thread.start()
						all_threads.append(one_thread)
						
				
				for one_thread in all_threads:
					one_thread.join()
				
				for worker in self.workers:
					if worker.need_undo:
						worker.undo()
					
				for one_thread in all_threads:
					if type(one_thread.sequence)!=type(["list"]):
						raise GRPException(_("GnuGo thread failed:")+"\n"+str(one_thread.sequence))
					
					one_sequence=one_thread.one_top_move+" "+one_thread.sequence[0]
					es=one_thread.sequence[1]
					one_sequence=one_sequence.strip()
					log(">>>>>>",one_sequence)
					previous_move=one_move.parent
					current_color=player_color
					first_move=True
					for one_deep_move in one_sequence.split(' '):
						if one_deep_move not in ['RESIGN','PASS']:
							i,j=gtp2ij(one_deep_move)
							new_child=previous_move.new_child()
							node_set(new_child,current_color,(i,j))
							if first_move:
								first_move=False
								node_set(new_child,"ES",es)
							previous_move=new_child
							if current_color in ('w','W'):
								current_color='b'
							else:
								current_color='w'

		else:
			gnugo.undo()
		#one_move.add_comment_text(additional_comments)
		
		log("Creating the influence map")
		black_influence=gnugo.get_gnugo_initial_influence_black()
		black_territories_points=[]
		black_influence_points=[]
		white_influence=gnugo.get_gnugo_initial_influence_white()
		white_territories_points=[]
		white_influence_points=[]
		for i in range(self.size):
			for j in range(self.size):
				if black_influence[i][j]==-3:
					black_territories_points.append([i,j])
				if white_influence[i][j]==3:
					white_territories_points.append([i,j])
				
				if black_influence[i][j]==-2:
					black_influence_points.append([i,j])
				if white_influence[i][j]==2:
					white_influence_points.append([i,j])

		if black_influence_points!=[]:
			node_set(one_move,"IBM",black_influence_points) #IBM: influence black map
			
		if black_territories_points!=[]:
			node_set(one_move,"TBM",black_territories_points) #TBM: territories black map
			
		if white_influence_points!=[]:
			node_set(one_move,"IWM",white_influence_points) #IWM: influence white map
			
		if white_territories_points!=[]:
			node_set(one_move,"TWM",white_territories_points) #TWM: territories white map
		
		return answer #returning the best move, necessary for live analysis