示例#1
0
        private void AnalyseScanForTargetLock()
        {
            if (lastScan.NumberOfPOI > 0)
            {
                behaviour.SetBehaviour(PBMode.Hunt);
            }

            lastScan.ScanResultEach((ab, cd) => {
                if (cd == ScanTileResult.Bot)
                {
                    b.Warning.Log("EH");
                }
            });

            if (lastScan.NumberOfPOI > 0)
            {
                BotWriteMessage("Point of interest found");

                foreach (var v in lastScan.GetPointsOfInterest())
                {
                    if ((weaponsActive) && (lastScan.GetResultAtPosition(v.ScanLocation) == ScanTileResult.Bot))
                    {
                        if (CurrentSpeed > 5)
                        {
                            Decelerate();
                        }
                        BotWriteMessage("FIRING : " + v.POIIdentity.ToString());
                        var res = FireWeapon(v.POIIdentity, "Rifle");
                        if (res.State == UsageEndState.Fail_NoAmmo)
                        {
                            weaponsActive = false;
                        }
                    }
                    else
                    {
                        // RAMMING SPEED!
                        HeadToPoint(v.ScanLocation);
                        Accelerate();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks>
        /// [-1, 1][ 0, 1][ 1, 1]
        /// [-1, 0][ kev ][ 1, 0]
        /// [-1,-1][ 0,-1][ 1,-1]
        /// </remarks>
        /// <param name="turn"></param>
        /// <param name="tick"></param>

        protected override void BotTakeAction(int turn, int tick, LastTickRecord ltr)
        {
            //reset the scan
            scannedThisTick = false;

            //if (turn == 4 & tick == 10) {
            //    Plisky.Boondoggle2.Test.TestUtils.DumpScanResult(grid, turn, tick, this.Name);
            //}

            int things = this.Scan(turn, tick);

            if (things == 0)
            {
                if (speed > 1)
                {
                    for (int i = 0; i < 11; i++)
                    {
                        b.Info.Log($"Nothing around!  Speed is {speed} Decelerating to {speed + 1}");
                        this.speed = Decelerate();
                    }
                }
            }
            else
            {
                if (rifle < 11)
                {
                    foreach (var poi in grid.GetPointsOfInterest())
                    {
                        b.Info.Log("KevBot FIRE!!!  - TargetId {" + poi.POIIdentity.ToString() + "}");
                        var eur = FireWeapon(poi.POIIdentity, "Rifle" + rifle);
                        b.Info.Log($"KevBot fire result was : {eur.State}");
                        if (eur.State == UsageEndState.Fail_NoAmmo)
                        {
                            rifle++;
                        }
                    }
                }
                else
                {
                    if (speed < 10)
                    {
                        for (int i = 0; i < 11; i++)
                        {
                            b.Info.Log($"Bitches in the hood!  Speed is {speed} Accelerating to {speed + 1}");
                            this.speed = Accelerate();
                        }
                    }
                }
            }

            var nextHeading = GetNextPositionFromDirection();

            //The position we are about to occupy is unscanned
            if (grid.GetResultAtPosition(nextHeading.Point) == ScanTileResult.Unscanned)
            {
                b.Info.Log("Found our next heading is unscanned, rescan!");
                rescan      = true;
                things      = this.Scan(turn, tick);
                nextHeading = GetNextPositionFromDirection();
            }

            //The position we are about to occupy is unoccupied
            if (grid.GetResultAtPosition(nextHeading.Point) == ScanTileResult.Unoccupied)
            {
                // Nothing of interest was returned on the map
                //if (things == 0)
                //{
                //    return;
                //}

                bool currentHeadingIsSafe = true;
                int  bots = 0;
                //There is something on the map that we might bump into, check whether
                //they can potentially move into the position we are about to occupy
                foreach (var rp in currentPosition.RelatedPoints)
                {
                    if (grid.GetResultAtPosition(rp) == ScanTileResult.Bot)
                    {
                        currentHeadingIsSafe = false;
                        b.Info.Log($"Found a bot at {rp.X}:{rp.Y} - can't go to {currentPosition.Point.X}:{currentPosition.Point.Y}, in case we collied");
                        bots++;
                    }
                    ////TODO : change this to walls straight ahead of us only
                    //if (grid.GetResultAtPosition(rp) == ScanTileResult.SolidWall)
                    //{
                    //    currentHeadingIsSafe = false;
                    //    b.Info.Log("Found a wall at {0}:{1} - can't go to {2}:{3}, in case we collied", rp.X, rp.Y, currentPosition.Point.X, currentPosition.Point.Y);
                    //    break;
                    //}
                }

                if (currentHeadingIsSafe)
                {
                    return;
                }

                b.Info.Log($"Current heading is not safe, there are {bots} bots about, change direction!");

                rescan = true;
                Scan(turn, tick);
            }
            else if (grid.GetResultAtPosition(nextHeading.Point) == ScanTileResult.SolidWall)
            {
                b.Info.Log($"Found a wall at {nextHeading.Point.X}:{nextHeading.Point.Y}");
                rescan = true;
                Scan(turn, tick);
                currentHeading.InUse = false;
                SetHeadingAttributes(currentHeading);
                nextHeading.Used  = true;
                nextHeading.InUse = false;
                SetHeadingAttributes(nextHeading);
            }

            //foreach (var rp in currentHeading.RelatedPoints) {
            //    if (grid.GetResultAtPosition(rp) == ScanTileResult.Bot) {
            //        b.Info.Log("Found a bot at {0}:{1} - can't go to {2}:{3}, in case we collied", rp.X, rp.Y, currentHeading.Point.X, currentHeading.Point.Y);
            //        currentHeading.InUse = false;
            //        SetHeadingAttributes(currentHeading);
            //        break;
            //    }
            //}

            //if (currentHeading.InUse)
            //    return;

            List <Heading> freeheadings = FindFreeHeadings(grid);

            if (freeheadings.Count() == 0)
            {
                b.Info.Log("No free headings left, start again");
                headings.ForEach(h => h.Used = false);
                freeheadings = FindFreeHeadings(grid);
            }

            foreach (var heading in freeheadings)
            {
                //if (heading == currentHeading)
                //    continue;
                if (heading == nextHeading)
                {
                    continue;
                }
                if (heading.Used)
                {
                    continue;
                }

                if (grid.GetResultAtPosition(heading.Point) == ScanTileResult.Unoccupied)
                {
                    currentHeading.InUse = false;
                    currentHeading.Used  = true;
                    SetHeadingAttributes(currentHeading);
                    b.Info.Log(currentHeading + " Used set to true, InUse set to false");
                    nextHeading.InUse = false;
                    nextHeading.Used  = true;
                    SetHeadingAttributes(nextHeading);
                    b.Info.Log(nextHeading + " Used set to true, InUse set to false");

                    heading.InUse = true;
                    SetHeadingAttributes(heading);
                    b.Info.Log(heading + " InUse set to true");
                    currentHeading = heading;
                    b.Info.Log($"Found a clear path at {currentHeading.Point.X}:{currentHeading.Point.Y} {Heading.HeadingText(currentHeading.Point)} - Let's go there!");
                    HeadToPoint(heading.Point);
                    return;
                }
            }
            b.Info.Log("No where to go, HALT!");
            this.speed = 0;
        }
示例#3
0
        private List <Heading> FindFreeHeadings(ScanEquipmentUseResult grid)
        {
            var freeheadings = (from h in headings where h.Used == false && h.Point != currentPosition.Point && grid.GetResultAtPosition(h.Point) == ScanTileResult.Unoccupied select h).ToList();

            List <Point> potentialBotLocations = new List <Point>(grid.GetPointsOfInterest().Count() * 9);

            foreach (var poi in grid.GetPointsOfInterest())
            {
                if (grid.GetResultAtPosition(poi.ScanLocation) == ScanTileResult.Bot)
                {
                    potentialBotLocations.Add(poi.ScanLocation);
                    var poiHeading = new Heading(poi.ScanLocation);
                    potentialBotLocations.AddRange(poiHeading.RelatedPoints);
                }
            }

            for (int i = freeheadings.Count() - 1; i >= 0; i--)
            {
                bool headingRemoved = false;
                foreach (var rp in freeheadings[i].RelatedPoints)
                {
                    //if (grid.GetResultAtPosition(rp) == ScanTileResult.SolidWall) {
                    //    headingRemoved = true;
                    //}
                    foreach (var potentialBotLocation in potentialBotLocations)
                    {
                        if (potentialBotLocation == rp)
                        {
                            b.Info.Log($"Found a (potential) bot location at {rp.X}:{rp.Y} - can't go to {freeheadings[i].Point.X}:{freeheadings[i].Point.Y}, in case we collied");
                            headingRemoved = true;
                            break;
                        }
                    }
                    if (headingRemoved)
                    {
                        freeheadings.RemoveAt(i);
                        break;
                    }
                    //if (grid.GetResultAtPosition(rp) == ScanTileResult.Bot) {
                    //    b.Info.Log("Found a bot at {0}:{1} - can't go to {2}:{3}, in case we collied", rp.X, rp.Y, freeheadings[i].Point.X, freeheadings[i].Point.Y);
                    //    freeheadings.RemoveAt(i);
                    //    break;
                    //} else {
                    //    var rph = new Heading(rp);
                    //    foreach (var rp2 in rph.RelatedPoints) {
                    //        if (grid.GetResultAtPosition(rp2) == ScanTileResult.Bot) {
                    //            b.Info.Log("Found a bot at {0}:{1} - can't go to {2}:{3}, in case we collied", rp2.X, rp2.Y, freeheadings[i].Point.X, freeheadings[i].Point.Y);
                    //            freeheadings.RemoveAt(i);
                    //            headingRemoved = true;
                    //            break;
                    //        }
                    //    }
                    //    if (headingRemoved)
                    //    {
                    //        break;
                    //    }
                    //}
                }
            }
            return(freeheadings);
        }