Example #1
0
        public SlimMind(Graph g)
        {
            SuperabundantOnly   = false;
            NearlyColorableOnly = false;
            MaxPot    = MetaKnowledge.Infinity;
            Knowledge = new Knowledge(g);

            ColoringAnalyzer = new ColoringAnalyzer();
        }
Example #2
0
        bool Analyze(Action <Tuple <string, int> > progress = null)
        {
            int winLength = 0;

            var totalBoards = RemainingBoardIDs.Count;
            var lastP       = -1;

            for (int i = RemainingBoardIDs.Count - 1; i >= 0; i--)
            {
                var id = RemainingBoardIDs[i];

                var b = BoardLookup[id];
                if (ColoringAnalyzer.Analyze(Knowledge, b))
                {
                    RemainingBoardIDs.RemoveAt(i);
                    WonBoardIDs.Add(id);

                    if (progress != null)
                    {
                        var p = 100 * (totalBoards - RemainingBoardIDs.Count) / totalBoards;
                        if (p > lastP)
                        {
                            progress(new Tuple <string, int>("Finding all colorable positions...", p));
                            lastP = p;
                        }
                    }
                }
            }

            while (RemainingBoardIDs.Count > 0)
            {
                winLength++;

                var count = RemainingBoardIDs.Count;

                for (int i = RemainingBoardIDs.Count - 1; i >= 0; i--)
                {
                    var id = RemainingBoardIDs[i];

                    var b = BoardLookup[id];
                    if (SwapAnalyzer.Analyze(id, WonBoardIDs))
                    {
                        RemainingBoardIDs.RemoveAt(i);
                        WonBoardIDs.Add(id);

                        if (progress != null)
                        {
                            var p = 100 * (totalBoards - RemainingBoardIDs.Count) / totalBoards;
                            if (p > lastP)
                            {
                                progress(new Tuple <string, int>(string.Format("Finding all {0} move wins...", winLength), p));
                                lastP = p;
                            }
                        }
                    }
                }

                if (RemainingBoardIDs.Count == count)
                {
                    foreach (var id in RemainingBoardIDs)
                    {
                        var b = BoardLookup[id];
                        Knowledge[b.Template.Value][b.ColorCount].AddLoss(b);
                    }

                    var g = Knowledge.GraphKnowledge.Graph;

                    var nearlyColorable = Enumerable.Range(0, Knowledge.GraphKnowledge.LineGraph.N).All(e => RemainingBoardIDs.Any(id => ColoringAnalyzer.ColorableWithoutEdge(Knowledge, BoardLookup[id], e)));
                    if (nearlyColorable)
                    {
                        FixerWonAllNearlyColorableBoards = false;
                        BreakerWonBoard = RemainingBoardIDs.Where(id =>
                        {
                            var b = BoardLookup[id];
                            return(g.DegreeCondition(b) && ColoringAnalyzer.ColorableWithoutEdge(Knowledge, b, 0));
                        }).Select(id => BoardLookup[id])
                                          .FirstOrDefault();

                        if (BreakerWonBoard == null)
                        {
                            BreakerWonBoard = BoardLookup[RemainingBoardIDs.First(id => ColoringAnalyzer.ColorableWithoutEdge(Knowledge, BoardLookup[id], 0))];
                        }
                    }

                    return(false);
                }
            }

            return(true);
        }