private void FromVisualTreeToStateMachine()
    {
        List <JsonStateInput> states = new List <JsonStateInput>();

        GetStates(tree.treeRoot.transform, ref states, "");

        JsonInput stateMachine = new JsonInput();

        int depth = 0;

        foreach (var s in states)
        {
            if (s.path.Length > depth)
            {
                depth = s.path.Length;
            }

            //print ("path "+s.path);
            //print ("\ttprob0 "+s.probEvent0);
            //print ("\tprob1 "+s.probEvent1);
        }

        stateMachine.depth   = depth.ToString();
        stateMachine.choices = (3).ToString();
        //*stateMachine.limitValue = (80).ToString();
        stateMachine.states     = states.ToArray();
        stateMachine.limitPlays = playLimit.text;

        //Josi
        stateMachine.sequ = sequencia.text;

        currTreeStateMachine = stateMachine;
    }
Exemple #2
0
        public async Task <ActionResult <List <PlayerName> > > GetTeamVS(JsonInput j)
        {
            try
            {
                var inputTeams = j.Inputstr.Split(',').ToList();

                using var connection = db.con;
                connection.Open();
                var team1 = await connection.GetAsync <Player>(int.Parse(inputTeams[0]));

                var team2 = await connection.GetAsync <Player>(int.Parse(inputTeams[1]));

                var allGames = (await connection.QueryAsync <Game>
                                    ($"select * from games where (\"Player1\" = '{team1.PlayerId}' and \"Player2\" = '{team2.PlayerId}') or (\"Player1\" = '{team2.PlayerId}' and \"Player2\" = '{team1.PlayerId}')")).ToList();
                if (!allGames.Any())
                {
                    return(Ok(null));
                }

                var alignedList = new List <Game>();
                foreach (var game in allGames)
                {
                    if (game.Player2 == team1.PlayerId)
                    {
                        var substitute = new Game(game.Player2, game.Player1, game.Player2Goals, game.Player1Goals);
                        alignedList.Add(substitute);
                    }
                    else
                    {
                        alignedList.Add(game);
                    }
                }

                TeamVsTeam output = new TeamVsTeam();


                foreach (var game in alignedList)
                {
                    output.TotalGames += 1;
                    if (game.Player1Goals > game.Player2Goals)
                    {
                        output.TotalWins += 1;
                    }
                    else
                    {
                        output.TotalLosses += 1;
                    }
                    output.TotalGF += game.Player1Goals;
                    output.TotalGA += game.Player2Goals;
                }

                var toReturnJSON = JsonSerializer.Serialize(output);
                return(Ok(toReturnJSON));
            }
            catch (Exception)
            {
                return(BadRequest(null));
            }
        }
 void LoadTree(JsonInput stateMachine)
 {
     if (stateMachine.limitPlays != null)
     {
         playLimit.text = stateMachine.limitPlays;
         sequencia.text = stateMachine.sequ;                 //Josi
     }
     foreach (JsonStateInput s in stateMachine.states)
     {
         SetTree(s.path, new double[] { Convert.ToDouble(s.probEvent0), Convert.ToDouble(s.probEvent1) }, tree.treeRoot.GetComponent <VisualTreeNode>());
     }
 }
Exemple #4
0
        public ActionResult Login(LoginData data)
        {
            data.CanInstall = CanInstall();
            if (ModelState.IsValid)
            {
                var input = new JsonInput { { "username", data.UserName }, { "password", data.Password } };
                input.CommandName = "login";
                if (data.CanInstall)
                {
                    User user;
                    if (Game.Current.Users.TryGetUser(input, out user))
                    {
                        // User already created.
                        ModelState.AddModelError("Login", CommonResources.LoginAlreadyExists);
                    }

                    if (user == null)
                    {
                        // Try to create the user account.
                        user = new User
                                {
                                    AccessLevel = UserAccessLevel.God
                                };
                        Login login;
                        if (!Game.Current.Users.TryAddLogin(input, out login))
                        {
                            ModelState.AddModelError("Login", CommonResources.LoginAlreadyExists);
                        }
                        if (login != null)
                        {
                            user.Logins.Add(login);
                            Game.Current.Repository.SaveUser(user);
                        }
                    }
                }

                // Attempt to login.
                var response = ProcessInput(input);
                if (response != null && response.Success)
                {
                    Authorize((string) response.Data, data.RememberMe);

                    // Successful login
                    if (!string.IsNullOrEmpty(data.ReturnUrl))
                        return Redirect(data.ReturnUrl);
                    return RedirectToAction("index");
                }

                // Login failed
                ModelState.AddModelError("Login", response != null ? response.Error : CommonResources.LoginInvalid);
            }
            return View(data);
        }
