Exemplo n.º 1
0
        public async Task Bot_Cannot_MoveForward_With_North_Orientation_On_1x1_Arena( )
        {
            // Arrange
            Arena arena = new Arena {
                Width = 1, Height = 1
            };
            Team team = new Team {
                Name = "Team!"
            };
            Bot bot = new Bot {
                LocationX = 0, LocationY = 0, Orientation = Orientation.North, MaximumStamina = 1, CurrentStamina = 1, StaminaDrain = 0
            };
            Deployment deployment = new Deployment {
                Arena = arena, Team = team, Bot = bot
            };

            bot.Deployments = (new[] { deployment }).ToList( );

            Script botScript = await BotScript.PrepareScript("MoveForward();".Base64Encode( ));

            botScript.Compile( );
            ScriptGlobals globals = new ScriptGlobals(arena, bot, new List <Bot>( ));

            // Act
            await botScript.RunAsync(globals);

            // Assert
            Assert.AreEqual(0, globals.LocationX);
            Assert.AreEqual(0, globals.LocationY);
            Assert.AreEqual(1, globals.Stamina);
            Assert.AreEqual(0, globals.StaminaDrain);
        }
 protected async void OnValidateBotScript()
 {
     await BusyAndExceptionHandling(async() =>
     {
         ScriptValidation = await _scriptClient.ValidateScript(new ScriptDto {
             Script = BotScript.Base64Encode()
         });
         ScriptValid = ScriptValidation.Messages.Count == 0;
     });
 }
Exemplo n.º 3
0
        private async Task <Script> GetCompiledBotScript(Bot bot)
        {
            if (!_cache.ScriptStored(bot))
            {
                var botScript = await BotScript.PrepareScript(bot.Script);

                botScript.Compile();
                _cache.StoreScript(bot, botScript);
            }

            return(_cache.LoadScript(bot));
        }
Exemplo n.º 4
0
        private void botGenerateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dictionary <String, object> inputs = ParseInputs(variableInput.Text);

            computerScript = new BotScript(inputs.Keys, inputs.Keys, OPERATORS, 20);

            codeInput.Text = "";
            foreach (String line in computerScript.getLines())
            {
                codeInput.Text += line + Environment.NewLine;
            }
        }
Exemplo n.º 5
0
 protected override void Start()
 {
     base.Start();
     soundLevelSlider.value = StaticClass.soundLevel;
     fxLevelSlider.value    = StaticClass.fxLevel;
     foodSound           = GetComponent <AudioSource>();
     skillText.text      = "Пробел для ускорения";
     botScript           = GameObject.Find("Bot").GetComponent <BotScript> ();
     numberOfPointsToWin = 200;
     interpPower         = 5f;
     StartCoroutine("Timer");
     SetCountText();
 }
Exemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     if (botInstance == null)
     {
         botInstance = this;
     }
     else
     {
         Destroy(gameObject);
     }
     myAnimator = GetComponent <Animator>();
     myRgb      = GetComponent <Rigidbody>();
     for (int i = 0; i < 7; i++)
     {
         bodysHealths[i] = 255f;
     }
 }
 private async void OnDeployBot()
 {
     await BusyAndExceptionHandling(async() =>
     {
         if (await _deploymentClient.Available(CurrentTeam.Name, SelectedArena.Name))
         {
             var bot = await _botClient.CreateBot(new BotDto
             {
                 Name                  = BotName,
                 Script                = BotScript.Base64Encode(),
                 LocationX             = 0,
                 LocationY             = 0,
                 Orientation           = OrientationDto.North,
                 MaximumPhysicalHealth = BotPhysicalHealth,
                 CurrentPhysicalHealth = BotPhysicalHealth,
                 MaximumStamina        = BotStamina,
                 CurrentStamina        = BotStamina,
                 LastAttackLocationX   = 0,
                 LastAttackLocationY   = 0
             });
             if (bot != null)
             {
                 var deployment = await _deploymentClient.Deploy(new DeploymentDto
                 {
                     ArenaName = SelectedArena.Name,
                     BotName   = BotName,
                     TeamName  = CurrentTeam.Name
                 });
                 if (deployment != null)
                 {
                     //BotName = "";
                     //BotScript = "";
                     //BotPhysicalHealth = 32000;
                     //BotMentalHealth = 32000;
                     //BotStamina = 32000;
                 }
             }
             RefreshArenas();
         }
         else
         {
             throw new ClientException("New deployment cannot be done. Deployment restriction applies!");
         }
     });
 }
