コード例 #1
0
    public override void onServerAwake()
    {
        base.onServerAwake();

        this.attack     = this.createAttackMethod();
        this.moveHelper = new MoveHelper(this);
    }
コード例 #2
0
 public override void DoWork()
 {
     FlyingEngine.Navigator.Stop();
     MoveHelper.ReleaseKeys();
     Main.CombatEngine.RunningAction();
     Mount.MountUp();
 }
コード例 #3
0
        public void keepPlayingEvenWhenLostSimpler()
        {
            /*
             * Starting position (Black to play)
             +---------------+
             |_ _ _ _ _ _ _ k| 8
             |p R p _ _ _ p _| 7
             |P p P _ _ _ P _| 6
             |_ P _ _ _ _ p _| 5
             |_ _ _ _ _ _ _ _| 4
             |_ _ _ _ _ _ _ _| 3
             |_ _ _ _ _ _ _ _| 2
             |_ _ _ _ _ _ _ _| 1
             +---------------+
             * A B C D E F G H
             */
            var board = BoardFactory.LoadBoardFromFen("7k/pRp3p1/PpP3P1/1P4p1/8/8/8/8 b - - 0 1");

            var moves = board.GetMoves();

            var aiWorkers = new AIWorkerManager();

            aiWorkers.spawnWorkers(3);
            aiWorkers.analyzeBoard(board, 2).Wait();
            aiWorkers.killWorkers();
            EvaluatedMove foundMove = aiWorkers.GetBestMove();

            Assert.IsTrue(MoveHelper.isValidMove(foundMove.move));
        }
コード例 #4
0
        public void keepPlayingEvenWhenLost()
        {
            /*
             * Starting position (Black to play)
             +---------------+
             |B _ _ _ _ _ _ _| 8
             |_ _ _ _ _ P R p| 7
             |_ _ _ _ N _ _ k| 6
             |_ _ _ p _ _ p _| 5
             |_ _ _ _ _ _ _ _| 4
             |_ _ _ _ P _ P _| 3
             |P _ _ _ _ _ K _| 2
             |_ _ _ _ _ _ _ _| 1
             +---------------+
             * A B C D E F G H
             */
            var board = BoardFactory.LoadBoardFromFen("B7/5PRp/4N2k/3p2p1/8/4P1P1/P5K1/8 b - - 0 2");

            var moves = board.GetMoves();


            var aiWorkers = new AIWorkerManager();

            aiWorkers.spawnWorkers(3);
            aiWorkers.analyzeBoard(board, 5).Wait();
            aiWorkers.killWorkers();
            EvaluatedMove foundMove = aiWorkers.GetBestMove();

            Assert.IsTrue(MoveHelper.isValidMove(foundMove.move));
        }
コード例 #5
0
        public void keepPlayingEvenWhenLostSimpler()
        {
            /*
             * Starting position (Black to play)
             +---------------+
             |_ _ _ _ _ _ _ k| 8
             |p R p _ _ _ p _| 7
             |P p P _ _ _ P _| 6
             |_ P _ _ _ _ p _| 5
             |_ _ _ _ _ _ _ _| 4
             |_ _ _ _ _ _ _ _| 3
             |_ _ _ _ _ _ _ _| 2
             |_ _ _ _ _ _ _ _| 1
             +---------------+
             * A B C D E F G H
             */
            var board = BoardFactory.LoadBoardFromFen("7k/pRp3p1/PpP3P1/1P4p1/8/8/8/8 b - - 0 1");

            var moves = board.GetMoves();

            var           minmax    = new MinMaxAI();
            EvaluatedMove foundMove = minmax.MinMaxList(board, 2)[0];

            Assert.IsTrue(MoveHelper.isValidMove(foundMove.move));
        }
コード例 #6
0
ファイル: Location.cs プロジェクト: catontheway/myevo
        public static void FaceAngle(float angle)
        {
            float face;

            if (LazyMath.NegativeAngle(angle - ObjectManager.MyPlayer.Facing) < Math.PI)
            {
                face = LazyMath.NegativeAngle(angle - ObjectManager.MyPlayer.Facing);
                bool moving = ObjectManager.MyPlayer.IsMoving;
                if (face > 1)
                {
                    MoveHelper.ReleaseKeys();
                    moving = false;
                }
                FaceHorizontalWithTimer(face, "Left", moving);
            }
            else
            {
                face = LazyMath.NegativeAngle(ObjectManager.MyPlayer.Facing - angle);
                bool moving = ObjectManager.MyPlayer.IsMoving;
                if (face > 1)
                {
                    MoveHelper.ReleaseKeys();
                    moving = false;
                }
                FaceHorizontalWithTimer(face, "Right", moving);
            }
        }
