コード例 #1
0
        public void OnEndTurn()
        {
            if (IsLocked())
            {
                return;
            }

            // Save and run model
            if (fileMenu.ExternalSave())
            {
                // Block input
                gridPlacement.AddLock(this);
                AddLock(this);

                // Open prompt
                dialogueMenu.OpenDialogue(Dialogue.AIThinking);

                // Run process
                process = new Process();

                process.StartInfo.FileName         = "python";
                process.StartInfo.Arguments        = "runmodel.py ../Levels/" + fileMenu.LevelName + ".csv";
                process.StartInfo.WorkingDirectory = Application.dataPath + "/StreamingAssets/Model";
                process.StartInfo.CreateNoWindow   = true;
                process.StartInfo.UseShellExecute  = false;

                process.Start();
                StartCoroutine(EndTurnCoroutine(process));
            }
        }
コード例 #2
0
        public void OnEndTurn()
        {
            gridObjects = new List <GridObject>();
            if (IsLocked)
            {
                return;
            }

            // Block input
            gridPlacement.AddLock(this);

            //Save
            bool saved = fileMenu.ExternalSave();

            LogHandler.Instance.WriteLine("Ended Turn:  time = " + Time.time);

            //Open Prompt
            dialogueMenu.OpenDialogue(Dialogue.AIThinking);

            // Run model
            if (saved)
            {
                string[] lines   = File.ReadAllLines(Constants.directory + "/StreamingAssets/Levels/" + fileMenu.LevelName + ".csv");
                string   toSend  = "";
                bool     readRow = false;
                int      finalX  = int.Parse(lines[lines.Length - 1].Split(new char[] { ',' })[1]);
                startX = finalX - 20;

                if (startX < 0)
                {
                    startX = 0;
                }

                if (startX + 40 >= 100)
                {
                    startX -= (startX + 40) - 99;
                }

                foreach (string line in lines)
                {
                    if (readRow)
                    {
                        string[] splitLine = line.Split(new char[] { ',' });
                        int      thisX     = int.Parse(splitLine[1]);
                        if (thisX >= startX && thisX < startX + 40)
                        {
                            toSend += (thisX - startX) + "*" + splitLine[2] + "*" + Array.IndexOf(allNames, splitLine[0]) + "-";
                        }
                    }
                    else
                    {
                        readRow = true;
                    }
                }

                toSend += "|" + startX;

                if (socketConnection == null)
                {
                    socketConnection = new TcpClient("127.0.0.1", 5015);
                }
                try {
                    // Get a stream object for writing.
                    NetworkStream stream = socketConnection.GetStream();
                    if (stream.CanWrite)
                    {
                        // Convert string message to byte array.
                        byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(toSend);
                        // Write byte array to socketConnection stream.
                        stream.Write(clientMessageAsByteArray, 0, clientMessageAsByteArray.Length);
                    }
                }
                catch (SocketException socketException) {
                    UnityEngine.Debug.Log("Socket exception: " + socketException);
                }
                StartCoroutine(EndTurnCoroutine());
            }
        }