public void WarningsTest_CheckTieredProduction_MixedTiers() { colonizationResearch.SetMaxTier(StubColonizationResearchScenario.farmingResearchCategory, "munmuss", TechTier.Tier2); // Validate it catches that it's consistent, but undertiered farm1.Tier = TechTier.Tier2; farm2.Tier = TechTier.Tier2; var actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(2, actual.Count); Assert.AreEqual("Not all the products in the production chain for Snacks have advanced to Tier2.", actual[0].Message); Assert.IsTrue(actual[0].IsClearlyBroken); Assert.IsNotNull(actual[0].FixIt); Assert.AreEqual("There are Tier2 producers of Snacks, but it requires equal-tier Fertilizer production in order to work.", actual[1].Message); actual[0].FixIt(); Assert.AreEqual(TechTier.Tier1, farm1.Tier); Assert.AreEqual(TechTier.Tier1, farm2.Tier); colonizationResearch.SetMaxTier(StubColonizationResearchScenario.productionResearchCategory, "munmuss", TechTier.Tier2); fertFactory1.Tier = TechTier.Tier2; drill1.Tier = TechTier.Tier2; fertFactory1.Tier = TechTier.Tier2; farm1.Tier = TechTier.Tier2; farm2.Tier = TechTier.Tier2; actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual(actual[0].Message, $"Scanning technology at munmuss has not kept up with production technologies - Tier2 parts will not function until you deploy an equal-tier scanner to orbit around munmuss."); Assert.IsTrue(actual[0].IsClearlyBroken); Assert.IsNotNull(actual[0].FixIt); actual[0].FixIt(); Assert.AreEqual(drill1.Tier, TechTier.Tier1); Assert.AreEqual(fertFactory1.Tier, TechTier.Tier1); Assert.AreEqual(farm1.Tier, TechTier.Tier1); Assert.AreEqual(farm2.Tier, TechTier.Tier1); }
public void WarningsTest_CheckCorrectCapacity() { // Verify no false-positives. var actual = StaticAnalysis.CheckCorrectCapacity(colonizationResearch, this.producers, this.snacksOnly, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); // Verify if we need an excess, it gets reported this.producers.Add(new StubProducer(StubColonizationResearchScenario.Snacks, StubColonizationResearchScenario.Fertilizer, 3, TechTier.Tier1)); actual = StaticAnalysis.CheckCorrectCapacity(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual($"The ship needs at least 9 production of {StubColonizationResearchScenario.Fertilizer.BaseName} but it is only producing 6", actual[0].Message); Assert.IsFalse(actual[0].IsClearlyBroken); Assert.IsNull(actual[0].FixIt); // Verify it catches missing stuff in storage - forget the fertilizer List <ITieredProducer> hydroProducers = new List <ITieredProducer>() { this.hydro1, this.hydro2 }; actual = StaticAnalysis.CheckCorrectCapacity(colonizationResearch, hydroProducers, this.snacksOnly, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual($"The ship needs {StubColonizationResearchScenario.Fertilizer.BaseName} to produce {StubColonizationResearchScenario.HydroponicSnacks.BaseName}", actual[0].Message); Assert.IsNull(actual[0].FixIt); }
public Move SelectNextMove(BoardState board, Player player, IList <Move> moves, out string reasoning) { var currentAnalysis = new StaticAnalysis(board); var currentValue = currentAnalysis.GetBoardValue(player); var currentOpponentValue = currentAnalysis.GetBoardValue(player.GetOpponent()); var currentDiffValue = currentValue - currentOpponentValue; var valuedMoves = moves .Select(m => new Tuple <Move, BoardState>(m, board.CloneAndApply(m))) .Select(m => { var a = new StaticAnalysis(m.Item2); return(new Tuple <Move, float>(m.Item1, a.GetBoardValue(player, m.Item1) - a.GetBoardValue(player.GetOpponent()))); //return new Tuple<Move, float>(m.Item1, a.GetBoardValue(player)); }) .OrderByDescending(m => m.Item2) .ThenByDescending(m => Guid.NewGuid()) .ToList(); if (valuedMoves.Any()) { var bestMove = valuedMoves.First(); reasoning = $"Value diff {bestMove.Item2}"; return(bestMove.Item1); } return(fallbackStrategy.SelectNextMove(board, player, moves, out reasoning)); }
public bool ItDeterminesIfSomethingIsAnAggregateStatement(Type type, string methodName) { var method = type.GetMethod(methodName); Assert.IsNotNull(method); return(StaticAnalysis.IsAggregateMethod(method)); }
public void WarningsTest_CheckTieredProductionStorage() { Dictionary <string, double> storage = new Dictionary <string, double> { { "Snacks-Tier1", 100 }, { "Fertilizer-Tier1", 100 }, { "Shinies-Tier1", 100 } }; // Verify no false-positives. var actual = StaticAnalysis.CheckTieredProductionStorage(colonizationResearch, this.producers, this.snacksOnly, storage).ToList(); Assert.AreEqual(0, actual.Count); storage["Fertilizer-Tier1"] = 0; actual = StaticAnalysis.CheckTieredProductionStorage(colonizationResearch, this.producers, this.snacksOnly, storage).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual($"This craft is producing Fertilizer-Tier1 but there's no storage for it.", actual[0].Message); Assert.IsFalse(actual[0].IsClearlyBroken); Assert.IsNull(actual[0].FixIt); storage.Remove("Fertilizer-Tier1"); actual = StaticAnalysis.CheckTieredProductionStorage(colonizationResearch, this.producers, this.snacksOnly, storage).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual($"This craft is producing Fertilizer-Tier1 but there's no storage for it.", actual[0].Message); Assert.IsFalse(actual[0].IsClearlyBroken); Assert.IsNull(actual[0].FixIt); }
public void Normalise() { var report = new TestReport(); var p = Puzzle.Builder.DefaultTestPuzzle(); Assert.True(p.Definition.Wall.Equals(p[0, 0])); Assert.True(p.Definition.Void == p[1, 1]); Assert.True(p.Definition.Player == p[4, 4]); Assert.True(p[4, 4].IsPlayer); Assert.Equal(new VectorInt2(4, 4), p.Player.Position); var norm = StaticAnalysis.Normalise(p); report.WriteLine(norm.ToString()); Assert.Equal(new TestReport(@"########### ####.###### ###..###..# ##.X......# #...PX.#..# ###.X###..# ###..#OO..# ###.##O#.## ##......### ##.....#### ########### "), report); }
public void WarningsTest_NoPartsTest() { var result = StaticAnalysis.CheckBodyIsSet(colonizationResearch, new List <ITieredProducer>(), this.emptyContainers, this.emptyContainers); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public void WarningsTest_MissingBodyAssignment() { this.farm1.Body = null; this.farm2.Body = null; var actual = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("Need to set up the target for the world-specific parts", actual[0].Message); Assert.IsNotNull(actual[0].FixIt); actual[0].FixIt(); Assert.AreEqual("munmuss", this.farm1.Body); actual = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); // If nothing is set up foreach (var p in this.producers) { p.Body = null; } actual = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); // Then it gets complained about, but no fix is offered Assert.AreEqual(1, actual.Count); Assert.AreEqual("Need to set up the target for the world-specific parts", actual[0].Message); Assert.IsNull(actual[0].FixIt); }
public void WarningsTest_HappyParts() { var result = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers); Assert.IsNotNull(result); Assert.IsFalse(result.Any()); }
public static void PrintSceneAnalysis() { var config = Config.Config.LoadFromFile(); var sa = LoadStaticAnalysisRules(config); var violations = new Dictionary <Rule, List <IViolation> >(); HashSet <string> ignoredSceneObjectNames = new HashSet <string>(config.IgnoredSceneRootObjectNames); for (var i = 0; i < SceneManager.sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); GameObject[] rootGameObjects = scene.GetRootGameObjects(); for (var j = 0; j < rootGameObjects.Length; j++) { var obj = rootGameObjects[j]; if (ignoredSceneObjectNames.Contains(obj.name)) { continue; } violations = StaticAnalysis.MergeRuleViolationDictionary(violations, sa.Analyze(ViolationScope.Scene, obj)); } } EditorExtensions.ConsoleWindow.Instance.SetViolations(violations); }
public void WarningsTest_CheckTieredProduction_Hydroponics() { List <ITieredProducer> hydroProducers = new List <ITieredProducer>() { this.hydro1, this.hydro2 }; // Verify no false-positives. var actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, hydroProducers, this.basicHydroponicSupplies, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); hydroProducers[0].Tier = TechTier.Tier0; hydroProducers[1].Tier = TechTier.Tier2; actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, hydroProducers, this.basicHydroponicSupplies, this.emptyContainers).ToList(); Assert.AreEqual(2, actual.Count); Assert.AreEqual($"This base is not taking advantage of the latest tech for producing HydroponicSnacks", actual[0].Message); Assert.IsNotNull(actual[0].FixIt); actual[0].FixIt(); Assert.AreEqual(TechTier.Tier2, hydroProducers[0].Tier); Assert.AreEqual(TechTier.Tier2, hydroProducers[0].Tier); Assert.AreEqual($"Not all of the parts producing {StubColonizationResearchScenario.HydroponicSnacks.BaseName} are set at {TechTier.Tier2.DisplayName()}", actual[1].Message); Assert.IsNotNull(actual[1].FixIt); }
public void Run() { var board = BoardState.InitialBoard; var random = new Random(); IStrategy strategy = new BasicStaticAnalysisStrategy(); string reasoning; while (true) { var moves = board.GetMovesForNextPlayer().ToList(); if (moves.Count == 0) { Console.Clear(); board.RenderToConsole(); Console.WriteLine($"Checkmate by {board.NextPlayerToMove.GetOpponent()}"); while (Console.ReadKey().Key != ConsoleKey.Escape) { ; } board = BoardState.InitialBoard; continue; } var move = strategy.SelectNextMove(board, board.NextPlayerToMove, moves, out reasoning); Console.Clear(); board.Apply(move); board.RenderToConsole(); Console.WriteLine(); var analysis = new StaticAnalysis(board); Console.WriteLine($"Value for {move.Player}: {analysis.GetBoardValue(move.Player,move)} ({string.Join(",", analysis.GetBoardValueComponents(move.Player, move).Select(kv => kv.Key + ":" + kv.Value))})"); //Console.WriteLine($"Value for white: {analysis.GetBoardValue(Player.White)} ({string.Join(",", analysis.GetBoardValueComponents(Player.White, move).Select(kv => kv.Key + ":" + kv.Value))})"); //Console.WriteLine($"Value for black: {analysis.GetBoardValue(Player.Black)} ({string.Join(",", analysis.GetBoardValueComponents(Player.Black, move).Select(kv => kv.Key + ":" + kv.Value))})"); Console.WriteLine($"{move.ToString()} because {reasoning}"); Console.WriteLine($"{moves.Count} moves"); Console.WriteLine(string.Join(" ", moves.Select(m => m.ToAnnotation()))); Console.WriteLine($"{board.NextPlayerToMove} to move..."); Console.WriteLine($"White defends: {string.Join(" ",analysis.Analysis.Where(sq=>sq.IsWhiteDefendedSquare).Select(sq=>sq.Square.ToString()))}"); //if (board.WhiteInCheck || board.BlackInCheck) var key = Console.ReadKey(); if (key.Key == ConsoleKey.Escape) { break; } if (key.Key == ConsoleKey.R) { board = BoardState.InitialBoard; } } }
public void ItConvertsPredicateTypes() { var method = GetType().GetMethod("DoIt"); Func <object, bool> cont = j => (int)j % 2 == 0; var converter = StaticAnalysis.CreateConverter(typeof(int)); method.Invoke(this, new [] { converter(cont) }); Assert.AreEqual(1, didIt); }
private void StaticAnalysis(string path, StaticAnalysis sta) { foreach (var step in sta.Steps) { Thread ts = new Thread(new ParameterizedThreadStart(StaticAnalysisStep)); ts.Start(new object[] { path, step }); threads.Add(ts); } }
public void WIP_ExploringImprovedBitmap() { var p = Puzzle.Builder.DefaultTestPuzzle(); var floor = p.ToMap(p.Definition.AllFloors); outp.WriteLine($"{floor.GetType().Name} = {floor.SizeInBytes()} bytes"); var alt = new BitmapByteSeq(floor); outp.WriteLine($"{alt.GetType().Name} = {alt.SizeInBytes()}"); var enumFloor = StaticAnalysis.IndexPositions(floor); outp.WriteLine($"Floors : {enumFloor.Count}={enumFloor.Count /8 + 1}bytes vs {floor.Size.X * floor.Size.Y}"); }
public Move SelectNextMove(BoardState board, Player player, IList <Move> moves, out string reasoning) { var currentAnalysis = new StaticAnalysis(board); var bestMove = RankMoves(board, player, moves, currentAnalysis).FirstOrDefault(); if (bestMove != null) { reasoning = bestMove.Item2; return(bestMove.Item1); } return(fallbackStrategy.SelectNextMove(board, player, moves, out reasoning)); }
public void WarningsTest_MismatchedBodyAssignment() { this.farm1.Body = "splut"; this.farm2.Body = null; var actual = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("Not all of the body-specific parts are set up for munmuss", actual[0].Message); Assert.IsNotNull(actual[0].FixIt); actual[0].FixIt(); Assert.AreEqual("munmuss", this.farm1.Body); Assert.AreEqual("munmuss", this.farm2.Body); actual = StaticAnalysis.CheckBodyIsSet(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); }
public void WarningsTest_CheckTieredProduction_LandedMixedupFarms() { // Validate it catches that it's consistent, but undertiered farm1.Tier = TechTier.Tier0; var actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(2, actual.Count); Assert.AreEqual(actual[0].Message, $"This base is not taking advantage of the latest tech for producing Snacks"); Assert.AreEqual(actual[1].Message, $"Not all of the parts producing {farm1.Output.BaseName} are set at {farm2.Tier}"); Assert.IsNotNull(actual[1].FixIt); actual[1].FixIt(); Assert.AreEqual(TechTier.Tier1, farm1.Tier); actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); }
public void WarningsTest_ChecksSnacks() { List <SkilledCrewman> noCrew = new List <SkilledCrewman>(); List <SkilledCrewman> someCrew = new List <SkilledCrewman> { new StubSkilledCrewman("Tourist", 0) }; // Control - it shouldn't warn if there's no crew var actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>(), this.emptyContainers, this.emptyContainers, noCrew).ToArray(); Assert.AreEqual(0, actual.Length); // When we add crew, it complains actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>(), this.emptyContainers, this.emptyContainers, someCrew).ToArray(); Assert.AreEqual(1, actual.Length); // When we add snack storage, it shuts up actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>(), this.snacksOnly, this.emptyContainers, someCrew).ToArray(); Assert.AreEqual(0, actual.Length); // When we add snack storage, it shuts up actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>(), this.snacksOnly, this.emptyContainers, someCrew).ToArray(); Assert.AreEqual(0, actual.Length); // When we add a snack producer, it shuts up actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>() { new StubFarm() { Tier = TechTier.Tier4 } }, this.emptyContainers, this.emptyContainers, someCrew).ToArray(); Assert.AreEqual(0, actual.Length); // Given there are parts that produce on board - it should warn even if there aren't crew actual = StaticAnalysis.CheckHasSomeFood( colonizationResearch, new List <ITieredProducer>() { new StubDrill() }, this.emptyContainers, this.emptyContainers, noCrew).ToArray(); Assert.AreEqual(1, actual.Length); }
public void UnderstandsMaxTier() { colonizationResearch.SetMaxTier(StubColonizationResearchScenario.farmingResearchCategory, "munmuss", TechTier.Tier3); colonizationResearch.SetMaxTier(StubColonizationResearchScenario.productionResearchCategory, "munmuss", TechTier.Tier3); colonizationResearch.SetMaxTier(StubColonizationResearchScenario.scanningResearchCategory, "munmuss", TechTier.Tier3); colonizationResearch.SetMaxTier(StubColonizationResearchScenario.shiniesResearchCategory, "munmuss", TechTier.Tier2); var producers = new List <ITieredProducer>() { new StubProducer(StubColonizationResearchScenario.Fertilizer, StubColonizationResearchScenario.Stuff, 6, TechTier.Tier3), new StubProducer(StubColonizationResearchScenario.Stuff, null, 6, TechTier.Tier3), new StubProducer(StubColonizationResearchScenario.Shinies, null, 6, TechTier.Tier2) }; var actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); }
private BitStream Encode(Puzzle puzzle) { var norm = StaticAnalysis.RemoveOuter(StaticAnalysis.Normalise(puzzle)); var bs = new BitStream(); foreach (var cell in RunLength.Encode(norm.ForEachTile(), this)) { var s = cell.Item1.Cell; if (s == puzzle.Definition.Void || s == puzzle.Definition.Wall) { EncodeItem(cell, Control.None, bs); } if (s == puzzle.Definition.Floor) { EncodeItem(cell, Control.Floor, bs); } if (s == puzzle.Definition.Goal) { bs.AddRange(BitStream.Encode(Control.Goal)); } if (s == puzzle.Definition.Crate) { bs.AddRange(BitStream.Encode(Control.Crate)); } if (s == puzzle.Definition.CrateGoal) { bs.AddRange(BitStream.Encode(Control.CrateGoal)); } if (s == puzzle.Definition.Player) { bs.AddRange(BitStream.Encode(Control.Player)); } if (s == puzzle.Definition.PlayerGoal) { bs.AddRange(BitStream.Encode(Control.PlayerGoal)); } } bs.AddRange(BitStream.Encode(Control.End)); return(bs); }
public static void PrintPrefabAnalysis() { var config = Config.Config.LoadFromFile(); var sa = LoadStaticAnalysisRules(config); var prefabDirectories = config.PrefabLocations; var assets = AssetDatabase.FindAssets("t:prefab", prefabDirectories); var violations = new Dictionary <Rule, List <IViolation> >(); for (var i = 0; i < assets.Length; i++) { var asset = assets[i]; var path = AssetDatabase.GUIDToAssetPath(asset); var obj = AssetDatabase.LoadAssetAtPath <GameObject>(path); violations = StaticAnalysis.MergeRuleViolationDictionary(violations, sa.Analyze(ViolationScope.Prefab, obj)); } EditorExtensions.ConsoleWindow.Instance.SetViolations(violations); }
public void WarningsTest_CheckExtraBaggage() { // Verify no false-positives. var actual = StaticAnalysis.CheckExtraBaggage(colonizationResearch, this.producers, this.snacksOnly, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); Dictionary <string, double> extraBaggage = new Dictionary <string, double>() { { "Snacks-Tier4", 100.0 }, { "Fertilizer-Tier3", 100.0 }, }; actual = StaticAnalysis.CheckExtraBaggage(colonizationResearch, this.producers, extraBaggage, emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual($"This vessel is carrying Fertilizer-Tier3. Usually that kind of cargo is produced, so likely there's no point in carrying it into orbit with you. You should probably empty those containers.", actual[0].Message); Assert.IsFalse(actual[0].IsClearlyBroken); Assert.IsNotNull(actual[0].FixIt); // We can't validate the FixIt routine because it reparses the vessel's parts }
public void WarningsTest_CheckTieredProduction_LandedUndertiered() { // Verify no false-positives. var actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); // Validate it catches that it's consistent, but undertiered foreach (var p in this.producers) { p.Tier = TechTier.Tier0; } actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("This base is not taking advantage of the latest tech for producing Stuff", actual[0].Message); Assert.IsNotNull(actual[0].FixIt); actual[0].FixIt(); actual = StaticAnalysis.CheckTieredProduction(colonizationResearch, this.producers, this.emptyContainers, this.emptyContainers).ToList(); Assert.AreEqual(0, actual.Count); }
// public Profile LoadProfile(string fileName) // { // var profile = new Profile // { // FileName = fileName, // Current = null, // Statistics = new Statistics() // }; // var pairs = TrivialNameValueFileFormat.Load(fileName); // var binder = new TrivialNameValueFileFormat.WithBinder<Profile>(); // foreach (var pair in pairs) // { // binder.SetWhen(pair, profile, x => x.Name); // binder.SetWhen(pair, profile, x => x.Created); // binder.SetWhen(pair, profile, x => x.TimeInGame); // binder.With(profile, x => x.Current) // .SetWhen(pair, x => x.Library) // .SetWhen(pair, x => x.Puzzle); // binder.With(profile, x => x.Statistics) // .SetWhen(pair, x => x.Pushes) // .SetWhen(pair, x => x.Steps) // .SetWhen(pair, x => x.Started) // .SetWhen(pair, x => x.Undos) // .SetWhen(pair, x => x.Restarts) // ; // } // // return profile; // } // public TrivialNameValueFileFormat SaveProfile(Profile lib, string fileName) // { // var txt = TrivialNameValueFileFormat.Serialise(lib); // txt.Save(fileName); // return txt; // } public Library LoadLegacySokoSolve_SSX(string fileName) { var ser = new XmlSerializer(typeof(SokobanLibrary)); SokobanLibrary?xmlLib = null; using (var reader = File.OpenText(fileName)) { xmlLib = (SokobanLibrary)ser.Deserialize(reader); } var lib = Convert(xmlLib); foreach (var puzzle in lib) { puzzle.Rating = StaticAnalysis.CalculateRating(puzzle.Puzzle); } return(lib); }
public void WarningsTest_ChecksCombiners() { var partProducers = new List <ITieredProducer>() { this.drill1, this.partFactory }; var combiners = new List <ITieredCombiner>() { this.combiner }; Dictionary <string, double> availableMixins = new Dictionary <string, double>() { { StubRocketPartCombiner.ExpectedInputResource, 100.0 } }; Dictionary <string, double> placeForOutput = new Dictionary <string, double>() { { StubRocketPartCombiner.ExpectedOutputResource, 100.0 } }; // Verify no false-positives. var actual = StaticAnalysis.CheckCombiners(colonizationResearch, partProducers, combiners, availableMixins, placeForOutput).ToList(); Assert.AreEqual(0, actual.Count); // Verify finds missing untiered input actual = StaticAnalysis.CheckCombiners(colonizationResearch, partProducers, combiners, this.emptyContainers, placeForOutput).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("To produce Rocket Parts you will need to bring some Complex Parts.", actual[0].Message); // Verify finds missing tiered input actual = StaticAnalysis.CheckCombiners(colonizationResearch, new List <ITieredProducer>(), combiners, availableMixins, placeForOutput).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("To produce Rocket Parts, you need produce LocalParts as input.", actual[0].Message); // Verify checks storage for output actual = StaticAnalysis.CheckCombiners(colonizationResearch, partProducers, combiners, availableMixins, new Dictionary <string, double>()).ToList(); Assert.AreEqual(1, actual.Count); Assert.AreEqual("There's no place to put the Rocket Parts this base is producing.", actual[0].Message); }
/// <summary> /// Initialise and perform the static puzzle analysis /// </summary> public void Init() { debugReport.AppendHeading(2, "Static Puzzle Analysis"); staticAnalysis = new StaticAnalysis(this); staticAnalysis.Analyse(); debugReport.CompleteSection(); }
/// <summary> /// Filter out irrelivant checks (use wall/floor to match). From all posible check locations (Width, Height) /// generate the list of possible hits /// </summary> /// <param name="staticAnalysis"></param> /// <returns>true of match found</returns> public bool PreProcess(StaticAnalysis staticAnalysis) { checkLocations = new List<VectorInt>(); for (int cx = 0; cx < staticAnalysis.WallMap.Size.Width; cx++) for (int cy = 0; cy < staticAnalysis.WallMap.Size.Height; cy++) { PreProcessHintLocation(cx, cy, staticAnalysis); } if (checkLocations.Count == 0) { checkLocations = null; return false; } return true; }
/// <summary> /// Perform the PreProcess check at a specific location /// </summary> /// <param name="cx"></param> /// <param name="cy"></param> /// <param name="staticAnalysis"></param> public void PreProcessHintLocation(int cx, int cy, StaticAnalysis staticAnalysis) { for (int hintY = 0; hintY < hint.GetLength(1); hintY++) for (int hintX = 0; hintX < hint.GetLength(0); hintX++) { if (staticAnalysis.WallMap.Size.Width <= hintX + cx) return; if (staticAnalysis.WallMap.Size.Height <= hintY + cy) return; switch (hint[hintX, hintY]) { case (HintCell.Floor): if (!staticAnalysis.FloorMap[cx + hintX, cy + hintY]) return; break; case (HintCell.Wall): if (!staticAnalysis.WallMap[cx + hintX, cy + hintY]) return; break; case (HintCell.CrateNotGoal): if (!staticAnalysis.FloorMap[cx + hintX, cy + hintY] && !staticAnalysis.GoalMap[cx + hintX, cy + hintY]) return; break; case (HintCell.CrateGoalOrCrateNonGoal): if (!staticAnalysis.FloorMap[cx + hintX, cy + hintY]) return; break; case (HintCell.DeadStatic): if (!staticAnalysis.DeadMap[cx + hintX, cy + hintY]) return; break; case (HintCell.DeadStaticOrDynamic): // Cannot precalculate this break; case (HintCell.Ignore): break; default: throw new InvalidDataException("Unknown hint cell state:" + hint[hintX, hintY]); } } // All criteria passed this.checkLocations.Add(new VectorInt(cx, cy)); }
private void btnImports_Click(object sender, EventArgs e) { total = bFiles.Count + mFiles.Count; MessageBox.Show(total.ToString()); ThreadPool.QueueUserWorkItem(x => StaticAnalysis.HistogramOfImports(mFiles, bFiles)); }
private void mnuAnalyzeFiles_Click(object sender, EventArgs e) { total = bFiles.Count + mFiles.Count; MessageBox.Show(total.ToString()); ThreadPool.QueueUserWorkItem(x => StaticAnalysis.Analyze(mFiles, bFiles)); }
public bool ItDeterminesIfSomethingIsAProceedFunction(Type type) { return(StaticAnalysis.IsProceedFunction(type)); }
public bool ItDeterminesIfSomethingIsAStatementController(Type type) { return(StaticAnalysis.IsStatementController(type)); }