コード例 #7
0
        private static void GotoRepair(List <Entity> builders, List <Entity> facilities)
        {
            foreach (Entity facility in facilities)
            {
                List <Point> repairPoints = Helper.GetFacilityTerritory(facility, p =>
                {
                    Tile tile = World.Get(p);
                    return(tile.CanMoveHere && !tile.Attacked);
                });

                (Entity builder, Point repairPoint, int distance) = Helper.FindNearest(builders, repairPoints);
                if (builder == null)
                {
                    continue;
                }

                if (facility.RepairesCount > 0)
                {
                    int ticksToRepair = (facility.MaxHealth - facility.Health) / facility.RepairesCount;
                    if (ticksToRepair < 1.5 * distance)
                    {
                        return;
                    }
                }

                MoveHelper.Move(builder, repairPoint);
                builders.Remove(builder);
            }
        }
コード例 #8
0
ファイル: UnitBase.cs プロジェクト: CodeShaper13/BattleGame
        protected override void onStart()
        {
            base.onStart();

            this.moveHelper = new MoveHelper(this);
            this.setTask(null);
        }
コード例 #9
0
ファイル: DangerDodger.cs プロジェクト: Buddyfu/DangerDodger
        public async Task <bool> PerformKiting(IEnumerable <CachedNetworkObject> dangerousObjects, CachedNetworkObject nearestThreat, float dangerRadius, Stopwatch stopwatchToReset = null)
        {
            if (dangerousObjects.Any())
            {
                if (nearestThreat != null && nearestThreat.Distance <= dangerRadius)
                {
                    Log.InfoFormat("[DangerDodger] Initiating kiting.");
                    List <Vector2> positions    = dangerousObjects.Select(o => o.Position.ToVector2()).ToList();
                    Vector2        dangerCenter = GeometryHelper.getAveragePoint(positions);
                    Log.InfoFormat("[DangerDodger] NearestThreat.Name: [{0}], NearestThreat.Position: [{1}], DangerCenter: [{2}]", nearestThreat.Name, nearestThreat.Position, dangerCenter);
                    //The escape angle represents the shortest way out of the danger.
                    double   escapeAngle = GeometryHelper.getAngleBetweenPoints(dangerCenter, LokiPoe.Me.Position.ToVector2());
                    Vector2i newPosition = MoveHelper.CalcSafePosition(escapeAngle, DangerDodgerSettings.Instance.StepLength);

                    if (newPosition != LokiPoe.Me.Position)
                    {
                        //PlayerMover.MoveTowards(newPosition) Does not seem to work when the character is busy.
                        Log.InfoFormat("[DangerDodger] Kiting towards a safer position. CurrentPosition: [{0}], NewPosition: [{1}]", LokiPoe.Me.Position, newPosition);
                        if (!await Coroutines.MoveToLocation(newPosition, 5, 1000))
                        {
                            Log.ErrorFormat("[DangerDodger] Error kiting towards safe position. ");
                        }
                    }
                    return(true);
                }
            }
            else
            {
                if (stopwatchToReset != null)
                {//In some cases, we don't restart the stopwatch when the threat is still nearby. The bot could decide to go pick up some item in the middle of danger zone at any moment ;.;
                    stopwatchToReset.Restart();
                }
            }
            return(false);
        }
コード例 #10
0
ファイル: PVEBehaviorCombat.cs プロジェクト: semi420/lazybot
 public override PullResult Pull(PUnit target)
 {
     //Logging.Debug("Pull started");
     Buff();
     PrePull(target);
     if (Behavior.UseAutoAttack)
     {
         target.InteractWithTarget();
     }
     if (!MoveHelper.MoveToUnit(target, Behavior.PullDistance))
     {
         return(PullResult.CouldNotPull);
     }
     if (Behavior.SendPet)
     {
         PetAttackKey.SendKey();
     }
     foreach (Rule rule in Behavior.PullController.GetRules.Where(rule => rule.IsOk))
     {
         target.Face();
         rule.ExecuteAction(Behavior.GlobalCooldown);
     }
     // Logging.Debug("Pull done");
     if (PPullBlackList.IsBlacklisted(target))
     {
         return(PullResult.CouldNotPull);
     }
     return(PullResult.Success);
 }
