def _update_curr_player(self, curr_player_id, put_card): player = self._players[curr_player_id] hcs = HandCardStruct() hand_card_color_seq = player.hand_card_struct.hand_card_color_seq for item in put_card: for ix, val in enumerate(hand_card_color_seq): if val is not None and item == val[1]: hand_card_color_seq[ix] = None break new_seq = list(filter(lambda x: x is not None, hand_card_color_seq)) hcs.hand_card_color_seq = new_seq player.hand_card_struct = hcs for item in put_card: self._put_card_status[item] += 1
def game_start(self): # 第一个玩家是第二个玩家的上家 # 第二个玩家是第三个玩家的上家 # 第三个玩家是第一个玩家的上家 player1 = Player('001') id1 = player1.player_id print('玩家[ID=%s]进入了游戏' %id1) player2 = Player('002') id2 = player2.player_id print('玩家[ID=%s]进入了游戏' %id2) player3 = Player('003') id3 = player3.player_id print('玩家[ID=%s]进入了游戏' %id3) self._players[id1] = player1 self._players[id2] = player2 self._players[id3] = player3 sleep_time = 1 print('游戏%s后开始...' %sleep_time) for k in range(sleep_time): print(sleep_time-k) time.sleep(1) print('-----------------游戏开始---------------') random.shuffle(all_card.ALL_CARD) time.sleep(1) print('开始为玩家[ID=%s]发牌' %id1) hand_card = self.deal_card(1) hcs1 = HandCardStruct() hcs1.hand_card_color_seq = hand_card print('玩家[ID=%s]的手牌为\n%s' %(id1, hcs1.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' %id2) hand_card = self.deal_card(2) hcs2 = HandCardStruct() hcs2.hand_card_color_seq = hand_card print('玩家[ID=%s]的手牌为\n%s' %(id2, hcs2.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' %id3) hand_card = self.deal_card(3) hcs3 = HandCardStruct() hcs3.hand_card_color_seq = hand_card print('玩家[ID=%s]的手牌为\n%s' %(id3, hcs3.hand_card_seq)) time.sleep(1) # TO DO: 目前是随机一个玩家为地主,后续需要添加抢地主环节 rnd, self._land_owner_id = self.call_by([id1,id2,id3]) # 设置玩家角色 self.set_player_role(rnd, [id1,id2,id3])
def set_game_env(self): # 第一个玩家是第二个玩家的上家 # 第二个玩家是第三个玩家的上家 # 第三个玩家是第一个玩家的上家 player1 = Player('001') id1 = player1.player_id print('玩家[ID=%s]进入了游戏' % id1) player2 = Player('002') id2 = player2.player_id print('玩家[ID=%s]进入了游戏' % id2) player3 = Player('003') id3 = player3.player_id print('玩家[ID=%s]进入了游戏' % id3) self._players[id1] = player1 self._players[id2] = player2 self._players[id3] = player3 sleep_time = self._sleep_time print('游戏%s后开始...' % sleep_time) for k in range(sleep_time): print(sleep_time - k) time.sleep(1) print('-----------------游戏开始---------------') random.shuffle(all_card.ALL_CARD) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id1) hand_card = self.deal_card(1) hcs1 = HandCardStruct() hcs1.hand_card_color_seq = hand_card player1.hand_card_struct = hcs1 print('玩家[ID=%s]的手牌为\n%s' % (id1, hcs1.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id2) hand_card = self.deal_card(2) hcs2 = HandCardStruct() hcs2.hand_card_color_seq = hand_card player2.hand_card_struct = hcs2 print('玩家[ID=%s]的手牌为\n%s' % (id2, hcs2.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id3) hand_card = self.deal_card(3) hcs3 = HandCardStruct() hcs3.hand_card_color_seq = hand_card player3.hand_card_struct = hcs3 print('玩家[ID=%s]的手牌为\n%s' % (id3, hcs3.hand_card_seq)) time.sleep(1) # TO DO: 目前是随机一个玩家为地主,后续需要添加抢地主环节 land_rnd, self._land_owner_id = self.call_by([id1, id2, id3]) print('地主被玩家[ID=%s]抢到' % self._land_owner_id) # 设置玩家角色 self.set_player_role(land_rnd, [id1, id2, id3]) for player in self._players.values(): if player.player_role == PlayerRoleEnum.LAND_OWNER: print('玩家[ID=%s]为地主' % player.player_id) elif player.player_role == PlayerRoleEnum.UP_LAND_OWNER: print('玩家[ID=%s]为地主上家' % player.player_id) elif player.player_role == PlayerRoleEnum.LOW_LAND_OWNER: print('玩家[ID=%s]为地主下家' % player.player_id) else: print('Game running error') return self._bottom_card = self.deal_card(0) print('三张底牌为 %s' % self._bottom_card) land_hand_card = self.deal_card(land_rnd + 1) land_hand_card += self._bottom_card land_hcs = HandCardStruct() land_hcs.hand_card_color_seq = land_hand_card land_player = self._players[self._land_owner_id] land_player.hand_card_struct = land_hcs print('地主[ID=%s]的手牌为\n%s' % (land_player.player_id, land_hcs.hand_card_seq))
def set_game_env_test(self): player1 = Player('001') id1 = player1.player_id print('玩家[ID=%s]进入了游戏' % id1) player2 = Player('002') id2 = player2.player_id print('玩家[ID=%s]进入了游戏' % id2) player3 = Player('003') id3 = player3.player_id print('玩家[ID=%s]进入了游戏' % id3) self._players[id1] = player1 self._players[id2] = player2 self._players[id3] = player3 sleep_time = 3 print('游戏%s后开始...' % sleep_time) for k in range(sleep_time): print(sleep_time - k) time.sleep(1) print('-----------------游戏开始---------------') random.shuffle(all_card.ALL_CARD) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id1) hand_card = [(CardColorEnum.SPADE, 3), (CardColorEnum.SPADE, 3), (CardColorEnum.SPADE, 4), (CardColorEnum.SPADE, 4), (CardColorEnum.SPADE, 6), (CardColorEnum.SPADE, 7), (CardColorEnum.SPADE, 7), (CardColorEnum.SPADE, 7), (CardColorEnum.SPADE, 8), (CardColorEnum.SPADE, 10), (CardColorEnum.SPADE, 10), (CardColorEnum.SPADE, 11), (CardColorEnum.SPADE, 11), (CardColorEnum.SPADE, 12), (CardColorEnum.SPADE, 12), (CardColorEnum.SPADE, 12), (CardColorEnum.SPADE, 12), (CardColorEnum.SPADE, 15), (CardColorEnum.SPADE, 15), (CardColorEnum.SPADE, 16)] hcs1 = HandCardStruct() hcs1.hand_card_color_seq = hand_card player1.hand_card_struct = hcs1 print('玩家[ID=%s]的手牌为\n%s' % (id1, hcs1.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id2) hand_card = [(CardColorEnum.SPADE, 3), (CardColorEnum.SPADE, 3), (CardColorEnum.SPADE, 4), (CardColorEnum.SPADE, 5), (CardColorEnum.SPADE, 8), (CardColorEnum.SPADE, 8), (CardColorEnum.SPADE, 8), (CardColorEnum.SPADE, 9), (CardColorEnum.SPADE, 9), (CardColorEnum.SPADE, 10), (CardColorEnum.SPADE, 11), (CardColorEnum.SPADE, 13), (CardColorEnum.SPADE, 13), (CardColorEnum.SPADE, 13), (CardColorEnum.SPADE, 14), (CardColorEnum.SPADE, 14), (CardColorEnum.SPADE, 15)] hcs2 = HandCardStruct() hcs2.hand_card_color_seq = hand_card player2.hand_card_struct = hcs2 print('玩家[ID=%s]的手牌为\n%s' % (id2, hcs2.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id3) hand_card = [(CardColorEnum.SPADE, 4), (CardColorEnum.SPADE, 5), (CardColorEnum.SPADE, 5), (CardColorEnum.SPADE, 5), (CardColorEnum.SPADE, 6), (CardColorEnum.SPADE, 6), (CardColorEnum.SPADE, 6), (CardColorEnum.SPADE, 7), (CardColorEnum.SPADE, 9), (CardColorEnum.SPADE, 9), (CardColorEnum.SPADE, 10), (CardColorEnum.SPADE, 11), (CardColorEnum.SPADE, 13), (CardColorEnum.SPADE, 14), (CardColorEnum.SPADE, 14), (CardColorEnum.SPADE, 15), (CardColorEnum.SPADE, 17)] hcs3 = HandCardStruct() hcs3.hand_card_color_seq = hand_card player3.hand_card_struct = hcs3 print('玩家[ID=%s]的手牌为\n%s' % (id3, hcs3.hand_card_seq)) time.sleep(1) # TO DO: 目前是随机一个玩家为地主,后续需要添加抢地主环节 land_rnd, self._land_owner_id = 0, id1 print('地主被玩家[ID=%s]抢到' % self._land_owner_id) # 设置玩家角色 self.set_player_role(land_rnd, [id1, id2, id3]) for player in self._players.values(): if player.player_role == PlayerRoleEnum.LAND_OWNER: print('玩家[ID=%s]为地主' % player.player_id) elif player.player_role == PlayerRoleEnum.UP_LAND_OWNER: print('玩家[ID=%s]为地主上家' % player.player_id) elif player.player_role == PlayerRoleEnum.LOW_LAND_OWNER: print('玩家[ID=%s]为地主下家' % player.player_id) else: print('Game running error') return
def human_agent_battle(self): global human_player_id human_name = input('请输入人类玩家名称:') human_name = "灭霸" if len(human_name) == 0 else human_name human_player_id = human_name player1 = Player(human_name) id1 = player1.player_id print('玩家[ID=%s]进入了游戏' % id1) player2 = Player('机器人-狗蛋') id2 = player2.player_id print('玩家[ID=%s]进入了游戏' % id2) player3 = Player('机器人-猫屎') id3 = player3.player_id print('玩家[ID=%s]进入了游戏' % id3) self._players[id1] = player1 self._players[id2] = player2 self._players[id3] = player3 sleep_time = 3 print('游戏%s后开始...' % sleep_time) for k in range(sleep_time): print(sleep_time - k) time.sleep(1) print('-----------------游戏开始---------------') random.shuffle(all_card.ALL_CARD) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id1) hand_card = self.deal_card(1) hcs1 = HandCardStruct() hcs1.hand_card_color_seq = hand_card player1.hand_card_struct = hcs1 print('玩家[ID=%s]的手牌为\n%s' % (id1, hcs1.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id2) hand_card = self.deal_card(2) hcs2 = HandCardStruct() hcs2.hand_card_color_seq = hand_card player2.hand_card_struct = hcs2 print('玩家[ID=%s]的手牌为\n%s' % (id2, hcs2.hand_card_seq)) time.sleep(1) print('开始为玩家[ID=%s]发牌' % id3) hand_card = self.deal_card(3) hcs3 = HandCardStruct() hcs3.hand_card_color_seq = hand_card player3.hand_card_struct = hcs3 print('玩家[ID=%s]的手牌为\n%s' % (id3, hcs3.hand_card_seq)) time.sleep(1) # 叫地主 land_rnd, self._land_owner_id = self.call_by([id1, id2, id3]) print('地主被玩家[ID=%s]抢到' % self._land_owner_id) # 设置玩家角色 self.set_player_role(land_rnd, [id1, id2, id3]) for player in self._players.values(): if player.player_role == PlayerRoleEnum.LAND_OWNER: print('玩家[ID=%s]为地主' % player.player_id) elif player.player_role == PlayerRoleEnum.UP_LAND_OWNER: print('玩家[ID=%s]为地主上家' % player.player_id) elif player.player_role == PlayerRoleEnum.LOW_LAND_OWNER: print('玩家[ID=%s]为地主下家' % player.player_id) else: print('Game running error') return self._bottom_card = self.deal_card(0) print('三张底牌为 %s' % self._bottom_card) land_hand_card = self.deal_card(land_rnd + 1) land_hand_card += self._bottom_card land_hcs = HandCardStruct() land_hcs.hand_card_color_seq = land_hand_card land_player = self._players[self._land_owner_id] land_player.hand_card_struct = land_hcs print('地主[ID=%s]的手牌为\n%s' % (land_player.player_id, land_hcs.hand_card_seq))