Beispiel #1
0
    def client_reset(self, u: str, AI, logger, pos):
        self.username = u
        # create a gRPC channel + stub
        channel = grpc.insecure_channel(address + ':' + str(port))
        self.conn = rpc.GameStub(channel)
        self.ai = AI
        self._lock = threading.Lock()
        self._decision_so_far = [
        ]  # history of the decision info from the server
        self._new_response = []  # response list from the server
        self._new_request = []  # request list waiting to send to the server

        self.mypos = pos
        self.initMoney = -1
        self.bigBlind = -1
        self.totalPlayer = -1
        self.button = -1
        self.logger = logger
        self.step = -1
        if self.logger is None:
            self.logger = simple_logger()
        self.state = State(self.logger, self.totalPlayer, self.initMoney,
                           self.bigBlind, self.button)

        self.initialized = False
        self.stoped = False
        self.round = 0
        self.allowheartbeat = True
        self.heartbeaklock = threading.Lock()
    def __init__(self,
                 username: str,
                 key: str,
                 logger,
                 address='47.102.204.214',
                 port=9500,
                 question_path='C:/Users/Haoyang XU/Desktop/Question-client/',
                 answer_path='C:/Users/Haoyang XU/Desktop/Answer/'):
        self.username = username
        # create a gRPC channel + stub
        self.address = address
        self.port = port
        self.question_path = question_path
        self.answer_path = answer_path
        channel = grpc.insecure_channel(address + ':' + str(port))
        self.conn = rpc.MatStub(channel)

        self._lock = threading.Lock()
        self._decision_so_far = [
        ]  # history of the decision info from the server
        self._is_started = True  # control heartbeat
        self._new_response = []  # response list from the server
        self._new_request = []  # request list waiting to send to the server

        self.init_capital = -1
        self.logger = logger

        if self.logger is None:
            self.logger = simple_logger()

        self.stoped = False

        self.key = key
        self.logger.info('self.key is inited to ' + self.key)

        self.cond = threading.Condition()
        self.heart_beat_interval = 0.1

        self.question_dict = {}
        self.keys_file = {}
        self.init_questions()

        self.login(self.username, self.key)  # 这里是阻塞的,不登录无法进行游戏

        self._updater = threading.Thread(target=self.run)  # 维持heartbeat
        self._updater.setDaemon(True)
        self._updater.start()

        self._updater2 = threading.Thread(target=self.start)  # 维持通信处理
        self._updater2.setDaemon(True)
        self._updater2.start()
Beispiel #3
0
class ClientJob(object):
    def __init__(self, c):
        self.client = c

    def run(self):
        # print('run for client:%d'%(self.client.mypos))
        client_start(self.client)


#**********************************NOTICE**************************************
# You should make sure that your username is unique and can only contain letters, numbers and '_'.
# You should never keep more than one connection to the server at the same time.
#******************************************************************************

if __name__ == '__main__':
    # ************************************ modify here to use your own username! ***********************

    if len(sys.argv) == 1:
        print('Error: enter the name for the client!')
    #username = sys.argv[1]
    username = "******"
    logger = simple_logger()
    # ****************************************************************************************************

    # ************************************ modify here to use your own AI! ********************************

    c = Client(username, ai, logger)
    ClientJob(c).run()

# ****************************************************************************************************