コード例 #11
0
        private static void MoveExtentLeft(List<DynamicDisk> disks, DynamicVolume volume, MoveExtentOperationBootRecord resumeRecord, ref long bytesCopied)
        {
            DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(disks, volume.DiskGroupGuid);
            if (database == null)
            {
                throw new DatabaseNotFoundException();
            }

            DynamicDiskExtent relocatedExtent = DynamicDiskExtentHelper.GetByExtentID(volume.DynamicExtents, resumeRecord.ExtentID);
            if (resumeRecord.OldStartSector == (ulong)relocatedExtent.FirstSector)
            { 
                // the database update was not completed (this must be a resume operation)
                relocatedExtent = new DynamicDiskExtent(relocatedExtent.Disk, (long)resumeRecord.NewStartSector, relocatedExtent.Size, resumeRecord.ExtentID);
                VolumeManagerDatabaseHelper.UpdateExtentLocation(database, volume, relocatedExtent);
            }

            DiskExtent sourceExtent = new DiskExtent(relocatedExtent.Disk, (long)resumeRecord.OldStartSector, relocatedExtent.Size);

            MoveHelper.MoveExtentDataLeft(volume, sourceExtent, relocatedExtent, resumeRecord, ref bytesCopied);
            
            // if this is a resume, then volume is StripedVolume, otherwise it is a Raid5Volume
            if (resumeRecord.RestoreRAID5)
            {
                VolumeManagerDatabaseHelper.ConvertStripedVolumeToRaid(database, volume.VolumeGuid);
                // get the updated volume (we just reconverted to RAID-5)
                volume = DynamicVolumeHelper.GetVolumeByGuid(disks, volume.VolumeGuid);
            }
            
            // restore the filesystem boot sector
            byte[] filesystemBootRecord = relocatedExtent.Disk.ReadSector((long)resumeRecord.BootRecordBackupSector);
            volume.WriteSectors(0, filesystemBootRecord);

            ClearBackupData(relocatedExtent.Disk, resumeRecord);
        }
コード例 #12
0
        public override void DoWork()
        {
            FlyingEngine.Navigator.Stop();
            if (ApproachPosFlying.Approach(_npc.Location, 12))
            {
                MoveHelper.MoveToLoc(_npc.Location, 3);
                //VendorManager.DoSell(_npc);

                while (!ObjectManager.MyPlayer.Target.Name.Equals(_npc.Name))
                {
                    // 目标选择NPC
                    KeyHelper.SendLuaOverChat("/target " + _npc.Name);
                    Thread.Sleep(500);
                }

                _npc.Interact();
                Thread.Sleep(500);

                // 卖东西
                SpyFrame.ExecSimpleLua("/script SellJunk:Sell()");
                Thread.Sleep(500);

                // 修理
                SpyFrame.ExecSimpleLua("/click MerchantRepairAllButton");
            }
            FlyingBlackList.Blacklist(_npc, 200, true);
            Logging.Write("[Vendor]Vendor done");
        }
コード例 #13
0
 public virtual void LogicSelfBuff()
 {
     try
     {
         _queuedBuffs.Clear();
         SelfBuffActions.Sort();
         foreach (PAction selfBuffAction in
                  SelfBuffActions.Where(
                      selfBuffAction =>
                      selfBuffAction.IsWanted && (selfBuffAction.IsReady || selfBuffAction.WaitUntilReady)))
         {
             _queuedBuffs.Add(selfBuffAction);
         }
         if (_queuedBuffs.Count != 0)
         {
             MoveHelper.ReleaseKeys();
         }
         foreach (PAction queuedBuff in _queuedBuffs)
         {
             queuedBuff.Execute();
         }
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception e)
     {
         Log("Error in LogicSelfBuff please check class code: " + e);
     }
 }
