示例#1
0
def pick_resp(bot, game, uid, opcion):
    try:
        log.info('pick_resp called')
        if (game.board.state.fase_actual != "Adivinando"
                or uid != game.board.state.active_player.uid or int(opcion) >
                len(game.board.state.ordered_votes)):  # and uid not in ADMIN:
            bot.send_message(
                game.cid,
                "No es el momento de adivinar, no eres el que tiene que adivinar o no has ingresado algo valido para puntuar",
                ParseMode.MARKDOWN)
            return
        # Llego con un numero valido, mayor a zero y que esta en el rando de las respuestas
        args_text = opcion

        game.board.state.index_pick_resp = int(args_text) - 1

        bot.send_message(game.cid,
                         "El jugador activo ha elegido la frase! A votar!")
        game.board.state.fase_actual = "Votando Frases"

        if len(game.board.state.votes_on_votes) == (len(game.player_sequence) -
                                                    1) * 2:
            SayAnythingController.count_points(bot, game)
        else:
            SayAnythingController.command_call(bot, game)

        #SayAnythingController.count_points(bot, game)
        #SayAnythingController.start_next_round(bot, game)

    except Exception as e:
        bot.send_message(uid, str(e))
        log.error("Unknown error: " + str(e))
示例#2
0
def myturn_message(bot, game, uid):
    try:
        if game.tipo == 'JustOne':
            return JustOneController.myturn_message(game, uid)
        elif game.tipo == 'SayAnything':
            if game.board.state.fase_actual == "Votando Frases":
                SayAnythingController.send_vote_buttons(bot, game, uid)
                return "Te faltan votos"
            return SayAnythingController.myturn_message(game, uid)
    except Exception as e:
        return str(e)
示例#3
0
def command_pass(bot, update):
    log.info('command_pass called')
    uid = update.message.from_user.id
    cid = update.message.chat_id
    game = Commands.get_game(cid)

    if game.board.state.fase_actual != "Adivinando" or uid != game.board.state.active_player.uid:
        bot.send_message(
            game.cid,
            "No es el momento de adivinar o no eres el que tiene que adivinar",
            ParseMode.MARKDOWN)
        return
    SayAnythingController.pass_say_anything(bot, game)
示例#4
0
def command_forced_clue(bot, update):
    uid = update.message.from_user.id
    cid = update.message.chat_id
    game = get_game(cid)
    '''
	answer = "Pista "
	i = 1
	for uid in game.playerlist:
		if uid != game.board.state.active_player.uid:
			game.board.state.last_votes[uid] = answer + str(i)
			i += 1
	'''
    #game.board.state.reviewer_player = game.playerlist[387393551]
    SayAnythingController.review_clues(bot, game)
