def player_think_hu(self):  # 玩家是否自摸胡
     self.players[self.now_turn].hu_dis = hu_judge.hu_distance(
         self.players[self.now_turn].tiles)
     if self.players[self.now_turn].hu_dis == 0:  # 判断是否胡
         #             print("玩家" + str(self.now_turn) + "自摸胡了:" + utils.get_Tiles_names(self.players[self.now_turn].tiles))
         self.hu_id = self.now_turn
         self.finished = True
     return self.finished
示例#2
0
 def computer_choose(self):
     now_dis = hu_judge.hu_distance(self.tiles)
     cnt = self.get_cnt(self.tiles)
     list_dis = []
     for i in range(34):
         if cnt[i] == 1:
             self.tiles.remove(i)
             k = hu_judge.hu_distance(self.tiles)
             self.tiles.append(i)
             if k < now_dis:
                 return i
             elif k == now_dis:
                 list_dis.append(i)
     if len(list_dis) == 0:
         ran = int(np.floor(np.random.rand() * len(self.tiles)))
         t = self.tiles[ran]
     else:
         ran = int(np.floor(np.random.rand() * len(list_dis)))
         t = list_dis[ran]
     return t
 def others_think_hu(self, last_tile):
     for j in range(3):
         # 首先判断有没有人胡这张牌
         if hu_judge.hu_distance(
                 self.players[(self.now_turn + j) % 4].tiles,
                 last_tile) == 0:
             #                 print("玩家" + str((self.now_turn + j) % 4) + "胡了:" + utils.get_Tiles_names(
             #                     self.players[(self.now_turn + j) % 4].tiles) + utils.get_tile_name(last_tile))
             self.finished = True
             self.hu_id = (self.now_turn + j) % 4
             return True
     return False
示例#4
0
 def think_pong(self, tile, env=[]):
     if self.type == 'human':  # 待完善
         if self.is_pong(tile):
             print('是否要碰?(y/n)')
             flag = input()
             if flag == 'y':
                 self.tiles.remove(tile)
                 self.tiles.remove(tile)
                 self.pong_tiles.append([tile] * 3)
                 return 1
         return 0
     elif self.type == 'computer':  # 返回是否碰
         if self.is_pong(tile):
             # print("如果碰了,推荐出牌:",Utils.get_tile_name(t))
             # print("当前手牌:",Utils.get_Tiles_names(self.tiles))
             self.tiles.remove(tile)
             self.tiles.remove(tile)
             t = self.computer_choose()
             self.tiles.remove(t)
             if hu_judge.hu_distance(self.tiles) < self.hu_dis:
                 # print(str(self.id) + "碰" + utils.get_tile_name(tile))
                 self.pong_tiles.append([tile] * 3)
                 self.tiles += [t]
                 c = 1
             else:
                 self.tiles += [tile, tile, t]
                 c = 0
         else:
             c = 0
         return c
     elif self.type == 'ai':  # 返回是否碰
         pong_choice = [0]
         if self.is_pong(tile):  # 能碰
             self.old_pong_env = env
             pong_choice.append(1)
             c = self.pong_agent.act(env, utils.get_pong_cnt(pong_choice))
             if c == 1:  # 选择碰
                 self.tiles.remove(tile)
                 self.tiles.remove(tile)
                 self.pong_tiles += [tile] * 3
             self.last_act = 2
             self.old_pong_env = env
             self.last_act_pong = c
         else:
             c = 0
         return c
     else:
         return -1