예제 #1
0
        public async void Start(IBotCommands botCommands)
        {
            while (true)
            {
                var direction = (Direction)Random.Range(0, 4);
                var addvec    = new Vector2[]
                {
                    Vector2.up, Vector2.down, Vector2.left, Vector2.right
                }[(int)direction];
                var myPosition = await botCommands.GetMyPosition();

                var tileType =
                    await botCommands.GetTileType(new GridPosition((int)(myPosition.X + addvec.x),
                                                                   (int)(myPosition.Y + addvec.y)));

                if (tileType != TileType.Hole)
                {
                    await botCommands.Move(direction, 1);
                }


                if (Random.Range(0, 100) == 50)
                {
                    botCommands.Shot();
                    await botCommands.MoveShotRotation(Random.Range(0, 360));
                }
            }
        }
예제 #2
0
        private Engine CreateEngine(CancellationToken cancellationToken, int processId)
        {
            var engine = new Engine(options => { options.DebugMode(); });

            engine.Step += (s, e) =>
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    throw new OperationCanceledException();
                }
                return(StepMode.Into);
            };
            engine.SetValue("KeyCode", TypeReference.CreateTypeReference(engine, typeof(KeyCode)));
            engine.SetValue("GetKey", new Func <KeyCode, bool>(code =>
            {
                var task = botCommands.GetKey(code);
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("GetKeyDown", new Func <KeyCode, bool>(code =>
            {
                var task = botCommands.GetKeyDown(code);
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("GetKeyUp", new Func <KeyCode, bool>(code =>
            {
                var task = botCommands.GetKeyUp(code);
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("Dir", TypeReference.CreateTypeReference(engine, typeof(Direction)));
            engine.SetValue("Pos", TypeReference.CreateTypeReference(engine, typeof(GridPosition)));
            engine.SetValue("TileType", TypeReference.CreateTypeReference(engine, typeof(TileType)));
            engine.SetValue("Coroutine",
                            new Action <uint, JsValue>((frameTime, jsfunc) =>
            {
                botCommands.Coroutine(frameTime, () => jsfunc.Invoke());
            }));
            engine.SetValue("Shot", new Action(() => botCommands.Shot()));
            engine.SetValue("Attack", new Action(() => botCommands.MeleeAttack()));

            engine.SetValue("Move", new Action <Direction, uint>((dir, mass) =>
                                                                 botCommands.Move(dir, mass).Wait()
                                                                 ));
            engine.SetValue("MoveDir", new Action <Direction>(dir =>
                                                              botCommands.MoveDirection(dir).Wait()
                                                              ));
            engine.SetValue("ShotDir", new Action <float>(dir =>
                                                          botCommands.MoveShotRotation(dir).Wait()
                                                          ));
            engine.SetValue("GetMyPos", new Func <GridPosition>(() =>
            {
                var task = botCommands.GetMyPosition();
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("GetPosAngle", new Func <GridPosition, float>(pos =>
            {
                var task = botCommands.GetPositionAngle(pos);
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("GetTileType", new Func <GridPosition, TileType>(pos =>
            {
                var task = botCommands.GetTileType(pos);
                task.Wait();
                return(task.Result);
            }));
            engine.SetValue("Print", new Action <object>(obj =>
                                                         ConsoleLogger.Log(DateTime.Now, processId, obj)
                                                         ));
            engine.SetValue("Wait", new Action <int>((milliSeconds) => Task.Delay(milliSeconds).Wait()));
            return(engine);
        }
 public Task <GridPosition> GetMyPosition()
 {
     return(botCommands.GetMyPosition());
 }