Exemple #5
0
 public IHttpActionResult Post(JsonInput input)
 {
     try
     {
         var robotController = new JsonController();
         var result          = robotController.Execute(input);
         return(Json(result));
     }
     catch
     {
         return(InternalServerError());
     }
 }
Exemple #6
0
 public virtual async Task <Response> JsonInputAsync(JsonInput properties, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("XmlClient.JsonInput");
     scope.Start();
     try
     {
         return(await RestClient.JsonInputAsync(properties, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
Exemple #7
0
 public virtual Response JsonInput(JsonInput properties, CancellationToken cancellationToken = default)
 {
     using var scope = _clientDiagnostics.CreateScope("XmlClient.JsonInput");
     scope.Start();
     try
     {
         return(RestClient.JsonInput(properties, cancellationToken));
     }
     catch (Exception e)
     {
         scope.Failed(e);
         throw;
     }
 }
    public void SaveTree()
    {
        List <JsonStateInput> states = new List <JsonStateInput>();

        GetStates(tree.treeRoot.transform, ref states, "");

        JsonInput stateMachine;

        if (currTreeStateMachine == null)
        {
            stateMachine = new JsonInput();
        }
        else
        {
            stateMachine = currTreeStateMachine;
        }

        int depth = 0;

        foreach (var s in states)
        {
            if (s.path.Length > depth)
            {
                depth = s.path.Length;
            }

            // print ("path "+s.path);
            // print ("\ttprob0 "+s.probEvent0);
            // print ("\tprob1 "+s.probEvent1);
        }

        stateMachine.depth   = depth.ToString();
        stateMachine.choices = (3).ToString();
        //* stateMachine.limitValue = (80).ToString();
        stateMachine.states     = states.ToArray();
        stateMachine.limitPlays = playLimit.text;


        //Josi
        stateMachine.sequ = sequencia.text;


        string json = JsonWriter.Serialize(stateMachine);

        LoadedPackage.packages[loadedPackKey].stages[selectedIndex] = json;
        WriteTreeToFile(json);
    }
Exemple #9
0
        public async Task <ActionResult> DeletePlayer([FromBody] JsonInput j)
        {
            var delPlayer = new Player(j.Inputstr);

            using var connection = db.con;
            connection.Open();
            var checkIfExists = (await connection.QueryAsync <Player>
                                     ($"select * from players where \"TeamPlayerName\" = '{delPlayer.TeamPlayerName}' ")).ToList();

            if (!checkIfExists.Any())
            {
                return(BadRequest("Unable to delete the player"));
            }
            var repository = (await connection.DeleteAsync <Player>(checkIfExists[0]));

            return(Ok("Player removed successfully!"));
        }
Exemple #10
0
        public async Task <ActionResult> InsertPlayer(JsonInput j)
        {
            var inputParams = j.Inputstr.Split(',').ToList();
            var newPlayer   = new Player(inputParams[1]);

            if (inputParams[0] == "team")
            {
                newPlayer.IsTeam = true;
                newPlayer.P1     = int.Parse(inputParams[2]);
                newPlayer.P2     = int.Parse(inputParams[3]);
            }
            else
            {
                newPlayer.IsTeam = false;
                newPlayer.P1     = 0;
                newPlayer.P2     = 0;
            }
            using var connection = db.con;
            connection.Open();

            var checkIfExists = (await connection.QueryAsync <Player>
                                     ($"select * from players where \"TeamPlayerName\" = '{newPlayer.TeamPlayerName}' "));

            if (checkIfExists.Count() != 0)
            {
                return(BadRequest("Unable to add the player"));
            }

            if (newPlayer.IsTeam)
            {
                var checkIfCombo = (await connection.QueryAsync <Player>
                                        ($"select * from players where (\"P1\" = '{newPlayer.P1}' and \"P2\" = '{newPlayer.P2}') or (\"P1\" = '{newPlayer.P2}' and \"P2\" = '{newPlayer.P1}')"));

                if (checkIfCombo.Count() != 0)
                {
                    return(BadRequest($"Those players are already in a team"));
                }
            }
            var repository = (await connection.InsertAsync <Player>(newPlayer));

            if (repository != null)
            {
                return(Ok("Player added successfully!"));
            }
            return(BadRequest("Unable to add the player"));
        }
Exemple #11
0
    public void Answergot(string inputx)
    {
        // text = "北京天气";
        // string text1 = "{\"text\":\"" + text + "\"}";

        string url_param = "?charset=UTF-8&access_token=" + token;
        string url1      = baiduAPI + url_param;
        //   string json = @"{
        //'text':\"+inputx +" \"}";
        //json = json.Replace("'", "\"");
        JsonInput myobject = new JsonInput();

        myobject.text = inputx;
        string json1 = JsonUtility.ToJson(myobject);

        byte[] postData = System.Text.Encoding.UTF8.GetBytes(json1);
        WWW    www      = new WWW("https://" + url1, postData);

        StartCoroutine(WaitForRequest(www));
    }
    public void SaveTree()
    {
        List<JsonStateInput> states = new List<JsonStateInput>();

        GetStates(tree.treeRoot.transform, ref states, "");

        JsonInput stateMachine;

        if(currTreeStateMachine == null)
        {
            stateMachine = new JsonInput();
        }
        else
        {
            stateMachine = currTreeStateMachine;
        }

        int depth = 0;
        foreach(var s in states)
        {
            if(s.path.Length > depth)
            {
                depth = s.path.Length;
            }

            print ("path "+s.path);
            print ("\ttprob0 "+s.probEvent0);
            print ("\tprob1 "+s.probEvent1);
        }

        stateMachine.depth = depth.ToString();
        stateMachine.choices = (3).ToString();
        stateMachine.limitValue = (80).ToString();
        stateMachine.states = states.ToArray();
        stateMachine.limitPlays = playLimit.text;

        string json = JsonWriter.Serialize(stateMachine);
        LoadedPackage.packages[loadedPackKey].stages[selectedIndex] = json;
        WriteTreeToFile(json);
    }
 void SelectTreeByIndex(int index)
 {
     currTreeStateMachine = JsonFx.Json.JsonReader.Deserialize <JsonInput>(LoadedPackage.packages[loadedPackKey].stages[index]);
 }
    private void FromVisualTreeToStateMachine()
    {
        List<JsonStateInput> states = new List<JsonStateInput>();

        GetStates(tree.treeRoot.transform, ref states, "");

        JsonInput stateMachine = new JsonInput();

        int depth = 0;
        foreach(var s in states)
        {
            if(s.path.Length > depth)
            {
                depth = s.path.Length;
            }

            print ("path "+s.path);
            print ("\ttprob0 "+s.probEvent0);
            print ("\tprob1 "+s.probEvent1);
        }

        stateMachine.depth = depth.ToString();
        stateMachine.choices = (3).ToString();
        stateMachine.limitValue = (80).ToString();
        stateMachine.states = states.ToArray();
        stateMachine.limitPlays = playLimit.text;

        currTreeStateMachine = stateMachine;
    }
 void LoadTree(JsonInput stateMachine)
 {
     if(stateMachine.limitPlays != null)
     {
         playLimit.text = stateMachine.limitPlays;
     }
     foreach(JsonStateInput s in stateMachine.states)
     {
         SetTree(s.path, new double[]{Convert.ToDouble(s.probEvent0), Convert.ToDouble(s.probEvent1)}, tree.treeRoot.GetComponent<VisualTreeNode>());
     }
 }
Exemple #16
0
 // Because JsonInput implements the FubuMVC.Core.JsonMessage
 // marker interface, this endpoint will be configured as
 // "Asymmetric Json"
 public AjaxContinuation post_json_input(JsonInput input)
 {
     return(AjaxContinuation.Successful());
 }
 void SelectTreeByIndex(int index)
 {
     currTreeStateMachine = JsonFx.Json.JsonReader.Deserialize<JsonInput>(LoadedPackage.packages[loadedPackKey].stages[index]);
 }
Exemple #18
0
    void SetInitState(JsonInput t)
    {
        int max = t.states.Length;

        int r = Random.Range(0, max);

        currentState = t.states[r];
    }