示例#5
0
def command_prueba(bot, update, args, chat_data, user_data):
    #log.info(update.message.from_user.id)
    #log.info(update.message.chat_id)
    cid, uid = update.message.chat_id, update.message.from_user.id
    groupType, groupName = update.message.chat.type, update.message.chat.title

    if uid in ADMIN:
        game = get_game(cid)

        #bot.send_message(cid, "Este es el grupo ({0}) - Cuyo nombre es {1} y tipo es {2}".format(cid, groupName, groupType))
        #bot.send_message(cid, chat_data)
        #bot.send_message(cid, user_data)

        SayAnythingController.call_players_to_vote(bot, game)
        '''
示例#6
0
def init_game(bot, game):
	log.info('Game Init called')
	player_number = len(game.playerlist)
	game.board = Board(player_number, game)	
	bot.send_message(game.cid, "Juego iniciado")
	if game.tipo == "LostExpedition":
		init_lost_expedition(bot, game, player_number)
	elif game.tipo == "JustOne":
		JustOneController.init_game(bot, game)
	elif game.tipo == "SayAnything":
		game.create_board()
		SayAnythingController.init_game(bot, game)
	elif game.tipo == "Arcana":
		game.create_board()
		ArcanaController.init_game(bot, game)
示例#7
0
def add_propose(bot, game, uid, propuesta):
    # Se verifica igual en caso de que quede una botonera perdida
    if uid in game.playerlist:
        #Check if there is a current game
        if game.board == None:
            bot.send_message(game.cid, "El juego no ha comenzado!")
            return
        if uid == ADMIN[0] or (uid != game.board.state.active_player.uid
                               and game.board.state.fase_actual
                               == "Proponiendo Pistas"):
            bot.send_message(uid,
                             "Tu respuesta: %s fue agregada." % (propuesta))
            #game.board.state.last_votes[uid] = propuesta

            # Si tiene el atributo no fue ingresado ningun voto y no fue creado. Lo creo.
            if hasattr(game.board.state, 'ordered_votes'):
                previous_vote = next(
                    (vote for vote in game.board.state.ordered_votes
                     if vote.player.uid == uid), None)
                if previous_vote:
                    game.board.state.ordered_votes.remove(previous_vote)
                game.board.state.ordered_votes.append(
                    Vote(game.playerlist[uid], 'propuesta', propuesta))
            else:
                game.board.state.ordered_votes = []
                game.board.state.ordered_votes.append(
                    Vote(game.playerlist[uid], 'propuesta', propuesta))

            Commands.save(bot, game.cid)
            # Verifico si todos los jugadores -1 pusieron pista
            bot.send_message(
                game.cid, "El jugador *%s* ha ingresado una respuesta." %
                game.playerlist[uid].name, ParseMode.MARKDOWN)
            # Todo cambiar a -1 cuando termine las pruebas
            if len(game.board.state.ordered_votes) == len(
                    game.player_sequence) - 1:
                SayAnythingController.send_prop(bot, game)
        else:
            bot.send_message(
                uid,
                "No puedes proponer si sos el jugador activo o ya ha pasado la fase de poner pistas."
            )
    else:
        bot.send_message(uid,
                         "No puedes hacer clue si no estas en el partido.")
示例#8
0
def call_proponiendo_pistas(bot, game):
    if not game.dateinitvote:
        # If date of init vote is null, then the voting didnt start
        bot.send_message(game.cid, "No es momento de dar pista.")
    else:
        #If there is a time, compare it and send history of votes.
        start = game.dateinitvote
        stop = datetime.datetime.now()
        elapsed = stop - start
        if elapsed > datetime.timedelta(minutes=1):
            # Only remember to vote to players that are still in the game
            history_text = ""
            for player in game.player_sequence:
                # If the player is not in ordered_votes send him reminder
                voto_jugador = next((x for x in game.board.state.ordered_votes
                                     if x.player.uid == player.uid), None)
                if not voto_jugador and player.uid != game.board.state.active_player.uid:
                    history_text += "Tienes que dar una respuesta {0}.\n".format(
                        helper.player_call(player))
                    # Envio mensaje inicial de pistas para recordarle al jugador la pista y el grupo
                    mensaje = "Palabra en el grupo *{1}*.\nJugador activo: *{2}*\nLa frase es: *{0}*, propone tu respuesta!".format(
                        game.board.state.acciones_carta_actual, game.groupName,
                        game.board.state.active_player.name)
                    bot.send_message(player.uid, mensaje, ParseMode.MARKDOWN)
                    mensaje = "/resp Ejemplo" if game.board.num_players != 3 else "/prop Ejemplo Ejemplo2"
                    bot.send_message(player.uid, mensaje)
            bot.send_message(game.cid, history_text, ParseMode.MARKDOWN)
            if game.board.num_players != 3 and len(
                    game.board.state.ordered_votes) == len(
                        game.player_sequence) - 1:
                SayAnythingController.send_prop(bot, game)
            elif len(game.board.state.ordered_votes) == len(
                    game.player_sequence) + 1:
                # De a 3 jugadores exigo que pongan 2 pistas cada uno son 4 de a 3 jugadores
                SayAnythingController.send_prop(bot, game)
        else:
            bot.send_message(game.cid,
                             "5 minutos deben pasar para llamar a call")
示例#9
0
def command_call(bot, game):
    try:
        # Verifico en mi maquina de estados que comando deberia usar para el estado(fase) actual
        if game.board.state.fase_actual == "Proponiendo Pistas":
            call_proponiendo_pistas(bot, game)
        elif game.board.state.fase_actual == "Adivinando":
            bot.send_message(game.cid,
                             SayAnythingController.get_respuestas(bot, game),
                             ParseMode.MARKDOWN)
        elif game.board.state.fase_actual == "Votando Frases":
            call_to_vote_respeustas(bot, game)

    except Exception as e:
        bot.send_message(game.cid, str(e))
示例#10
0
def command_continue(bot, game, uid):
    try:

        # Verifico en mi maquina de estados que comando deberia usar para el estado(fase) actual
        if game.board.state.fase_actual == "Proponiendo Pistas":
            # Vuelvo a mandar la pista
            SayAnythingController.call_players_to_clue(bot, game)
        elif game.board.state.fase_actual == "Revisando Pistas":
            SayAnythingController.review_clues(bot, game)
        elif game.board.state.fase_actual == "Adivinando":
            active_player = game.board.state.active_player
            bot.send_message(
                game.cid,
                "{0} estamos esperando para que hagas /guess EJEMPLO o /pass".
                format(helper.player_call(active_player)), ParseMode.MARKDOWN)
        elif game.board.state.fase_actual == "Finalizado":
            SayAnythingController.continue_playing(bot, game)
    except Exception as e:
        bot.send_message(game.cid, str(e))
示例#11
0
def command_next_turn(bot, update):
    uid = update.message.from_user.id
    cid = update.message.chat_id
    game = Commands.get_game(cid)
    SayAnythingController.start_next_round(bot, game)