示例#1
0
        public static void Step()
        {
            if (GamebotData.service_type == "SOCKET_VS_BT" || GamebotData.service_type == "SOCKET_VS_MULTIAGENT")
            {
                // 发送游戏状态
                GamebotData.game_request      = new Request();
                GamebotData.game_request.Step = GamebotData.step_request;

                if (GamebotData.train)
                {
                    GamebotService.SocketSend(client1, GamebotData.game_request);
                    // 判断游戏是否结束
                    if (GamebotData.step_request.Done == true)
                    {
                        SceneManager.LoadScene("MainScene");
                        // Debug.Log("Restart Game...");
                    }
                    else
                    {
                        // 接受传回来的动作
                        GamebotData.game_response1 = GamebotService.SocketResponse(client1);
                    }
                }
                // 清空proto信息
                GamebotData.step_request.Hero = new Hero();
            }
            else if (GamebotData.service_type == "SOCKET_VS_SOCKET")
            {
                // 发送游戏状态
                GamebotData.game_request      = new Request();
                GamebotData.game_request.Step = GamebotData.step_request;
                GamebotService.SocketSend(client1, GamebotData.game_request);

                // 判断游戏是否结束
                if (GamebotData.step_request.Done == true)
                {
                    SceneManager.LoadScene("MainScene");
                    // Debug.Log("Restart Game...");
                }
                else
                {
                    // 如果游戏没有结束再向第二个socket发送信息
                    GamebotService.SocketSend(client2, GamebotData.game_request);

                    // 接受传回来的动作
                    GamebotData.game_response1 = GamebotService.SocketResponse(client1);
                    GamebotData.game_response2 = GamebotService.SocketResponse(client2);
                }
                GamebotData.step_request.Hero = new Hero();
            }
            else if (GamebotData.service_type == "FILE")
            {
            }
            else if (GamebotData.service_type == "SOCKET")
            {
            }
            else if (GamebotData.service_type == "LIBRARY")
            {
                /*
                 *  // TF-lite for mnist: Start
                 *  interpreter.SetInputTensorData(0, inputs);
                 *  interpreter.Invoke();
                 *  interpreter.GetOutputTensorData(0, outputs);
                 *  for (int i = 0; i < outputs.Length; i++)
                 *  {
                 *      Debug.Log(outputs[i]);
                 *  }
                 *  GamebotData.game_response1.Step.Player[0].Jump = 1;
                 */
            }
            else
            {
            }
        }
示例#2
0
        public static void Reset()
        {
            if (GamebotData.service_type == "SOCKET_VS_BT" || GamebotData.service_type == "SOCKET_VS_MULTIAGENT")
            {
                // 发送初始化游戏状态
                GamebotData.game_request             = new Request();
                GamebotData.game_request.RestartGame = GamebotData.reset_request;

                if (GamebotData.train)
                {
                    GamebotService.SocketSend(client1, GamebotData.game_request);
                    // 接受传回来的动作或者游戏退出的请求
                    GamebotData.game_response1 = GamebotService.SocketResponse(client1);

                    // 如果请求是退出则退出游戏
                    switch (GamebotData.game_response1.ResponseCase)
                    {
                    case Response.ResponseOneofCase.Quit:
                        GamebotService.client1.Close();
                        Application.Quit();
                        break;

                    default:
                        break;
                    }
                }
            }
            else if (GamebotData.service_type == "SOCKET_VS_SOCKET")
            {
                // 发送初始化游戏状态
                GamebotData.game_request             = new Request();
                GamebotData.game_request.RestartGame = GamebotData.reset_request;
                GamebotService.SocketSend(client1, GamebotData.game_request);

                // 接受传回来的动作或者游戏退出的响应
                GamebotData.game_response1 = GamebotService.SocketResponse(client1);

                // 如果响应是退出则退出游戏
                switch (GamebotData.game_response1.ResponseCase)
                {
                case Response.ResponseOneofCase.Quit:
                    // 向第二两个端口发送游戏结束指令
                    GamebotData.game_request      = new Request();
                    GamebotData.game_request.Quit = GamebotData.game_quit;
                    GamebotService.SocketSend(client2, GamebotData.game_request);

                    GamebotService.client1.Close();
                    GamebotService.client2.Close();
                    Application.Quit();
                    break;

                default:
                    break;
                }

                GamebotService.SocketSend(client2, GamebotData.game_request);
                GamebotData.game_response2 = GamebotService.SocketResponse(client2);
            }
            else if (GamebotData.service_type == "FILE")
            {
            }
            else if (GamebotData.service_type == "SOCKET")
            {
            }
            else if (GamebotData.service_type == "LIBRARY")
            {
            }
            else
            {
            }
        }