예제 #1
0
 def eat(self, agent, card, ctype, eat_list):
     if GameBoard.GoalState(self, card): # Check goal state
         self.gb.win_agent = self
         self.win_card = card
         self.win+=1
         agent.lose+=1
         print("\t[Test] Agent({0}) 吃胡 {1}!".format(self.name, card))
         return
     # Greedy algorithm: Always eat from the first choice
     print('\t[Info] {0}'.format(self))
     print('\t[Info] Eat {0} has option(s):'.format(card))
     if ctype==1:
     #if len(eat_list)==1: return self._eat(card, self.wang_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i+1, toCListStr(eat_list[i][1])))
         choice_opt = input('\t: ')
         if len(choice_opt) > 0: 
             return self._eat(card, self.wang_list, eat_list[int(choice_opt)-1][0], eat_list[int(choice_opt)-1][1])
     elif ctype==2:
     #if len(eat_list)==1: return self._eat(card, self.tube_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i+1, toCListStr(eat_list[i][1])))
         choice_opt = input('\t: ')
         if choice_opt == 'n' or choice_opt == 'N':
             return
         if len(choice_opt) > 0:
             return self._eat(card, self.tube_list, eat_list[int(choice_opt)-1][0], eat_list[int(choice_opt)-1][1])
     elif ctype==3:
     #if len(eat_list)==1: return self._eat(card, self.bamb_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i+1, toCListStr(eat_list[i][1])))
         choice_opt = input('\tChoose 1-{0}: '.format(len(eat_list)))
         if len(choice_opt) > 0:
             return self._eat(card, self.bamb_list, eat_list[int(choice_opt)-1][0], eat_list[int(choice_opt)-1][1])
예제 #2
0
	def __str__(self):
		self_str = "{0}({1}/{2}/{3}): [".format(self.name, self.win_by_draw, self.win, self.lose)
		for card in self.wang_list:
			self_str+="{0} ".format(card)
		for card in self.tube_list:
			self_str+="{0} ".format(card)
		for card in self.bamb_list:
			self_str+="{0} ".format(card)
		for card in self.word_list:
			self_str+="{0} ".format(card)
		for card in self.wind_list:
			self_str+="{0} ".format(card)    
		self_str = "{0}]".format(self_str)
		if len(self.flow_list) > 0:
			self_str+=" / [ "
			for card in self.flow_list:
				self_str+="{0} ".format(card)
			self_str+="]"
		else:
			self_str+=" / []"
		if len(self.pong_list) > 0:
			self_str+=" / [ "
			for card in self.pong_list:
				self_str+="{0} ".format(card)
			self_str+="]"
		else:
			self_str+=" / []"
		if self.win_card:
			self_str+=" -> {0}".format(self.win_card)
		else:
			prewin_tiles = GameBoard.PreWinTiles(self)
			if len(prewin_tiles) > 0:
				self_str+=" / 聽 {0}".format(toCListStr(prewin_tiles))
		return self_str
예제 #3
0
 def __str__(self):
     self_str = "{0}({1}/{2}/{3}): [".format(self.name, self.win_by_draw,
                                             self.win, self.lose)
     for card in self.wang_list:
         self_str += "{0} ".format(card)
     for card in self.tube_list:
         self_str += "{0} ".format(card)
     for card in self.bamb_list:
         self_str += "{0} ".format(card)
     for card in self.word_list:
         self_str += "{0} ".format(card)
     for card in self.wind_list:
         self_str += "{0} ".format(card)
     self_str = "{0}]".format(self_str)
     if len(self.flow_list) > 0:
         self_str += " / [ "
         for card in self.flow_list:
             self_str += "{0} ".format(card)
         self_str += "]"
     else:
         self_str += " / []"
     if len(self.pong_list) > 0:
         self_str += " / [ "
         for card in self.pong_list:
             self_str += "{0} ".format(card)
         self_str += "]"
     else:
         self_str += " / []"
     if self.win_card:
         self_str += " -> {0}".format(self.win_card)
     else:
         prewin_tiles = GameBoard.PreWinTiles(self)
         if len(prewin_tiles) > 0:
             self_str += " / 聽 {0}".format(toCListStr(prewin_tiles))
     return self_str
예제 #4
0
 def _eat(self, olist, dlist, elist):
     self.pong_list.extend(elist)
     for e in dlist:
         olist.remove(e)
         self.card_count-=1
     dcard = self.drop()
     self.dprint("\t[Test] {0}: Eat '{1}' and drop {2}!".format(self.name, toCListStr(elist), dcard))
     #self.gb.disCard(self, dcard)
     return dcard
예제 #5
0
 def _eat(self, olist, dlist, elist):
     self.pong_list.extend(elist)
     for e in dlist:
         olist.remove(e)
         self.card_count -= 1
     dcard = self.drop()
     self.dprint("\t[Test] {0}: Eat '{1}' and drop {2}!".format(
         self.name, toCListStr(elist), dcard))
     #self.gb.disCard(self, dcard)
     return dcard
예제 #6
0
 def eat(self, agent, card, ctype, eat_list):
     if GameBoard.GoalState(self, card):  # Check goal state
         self.gb.win_agent = self
         self.win_card = card
         self.win += 1
         agent.lose += 1
         print("\t[Test] Agent({0}) 吃胡 {1}!".format(self.name, card))
         return
     # Greedy algorithm: Always eat from the first choice
     print('\t[Info] {0}'.format(self))
     print('\t[Info] Eat {0} has option(s):'.format(card))
     if ctype == 1:
         #if len(eat_list)==1: return self._eat(card, self.wang_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i + 1, toCListStr(eat_list[i][1])))
         choice_opt = input('\t: ')
         if len(choice_opt) > 0:
             return self._eat(card, self.wang_list,
                              eat_list[int(choice_opt) - 1][0],
                              eat_list[int(choice_opt) - 1][1])
     elif ctype == 2:
         #if len(eat_list)==1: return self._eat(card, self.tube_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i + 1, toCListStr(eat_list[i][1])))
         choice_opt = input('\t: ')
         if choice_opt == 'n' or choice_opt == 'N':
             return
         if len(choice_opt) > 0:
             return self._eat(card, self.tube_list,
                              eat_list[int(choice_opt) - 1][0],
                              eat_list[int(choice_opt) - 1][1])
     elif ctype == 3:
         #if len(eat_list)==1: return self._eat(card, self.bamb_list, eat_list[0][0], eat_list[0][1])
         for i in range(len(eat_list)):
             print("\t{0}:{1} ".format(i + 1, toCListStr(eat_list[i][1])))
         choice_opt = input('\tChoose 1-{0}: '.format(len(eat_list)))
         if len(choice_opt) > 0:
             return self._eat(card, self.bamb_list,
                              eat_list[int(choice_opt) - 1][0],
                              eat_list[int(choice_opt) - 1][1])