def process_pick_command(message, name, userlist): global GAME_START msg_list = message.split() str_pick_num = users.get_str_pick_num() pick_num = check.check_message_syntax(msg_list, str_pick_num) logging.debug(pick_num) on_time_flag = check.check_on_time(msg_list, users.gs_users) if GAME_START: msg = "Game was already started.. You can't use this command\n" userlist[1].send(msg) return if pick_num != -1 and on_time_flag: logging.debug(users.pick_cards_badak) if userlist[8] != '0': userlist[1].send("You already choosed a card (%s)\n" % userlist[8]) userlist[1].send("Wait a moment\n") elif userlist[6]: userlist[8] = users.pick_cards_badak[pick_num-1] # delete a picked card from pick_cards_badak users.pick_cards_badak.pop(pick_num-1) send_all("%s picks %s" % (name, userlist[8])) userlist[6] = False # if user is last one, then start go-stop game if name == users.ordered_user_list[2][0]: # decide first user and play game... first_player = users.who_is_first_player() logging.info("First player is %s" % first_player) # if badak cards have bonus cards, # then give it to first player preparing_new_round(first_player) GAME_START = True logging.info('start this round...') msg = "First player is %s. Let's start.." % first_player send_all(msg) # show one's own cards to user show_cards_to_all_users() # users.gs_users[first_player][1].send(users.gs_users[first_player][2], "\n") msg = "Your turn\n" users.gs_users[first_player][1].send(msg) #play_game_now() else: # send pick message to next user player_name = users.who_is_next_player(name) msg = ('Choose a card (1-%d): pick #\n' % (int(str_pick_num) - 1)) logging.debug(msg) users.gs_users[player_name][1].send(msg) users.gs_users[player_name][6] = True else: # need to be more specific [TODO] msg = "It's not your turn... Wait a sec..\n" userlist[1].send(msg) elif pick_num == -1: msg = 'You have to use pick 1-%s..\n' % str_pick_num logging.debug(msg) userlist[1].send(msg)
def process_play_command(message, name, userlist): msg_list = message.split() # your turn? if not userlist[6]: msg = "This is not your turn..\n" userlist[1].send(msg) return if not GAME_START: msg = "Game is not started.. You can't use this command\n" userlist[1].send(msg) return # argument is correct? card_num = check.check_message_syntax(msg_list, player_name=name) logging.debug(card_num) if card_num < 0: msg = "play command ERROR.. Try again." userlist[1].send(msg) return # Okay, so far so good.. logging.debug("users's cards: %s" % userlist[2]) logging.debug("users's card[%d]: %s" % (card_num-1, userlist[2][card_num-1])) logging.debug("badak card: %s" % str(users.cards_badak)) card_from_pile = [] card_of_user = userlist[2].pop(card_num-1) card_from_pile.append(users.cards_draw_pile.pop()) while card_from_pile[-1][0] == 'D': card_from_pile.append(users.cards_draw_pile.pop()) logging.debug("draw pile: %s" % str(cards_draw_pile)) # Phase 1 if card_of_user[0] != card_from_pile[-1][0]: matched_list = users.match_with_badak(card_of_user) logging.debug("matched list: %s" % str(matched_list)) if len(matched_list) == 0: # Phase 2 matched_list_with_pile = users.match_with_badak(card_from_pile[-1]) logging.debug("matched_list_with_pile: %s" % str(matched_list_with_pile)) if len(matched_list_with_pile) == 0: pass elif len(matched_list_with_pile) == 1: userlist[3].extend(matched_list_with_pile) userlist[3].extend(card_from_pile) elif len(matched_list_with_pile) == 2: pass elif len(matched_list_with_pile) == 3: pass else: assert(False) elif len(matched_list) == 1: # 1. just get one pair # 2. just get two different pairs (Happy!!) pass elif len(matched_list) == 2: pass elif len(matched_list) == 3: pass else: assert(False) users.cards_badak.append(card_of_user) else: # more complicated... pass