def select_rival_move(self): select = self.resp_rival if select == "su": resp = WindowBooks.eligeJugadaBooks( self.main_window, self.list_moves, self.game.last_position.is_white) elif select == "mp": resp = self.list_moves[0][0], self.list_moves[0][ 1], self.list_moves[0][2] nmax = self.list_moves[0][4] for xfrom, xto, promotion, pgn, peso in self.list_moves: if peso > nmax: resp = xfrom, xto, promotion nmax = peso elif select == "au": pos = random.randint(0, len(self.list_moves) - 1) resp = self.list_moves[pos][0], self.list_moves[pos][ 1], self.list_moves[pos][2] else: li = [int(x[4] * 100000) for x in self.list_moves] t = sum(li) num = random.randint(1, t) pos = 0 t = 0 for n, x in enumerate(li): t += x if num <= t: pos = n break resp = self.list_moves[pos][0], self.list_moves[pos][ 1], self.list_moves[pos][2] return resp
def eligeJugadaBookBase(self, book, book_select): fen = self.last_fen() if book_select == "su": listaJugadas = book.get_list_moves(fen) if listaJugadas: resp = WindowBooks.eligeJugadaBooks(self.main_window, listaJugadas, self.game.last_position.is_white) return True, resp[0], resp[1], resp[2] else: pv = book.eligeJugadaTipo(fen, book_select) if pv: return True, pv[:2], pv[2:4], pv[4:] return False, None, None, None
def ayuda(self): if self.human_is_playing: self.paraHumano() else: return self.board.set_position(self.game.last_position) main = self.list_moves[0][4] saux = False paux = 0 for n, jug in enumerate(self.list_moves): opacity = p = jug[4] simain = p == main if not simain: if not saux: paux = p saux = True opacity = 1.0 if p == paux else max(p, 0.25) self.board.creaFlechaMulti(jug[0] + jug[1], siMain=simain, opacity=opacity) resp = WindowBooks.eligeJugadaBooks(self.main_window, self.list_moves, self.human_side, siSelectSiempre=False) self.board.remove_arrows() if resp is None: self.sumar_aciertos = False self.sigueHumano() return xfrom, xto, promotion = resp ok, mens, jg = Move.get_game_move(self.game, self.game.last_position, xfrom, xto, promotion) self.movimientos += 1 self.set_label3("<b>%s</b>" % self.txt_matches()) self.move_the_pieces(jg.liMovs) self.masJugada(jg, True) self.error = "" self.sumar_aciertos = True self.siguienteJugada()
def play_human(self, xfrom, xto, promotion=None): jg = self.check_human_move(xfrom, xto, promotion) if not jg: return False found = False actpeso = 0 for jdesde, jhasta, jpromotion, jpgn, peso in self.list_moves: if xfrom == jdesde and xto == jhasta and jg.promotion == jpromotion: found = True actpeso = peso break if found and self.player_highest: # si el jugador busca elegir el maximo maxpeso = 0.0 for jdesde, jhasta, jpromotion, jpgn, peso in self.list_moves: if peso > maxpeso: maxpeso = peso if actpeso < maxpeso: found = False if not found: self.board.set_position(self.game.last_position) main = self.list_moves[0][4] saux = False paux = 0 for n, jug in enumerate(self.list_moves): opacity = p = jug[4] simain = p == main if not simain: if not saux: paux = p saux = True opacity = 1.0 if p == paux else max(p, 0.25) self.board.creaFlechaMulti(jug[0] + jug[1], siMain=simain, opacity=opacity) if self.show_menu: resp = WindowBooks.eligeJugadaBooks(self.main_window, self.list_moves, self.human_side, siSelectSiempre=False) self.board.remove_arrows() else: resp = None if resp is None: self.sumar_aciertos = False self.sigueHumano() return False xfrom, xto, promotion = resp ok, mens, jg = Move.get_game_move(self.game, self.game.last_position, xfrom, xto, promotion) else: if self.sumar_aciertos: self.aciertos += actpeso self.movimientos += 1 self.set_label3("<b>%s</b>" % self.txt_matches()) self.move_the_pieces(jg.liMovs) self.masJugada(jg, True) self.error = "" self.sumar_aciertos = True self.siguienteJugada() return True