Exemplo n.º 8
0
    public void Set(string player, int place, int index, int points, bool isSubscriber)
    {
        if (first)
        {
            trophyImage        = trophy.GetComponent <Image>();
            canvasGroup        = GetComponent <CanvasGroup>();
            canvasGroup.alpha  = 0;
            currentTrophy      = place;
            trophyImage.sprite = TROPHY_SPRITES[place];
        }
        targetTrophy = place;
        name         = player;
        tmpName.text = "<color=#" + ColorUtility.ToHtmlStringRGB(viewerNameColor) + ">" + player + "</color> - " + points + " pts";
        if (place > 0)
        {
            particles.Stop();
        }
        else if (!particles.isPlaying)
        {
            particles.Play();
        }
        if (botScript == null)
        {
            botScript = GameObject.FindGameObjectWithTag("BotScript").GetComponent <BotScript>();
        }
        // Set is actually getting called every frame on every leaderboard row, so this is pretty jank.
        if (isSubscriber)
        {
            sub = true;
        }
        targetX = (index % 2 == 0) ? 0 : -0.8f;
        targetY = -1.05f * index;

        if (first)
        {
            transform.localPosition = new Vector3(targetX + 1, targetY);
        }
        first      = false;
        destroying = false;
    }
Exemplo n.º 9
0
 private void Start()
 {
     DM = FindObjectOfType <DialogueManager>().GetComponent <DialogueManager>();
     BS = FindObjectOfType <BotScript>().GetComponent <BotScript>();
 }
Exemplo n.º 10
0
    void Update()
    {
        // left mouse button pressed?
        if (Input.GetMouseButtonDown(0))
        {
            // raycast
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                BotInfo hitBot = hit.collider.GetComponent <BotInfo>();
                if (hitBot != null && hitBot.IsMine)
                {
                    // select bot
                    SelectedBot = hitBot.GetComponent <BotScript>();
                }
            }
        }

        if (!GetComponent <BotInfo>().IsMine)
        {
            return;
        }

// current target not null? move towards and attack
        if (targetEnemy != null)
        {
            moveTowards(targetEnemy.transform.position, 2f);
            targetMovePos = transform.position;

            // close enough to target? attack
            if (Vector3.Distance(transform.position, targetEnemy.transform.position) <= 2f)
            {
                attackTimer += Time.deltaTime;
                if (attackTimer >= 1f)
                {
                    attackTimer = 0f;
                    // send damage message
                    NetworkUtils.connection.Send("TakeDamage", targetEnemy.BotID);
                }
            }
        }
        else
        {
            moveTowards(targetMovePos, 0.5f);
        }

        if (SelectedBot != this)
        {
            return;
        }

        // right mouse button pressed?
        if (Input.GetMouseButtonDown(1))
        {
            // raycast
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                BotInfo hitBot = hit.collider.GetComponent <BotInfo>();
                if (hitBot != null && !hitBot.IsMine)
                {
                    // target selected bot
                    targetEnemy = hitBot;
                }
                else if (hitBot == null)
                {
                    // move to position
                    targetMovePos = hit.point;
                }
            }
        }
    }
Exemplo n.º 11
0
 public Result(float score, BotScript script)
 {
     this.score  = score;
     this.script = script;
 }
Exemplo n.º 12
0
        public async Task <IActionResult> ValidateScript([FromBody] ScriptDto script)
        {
            ScriptValidationDto scriptValidation = await BotScript.ValidateScript(script.Script);

            return(Ok(scriptValidation));
        }