示例#1
0
        private EquipmentUseResult PerformMockScan()
        {
            ScanEquipmentUseResult result = new ScanEquipmentUseResult();

            result.State = UsageEndState.Success;


            return(result);
        }
示例#2
0
 private void PerformScan()
 {
     if (scan)
     {
         scanMinusOne = lastScan;
         lastScan     = (ScanEquipmentUseResult)UseEquipment("MyScanner");
         previousScans.Enqueue(lastScan);
         if (previousScans.Count > 10)
         {
             previousScans.Dequeue();
         }
         scanAge = 0;
     }
     scan = !scan;
 }
示例#3
0
        public static void DumpScanResult(ScanEquipmentUseResult sut, int turn, int tick, string botName) {
            Bilge b = new Bilge(tl:System.Diagnostics.TraceLevel.Verbose);

            b.Info.Log(string.Format("Scan Result for {2} turn {0}, tick {1}..... ", turn, tick, botName) + sut.LowestXValue.ToString() + "," + sut.LowestYValue.ToString() + " --> W:" + sut.Width.ToString() + " H:" + sut.Height.ToString());
            b.Info.Log("Unscanned-0,Unoccupied-1,SolidWall-2,You-3,Bot-4");
            b.Info.Log("________________________________________________");
            for (int y = sut.LowestYValue + sut.Height; y >= sut.LowestYValue; y--) {
                StringBuilder sb = new StringBuilder();
                string spacer = string.Empty;
                if (y < 0) { spacer = " "; }

                sb.Append(string.Format("Y [{1}{0:D2}] |", y, spacer));
                for (int x = sut.LowestXValue; x < sut.LowestXValue + sut.Width; x++) {
                    var res = sut.GetResultAtPosition(new Point(x, y));
                    sb.Append(string.Format("{0},", (int)res));
                }
                b.Info.Log(sb.ToString());
            }

            b.Info.Log("Scan Done");
        }
示例#4
0
        private int Scan(int turn, int tick)
        {
            int things = grid != null ? grid.NumberOfPOI : 0;

            if (tick == 1 | rescan || (tick > 1 & things > 0))
            {
                if (!scannedThisTick)
                {
                    if (things > 0)
                    {
                        b.Info.Log($"RESCAN as found {things} things on the scan during tick {tick}");
                    }
                    else if (rescan)
                    {
                        b.Info.Log($"RESCAN set to true {tick}");
                    }
                    else if (tick == 1)
                    {
                        b.Info.Log($"RESCAN as this is the first tick of the turn {tick}");
                    }
                    grid = UseEquipment("Scanner") as ScanEquipmentUseResult;
                    totalScans++;
                    turnScans++;
                    this.currentPosition      = ScanCentre;
                    this.currentHeading       = ScanCentre;
                    this.currentHeading.InUse = false;
                    SetHeadingAttributes(currentHeading);
                    rescan          = false;
                    scannedThisTick = true;
                    //TestUtils.DumpScanResult(grid, turn, tick, this.Name);
                }
            }
            else
            {
                SetCurrentPositionFromDirection();
            }

            return(grid.NumberOfPOI);
        }
        private ScanEquipmentUseResult GetDefinedScanResult(int definedResult, bool includeSecondBot = false)
        {
            Hub testHub = new Hub();

            var scanningBot = new MockBotFactory().CreateBasicMockBot().WithMockPack().ToBot();

            var scannedBot = new MockBotFactory().CreateBasicMockBot().WithMockPack().ToBot();

            TestEngineFactory tef = new TestEngineFactory().WithHub(testHub).WithDefaultWorld().WithEquipmentSupport().WithBotSupport().WithBot(scanningBot);

            if (includeSecondBot)
            {
                tef = tef.WithBot(scannedBot);
            }

            var engx = tef.WithPrepare().ToMockEngine();

            engx.PerformNextTick();
            engx.Mock_DirectSetBotLocation(scanningBot.PublicId, new Point(99, 99));  // Set bot to top right of the map.

            if (includeSecondBot)
            {
                engx.Mock_DirectSetBotLocation(scannedBot.PublicId, new Point(97, 99));  // Set bot to top right of the map.
            }

            bd2Engine ee = (bd2Engine)engx;


            var ae = scanningBot.InstallEquipment(KnownEquipmentIds.MOCKSCANNER, "FriendlyName", MountPoint.Internal);

            engx.Mock_DirectSetBotCharge(scanningBot.PublicId, 100);
            var result = scanningBot.UseEquipment(ae.InstanceId);
            ScanEquipmentUseResult resASR = (ScanEquipmentUseResult)result;

            Assert.Equal <UsageEndState>(UsageEndState.Success, resASR.State);

            return(resASR);
        }
示例#6
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);
        }