コード例 #14
0
ファイル: AIWorkerTest.cs プロジェクト: frit007/ParallelChess
        public static void fourWorkersFindCheckMate()
        {
            /*
             * Starting position (White to play)
             +---------------+
             |r n b k _ _ r _| 8
             |p p p p _ p B p| 7
             |_ _ _ q _ _ _ _| 6
             |_ _ _ _ _ _ _ _| 5
             |_ _ B _ _ _ Q _| 4
             |_ _ _ _ _ _ _ _| 3
             |P _ _ _ _ _ P P| 2
             |R _ _ _ R _ K _| 1
             +---------------+
             * A B C D E F G H
             */
            var board = BoardFactory.LoadBoardFromFen("rnbk2r1/pppp1pBp/3q4/8/2B3Q1/8/P5PP/R3R1K1 w - - 0 1");

            var moves = board.GetMoves();

            var ai = new AIWorkerManager();

            ai.spawnWorkers(1);
            ai.analyzeBoard(board, 3).GetAwaiter().GetResult();
            //BestMove foundMove = MinMaxAI.MinMaxList(board, 3)[0];

            Assert.AreEqual(BoardStateOffset.F6, ai.GetBestMove().move.targetPosition);
            //var board = BoardFactory.LoadBoardFromFen();


            Assert.IsTrue(MoveHelper.isValidMove(ai.GetBestMove().move));
        }
コード例 #15
0
ファイル: Location.cs プロジェクト: catontheway/myevo
        /// <summary>
        ///   让打架赛车面朝制定目标
        /// </summary>
        /// <param name = "打架赛车的PUnit">The pos.</param>
        /// <returns></returns>
        public void MFace(PUnit mObj)
        {
            float face;

            if (LazyMath.NegativeAngle(AngleHorizontal - mObj.Facing) < Math.PI)
            {
                face = LazyMath.NegativeAngle(AngleHorizontal - mObj.Facing);

                bool moving = mObj.IsMoving;
                if (face > 1)
                {
                    MoveHelper.ReleaseKeys();
                    moving = false;
                }
                FaceHorizontalWithTimer(face, "Left", moving);
            }
            else
            {
                face = LazyMath.NegativeAngle(mObj.Facing - AngleHorizontal);

                bool moving = mObj.IsMoving;
                if (face > 1)
                {
                    MoveHelper.ReleaseKeys();
                    moving = false;
                }
                FaceHorizontalWithTimer(face, "Right", moving);
            }
        }
コード例 #16
0
        public static bool Approach(Location location, int distance)
        {
            var    timeout = new Ticker(6000);
            double num2    = location.DistanceToSelf;

            MoveHelper.StopMove();
            location.Face();
            FlyingEngine.Navigator.Start();
            FlyingEngine.Navigator.SetDestination(location);
            while (location.DistanceToSelf2D > distance)
            {
                if (timeout.IsReady)
                {
                    FlyingEngine.Navigator.Stop();
                    return(false);
                }
                if (location.DistanceToSelf < num2)
                {
                    num2 = location.DistanceToSelf;
                    timeout.Reset();
                }
                if (location.DistanceToSelf < distance)
                {
                    FlyingEngine.Navigator.Stop();
                }
                Thread.Sleep(10);
            }
            FlyingEngine.Navigator.Stop();
            Descent();
            return(true);
        }
コード例 #17
0
        private static void Descent()
        {
            var ticker = new Ticker(6000);

            MoveHelper.Down(true);
            if (ObjectManager.MyPlayer.InVashjir)
            {
                //ugly vashjir method
                var      timerDiff = new Ticker(1000);
                float    diffSelf  = 3;
                Location oldPos    = ObjectManager.MyPlayer.Location;
                while (!ticker.IsReady && diffSelf > 0.3)
                {
                    if (timerDiff.IsReady)
                    {
                        diffSelf = MoveHelper.NegativeValue(oldPos.Z - ObjectManager.MyPlayer.Location.Z);
                        timerDiff.Reset();
                        oldPos = ObjectManager.MyPlayer.Location;
                    }
                    Thread.Sleep(10);
                }
            }
            else
            {
                while (ObjectManager.MyPlayer.IsFlying && !ticker.IsReady)
                {
                    Thread.Sleep(10);
                }
            }
            MoveHelper.Down(false);
        }
