def command_theme(m): cid = m.chat.id user = str(m.from_user.id) text = m.text exist = settings.settings_exist(cid) if exist: theme = text.split("/theme")[1].replace(" ", "") if not theme in THEMES: markup = types.ReplyKeyboardMarkup(row_width=2) for key in THEMES.keys(): markup.add("/theme " + key) current = game.get_info(cid)['theme'] bot.send_message(cid, "Choose one option:\n <b>Current: </b>" + current, reply_markup=markup, parse_mode="HTML", disable_notification=True) else: markup = types.ReplyKeyboardHide(selective=False) bot.send_message(cid, "Succesful!", reply_markup=markup, disable_notification=True) settings.update_settings(cid, theme=theme) playing = tools.game_exist(cid) if playing: game.update_info(cid, theme=theme) caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption, silent=True)
def command_white(m): cid = m.chat.id user = str(m.from_user.id) first_name = str(m.from_user.first_name) last_name = str(m.from_user.last_name) userMG.create_user(user, first_name, last_name) text = m.text exist = tools.game_exist(cid) if exist and not game.is_ready_info(cid): game_type = game.get_info(cid)['game_type'] if game_type == "0": uci = settings.get_settings(cid)['engine'] game.update_info(cid, white=user, black=uci, uci_white="0") firs_step(cid, bot) elif game_type == "1": players = [game.white(cid), game.black(cid)] if not user in players: if players[0] == "0": game.update_info(cid, white=user) if game.black(cid) != "0": firs_step(cid, bot) else: bot.send_message(cid, "Waiting for /black player...") else: bot.send_message( cid, "This color was already chosen.\nChoose /black...", disable_notification=True) else: bot.send_message(cid, "You've already chosen color.", disable_notification=True)
def command_fen(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: fen = game.get_info(cid)['fen'] bot.send_message(cid, fen, disable_notification=True) else: bot.send_message(cid, "Type for /start a new game", disable_notification=True)
def play_move(m): # print m cid = m.chat.id user = str(m.from_user.id) move = m.text exist = tools.game_exist(cid) if exist and game.is_ready_info(cid): game_type = game.get_info(cid)['game_type'] if game_type == "0": legal_moves = tools.get_legal_moves(cid) if move in legal_moves: user_move = tools.make_allowed_user_move(cid, user, move) if user_move != "INCORRECT_TURN": engine_move = tools.make_engine_move(cid) if user_move != "FINISHED" or engine_move != "FINISHED": caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption) if tools.finished( chess.Board(game.get_info(cid)['fen'])): tools.delete_game(cid) bot.send_message( cid, "End...\nType for /start a new game", disable_notification=True) else: tools.delete_game(cid) bot.send_message( cid, "Game finished...\nType for /start a new game") elif game_type == "1": legal_moves = tools.get_legal_moves(cid) if move in legal_moves: user_move = tools.make_allowed_user_move(cid, user, move) if user_move != "FINISHED": if user_move != "INCORRECT_TURN": caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption) else: tools.delete_game(cid) bot.send_message( cid, "Game finished...\nType for /start a new game")
def command_flip(m): cid = m.chat.id user = str(m.from_user.id) exist = tools.game_exist(cid) if exist: flipped = game.get_info(cid)['flipped'] if flipped == "0": game.update_info(cid, flipped="1") else: game.update_info(cid, flipped="0") caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption, silent=True) else: bot.send_message(cid, "Type for /start a new game", disable_notification=True)
def firs_step(cid, bot): #SEND BOARD AND DELETING MARKUP markup = types.ReplyKeyboardHide(selective=False) bot.send_message(cid, "Beginning game...", reply_markup=markup) #BOARD caption = tools.get_last_from_pgn(cid) tools.send_board_image(bot, cid, caption) if game.get_info(cid)['game_type'] == "1": white_name = userMG.get_user_info(game.white(cid))['first_name'] white_last_name = userMG.get_user_info(game.white(cid))['last_name'] white = white_name + " " + white_last_name black_name = userMG.get_user_info(game.black(cid))['first_name'] black_last_name = userMG.get_user_info(game.black(cid))['last_name'] black = black_name + " " + black_last_name players = "Players:\nWhite: " + white + "\nBlack: " + black bot.send_message(cid, players)
import chess.uci import utils.info as info import utils.chessUtils as csu engines_path = "/home/antonio/Escritorio/Chess/engines/" engines_names = [ "arasan", "critter", "fruit", "greko", "jazz", "komodo", "rocinante", "stockfish", "toga" ] engine_name = engines_names[3] engine_file = os.path.join(engines_path, engine_name) engine = chess.uci.popen_engine(engine_file) engine.uci() info.create_info(1) ditc = info.get_info(1) fen = ditc["fen"] board = chess.Board(fen) user_pieces_color = str(raw_input("Select color (B/W): ").upper()) if user_pieces_color == "B": info.update_info(1, flipped="1") rend = Renderer(1) rend.draw_fen().save("0.jpg", "JPEG") while (not board.is_checkmate() and not board.is_stalemate()): turn = csu.check_turn(board.fen()) if turn == user_pieces_color: legal_moves = csu.parsed_moves( str(board.legal_moves).split("(")[1].split(")")[0].replace(