예제 #1
0
    def _reload_empty_hand(self):
        '''
		Process the act of reloading hand with cards if it is empty.
		'''
        turn = self.state['g'].get_turn_pid()
        if True == self.state['g'].is_hand_empty():
            if True == self.DEBUG_FUNC:
                print "pid {0} drawing hand.".format(turn)

            FAIL = ''
            if 0 == turn:
                if self.chance(self.FAIL_CHANCE
                               ):  # correct len, wrong tags for this msg
                    msg = sp.serialize_turn(0)
                    msg = msg[5:]
                    FAIL = 'ERR_INVALID_XML'
                else:
                    msg = sp.serialize_draw_request()
                self.write(msg)

            new_hand = self.state['g'].draw_new_hand()

            if 0 == turn:
                if '' != FAIL:
                    msg = sp.serialize_error(FAIL)
                    self.read(length=len(msg), expect=msg)
                    return -1
                else:
                    msg = sp.serialize_cards(new_hand)
                    self.read(length=len(msg), expect=msg)

            if True == self.DEBUG_FUNC:
                print "  new hand: {0}".format(new_hand)

        return 0
예제 #2
0
	def _reload_empty_hand(self):
		'''
		Process the act of reloading hand with cards if it is empty.
		'''
		turn = self.state['g'].get_turn_pid()
		if True == self.state['g'].is_hand_empty():
			if True == self.DEBUG_FUNC:
				print "pid {0} drawing hand.".format(turn)

			FAIL = ''
			if 0 == turn:
				if self.chance(self.FAIL_CHANCE): # correct len, wrong tags for this msg
					msg = sp.serialize_turn(0)
					msg = msg[5:]
					FAIL = 'ERR_INVALID_XML'
				else:
					msg = sp.serialize_draw_request()
				self.write(msg)

			new_hand = self.state['g'].draw_new_hand()

			if 0 == turn:
				if '' != FAIL:
					msg = sp.serialize_error(FAIL)
					self.read(length=len(msg), expect=msg)
					return -1
				else:
					msg = sp.serialize_cards(new_hand)
					self.read(length=len(msg), expect=msg)

			if True == self.DEBUG_FUNC:
				print "  new hand: {0}".format(new_hand)

		return 0
예제 #3
0
 def _recv_error(self, error_name):
     expected = sp.serialize_error(error_name)
     self.read(length=len(expected), expect=expected)
     if True == self.DEBUG_ERR:
         print('exiting due to {0}'.format(error_name))
예제 #4
0
	def _recv_error(self, error_name):
		expected = sp.serialize_error(error_name)
		self.read(length=len(expected), expect=expected)
		if True == self.DEBUG_ERR:
			print('exiting due to {0}'.format(error_name))