コード例 #18
0
ファイル: Unstuck.cs プロジェクト: semi420/lazybot
        internal static void TryUnstuck()
        {
            Logging.Write(LogType.Warning, "Stuck");
            Thread.Sleep(2000);
            MoveHelper.ReleaseKeys();
            if (_lastStuckTickcount + 5000 < Environment.TickCount)
            {
                Logging.Debug("Jump");
                MoveHelper.Forwards(true);
                MoveHelper.Jump();
                MoveHelper.Forwards(false);
                Thread.Sleep(1500);
            }
            else
            {
                Logging.Debug("Lets unstuck");
                MoveHelper.ReleaseKeys();
                if (_lastStuckDirection)
                {
                    MoveHelper.RotateLeft(true);
                }
                else
                {
                    MoveHelper.RotateRight(true);
                }

                _lastStuckDirection = !_lastStuckDirection;
                Thread.Sleep(500);
                MoveHelper.ReleaseKeys();
                MoveHelper.Forwards(true);
                Thread.Sleep(1000);
                MoveHelper.Forwards(false);
            }
            _lastStuckTickcount = Environment.TickCount;
        }
コード例 #19
0
        public static void Coward(List <Entity> builders)
        {
            List <Entity> defenders = World.All(u => u.My && u.CanAttack);

            foreach (Entity builder in builders.ToList())
            {
                Point position = builder.Position;

                if (!World.Get(position).Attacked)
                {
                    continue;
                }

                var safePositions = new List <Point>(4);
                TryAdd(safePositions, position.Left);
                TryAdd(safePositions, position.Right);
                TryAdd(safePositions, position.Up);
                TryAdd(safePositions, position.Down);

                if (safePositions.Count == 0)
                {
                    return; // fatal, no way
                }

                Point safePosition = SelectSafePosition(safePositions, defenders);
                MoveHelper.Move(builder, safePosition);
                builders.Remove(builder);
            }
        }
コード例 #20
0
ファイル: Resurrect.cs プロジェクト: semi420/lazybot
        internal static void Pulse()
        {
            if (CorpsePosition.X == 0 && CorpsePosition.Y == 0 && CorpsePosition.Z == 0)
            {
                GrindingEngine.Navigator.Stop();
                MoveHelper.ReleaseKeys();
                CorpsePosition = ObjectManager.MyPlayer.Location;
                GrindingEngine.UpdateStats(0, 0, 1);
            }
            while (!ObjectManager.MyPlayer.IsGhost)
            {
                Thread.Sleep(1000);
                Frame staticPopup1Button1 = InterfaceHelper.GetFrameByName("StaticPopup1Button1");
                if (staticPopup1Button1 != null && staticPopup1Button1.IsVisible)
                {
                    staticPopup1Button1.LeftClick();
                    Thread.Sleep(2000);
                }
                Thread.Sleep(100);
            }
            if (GrindingEngine.Navigation.SpotToHit != CorpsePosition)
            {
                GrindingEngine.Navigation.SetNewSpot(CorpsePosition);
            }
            GrindingEngine.Navigation.Pulse();
            if (GrindingEngine.Navigation.IsLastWaypoints || CorpsePosition.DistanceToSelf2D < 20)
            {
                Logging.Write("Move to our corpse");
                GrindingEngine.Navigator.Stop();
                MoveHelper.ReleaseKeys();

                MoveHelper.MoveToLoc(CorpsePosition, 3);

                Logging.Write("Lets ress");

                Frame staticPopup1Button1 = InterfaceHelper.GetFrameByName("StaticPopup1Button1");
                var   clickTimeout        = new Ticker(5 * 1000);
                bool  firstClick          = false;
                while (ObjectManager.MyPlayer.IsGhost)
                {
                    if (!firstClick || clickTimeout.IsReady)
                    {
                        if (staticPopup1Button1 != null && staticPopup1Button1.IsVisible)
                        {
                            staticPopup1Button1.LeftClick();
                            firstClick = true;
                            clickTimeout.Reset();
                        }
                    }
                    Thread.Sleep(1000);
                }
                Logging.Write("Ress worked");
                Reset();
                GrindingEngine.Navigator.Stop();
                GrindingEngine.Navigation = new GrindingNavigation(GrindingEngine.CurrentProfile);
                return;
            }
            Thread.Sleep(10);
        }
コード例 #21
0
        public void MakeMove_WhenPlayerMakesFirstMove_ReturnMoveMessageIsOnlyHitOrMiss()
        {
            var availableReturnMessages = new MoveMessages[] { MoveMessages.Hit, MoveMessages.Miss };

            MoveHelper.MakeMove(_player, _board);

            Assert.IsTrue(availableReturnMessages.Contains(_board.Message));
        }
コード例 #22
0
 public static void Expansion(List <Entity> army)
 {
     foreach (var unit in army)
     {
         MoveHelper.Move(unit, new Point(World.Size / 2, World.Size / 2));
     }
     army.Clear();
 }
コード例 #23
0
 public override PathfindResult GetDestinations(Map map, Actor actor)
 {
     return(MoveHelper.Djikstra(
                p => map.ContainsActorAtLocation(p) ? int.MaxValue : map[p].Properties.MovementPenalty,
                p => GetAdjacentCoordinates(map, p),
                actor.GridPosition,
                actor.Properties.MovementPoints));
 }
コード例 #24
0
 public override bool ExecuteSecondaryEffect(BattlePokemon user, BattlePokemon target)
 {
     if (target.Pokemon.HP > 0 && target.WrapTurns == 0)
     {
         target.WrapTurns = MoveHelper.GetMultiHitAmount() + 1; // +1 because the last round is getting rid of the effect
         Battle.ActiveBattle.UI.ShowMessageAndWait($"{target.GetDisplayName()}\nwas WRAPPED by\n{user.GetDisplayName()}!");
     }
     return(true);
 }
コード例 #25
0
ファイル: AIWorkerTest.cs プロジェクト: frit007/ParallelChess
        public static void findValidMove()
        {
            var board = BoardFactory.LoadBoardFromFen();

            var ai = new AIWorkerManager();

            ai.spawnWorkers(1);
            ai.analyzeBoard(board, 2).GetAwaiter().GetResult();
            Assert.IsTrue(MoveHelper.isValidMove(ai.GetBestMove().move));
        }
コード例 #26
0
ファイル: AIWorkerTest.cs プロジェクト: frit007/ParallelChess
        public static void CompleteTest()
        {
            // for some reason this board would not return a answer when on difficulty 6
            var board = BoardFactory.LoadBoardFromFen("rnb1kbnr/pppp1ppp/4p3/8/3PP2q/8/PPP2PPP/RNBQKBNR w KQkq - 1 3");
            var ai    = new AIWorkerManager();

            ai.spawnWorkers(3);
            ai.analyzeBoard(board, 6).GetAwaiter().GetResult();
            Assert.IsTrue(MoveHelper.isValidMove(ai.GetBestMove().move));
        }
コード例 #27
0
        public void MakeMove_WhenPlayerMakesFirstMove_OnlyOneFieldChangesIsHitToTrue()
        {
            const int numberOfFieldsChanged = 1;

            MoveHelper.MakeMove(_player, _board);

            var counter = _board.Fields.Count(x => x.IsHit);

            Assert.AreEqual(numberOfFieldsChanged, counter);
        }
コード例 #28
0
 public override void DoWork()
 {
     HelperFunctions.ResetRedMessage();
     if (!Mount.IsMounted())
     {
         Mount.MountUp();
         MoveHelper.Jump(3000);
     }
     LazyHelpers.StopAll("背包满了, 停止工作");
 }
コード例 #29
0
ファイル: MailManager.cs プロジェクト: semi420/lazybot
 private static void RetryMailOpen(PGameObject node)
 {
     MoveHelper.StrafeLeft(true);
     Thread.Sleep(500);
     MoveHelper.StrafeLeft(false);
     node.Location.Face();
     Thread.Sleep(100);
     node.Interact(false);
     Thread.Sleep(1500);
 }
コード例 #30
0
 public override void DoWork()
 {
     GrindingEngine.Navigator.Stop();
     MoveHelper.MoveToLoc(_npc.Location, 5);
     VendorManager.DoSell(_npc);
     Logging.Write("[Vendor]Vendor done");
     GrindingEngine.Navigator.Stop();
     GrindingEngine.Navigation = new GrindingNavigation(GrindingEngine.CurrentProfile);
     ToTown.SetToTown(false);
 }