예제 #1
0
 private void InitializeDefaultValues()
 {
     rules           = new LinesOfActionRules();
     openingPosition = new LinesOfActionOpeningPosition();
     boardSize       = 8;
     soundOn         = true;
 }
예제 #2
0
        public void Solve()
        {
            bool      moreRules   = true;
            RulesBase usableRules = new RulesBase();

            usableRules.Rules = new List <Rule>(rDB.Rules);
            fDB.Clear();

            while (moreRules)
            {
                Tuple <Rule, int> ruleToApply = FindUsableRule(usableRules);
                if (ruleToApply != null)
                {
                    IFact newFact = ruleToApply.Item1.Conclusion;
                    newFact.Level = ruleToApply.Item2 + 1;
                    fDB.AddFact(newFact);
                    usableRules.Remove(ruleToApply.Item1);
                }
                else
                {
                    moreRules = false;
                }
            }

            ihm.PrintFacts(fDB.Facts);
        }
예제 #3
0
 // CONSTRUCTEUR
 /// <summary>
 /// Creates an instance of the XmlRulesBaseParser
 /// </summary>
 public XmlRulesBaseParser()
 {
     name      = null;
     version   = 0.0f;
     date      = DateTime.Today;
     rulesBase = new RulesBase();
     errorCode = XmlRulesBaseParserErrorCode.SUCCESS;
 }
예제 #4
0
 private void SetupGame()
 {
     soundsOn        = config.soundOn;
     boardSize       = config.boardSize;
     rules           = config.rules;
     openingPosition = config.openingPosition;
     openingPosition.SetBoardSize(boardSize);
 }
예제 #5
0
 private Tuple <Rule, int> FindUsableRule(RulesBase rBase)
 {
     foreach (Rule r in rBase.Rules)
     {
         int level = CanApply(r);
         if (level != -1)
         {
             return(Tuple.Create(r, level));
         }
     }
     return(null);
 }
예제 #6
0
 /// <summary>
 /// Boots a new game by resolving all dependencies.
 /// </summary>
 /// <typeparam name="T">The type of the game to boot.</typeparam>
 /// <param name="rules">The rules to use when running the game.</param>
 /// <returns>A new game object.</returns>
 public T Boot <T>(RulesBase rules) where T : GameBase
 {
     try
     {
         kernel.Rebind <RulesBase>().ToConstant(rules);
         return(kernel.Get <T>());
     }
     catch (Exception ex)
     {
         throw new BootFailedException(
                   message: "Booting the game failed successfully.", // true dat!
                   inner: ex);
     }
 }
예제 #7
0
        /// <summary>
        /// Builds a new rule object.
        /// </summary>
        /// <param name="ruleType">The type of rules to build.</param>
        /// <returns>A newly instantiated rule.</returns>
        public static RulesBase Build(Rule ruleType)
        {
            RulesBase rules = null;

            switch (ruleType)
            {
            case Rule.Sierpinskish:
                rules = new SierpinskishRules();
                break;

            default:
                rules = new StandardRules();
                break;
            }

            return(rules);
        }
예제 #8
0
        private void Run()
        {
            Console.WriteLine("Demonstration Intelligence Artificielle Système Expert" + Environment.NewLine +
                              "Sébastien ALVAREZ - Septembre 2018" + Environment.NewLine);

            Console.WriteLine("=> Création de la base de règles à partir du fichier xml...");
            XmlRulesBaseParser parser    = new XmlRulesBaseParser();
            RulesBase          rulesBase = parser.CreateRulesBase("RulesBase - polygones.xml");

            if (parser.ErrorCode == XmlRulesBaseParserErrorCode.SUCCESS)
            {
                Console.WriteLine("=> Base de règles chargée pour : " + parser.Name + "...");

                // Résolution du problème d'identification
                Console.WriteLine("=> Création du moteur d'inférence de l'IA...");
                FactsBase factsBase = new FactsBase();
                factsBase.Facts.Add(new IntFact("Ordre", 3, 0, null));
                factsBase.Facts.Add(new BoolFact("Angle droit", true, 0, null));

                Engine ia = new Engine(this, rulesBase, factsBase);

                //Engine ia = new Engine(this, rulesBase);
                Console.WriteLine("=> Résolution du problème d'identification...");
                ia.Solve();

                Console.WriteLine("\n=> Résolution du problème d'identification...");
                List <IFact> newFactsList = new List <IFact>();
                newFactsList.Add(new IntFact("Ordre", 3, 0, null));
                newFactsList.Add(new IntFact("Côtés égaux", 3, 0, null));
                ia.SetFactsBase(newFactsList);
                ia.Solve();

                Console.WriteLine("\n=> Résolution du problème d'identification...");
                ia = new Engine(this, rulesBase);
                ia.Solve();
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Erreur de parsing du fichier xml..." + Environment.NewLine + "Erreur : " + parser.ErrorCode.ToString());
                Console.ReadLine();
            }
        }
예제 #9
0
    public void Solve()
    {
        // On fait une copie des règle existantes
        // + création d'une base de faits vierge
        bool      moreRules   = true;
        RulesBase usableRules = new RulesBase();

        usableRules.Rules = new List <Rule>(rDB.Rules);
        fDB.Clear();

        // Tant qu'il existe des règles à appliquer
        while (moreRules)
        {
            // Cherche une règle à appeler
            Tuple <Rule, int> t = FindUsableRule(usableRules);

            if (t != null)
            {
                // Applique la règle et ajoute le nouveau fait
                // à la base
                IFact newFact = t.Item1.Conclusion;
                newFact.SetLevel(t.Item2 + 1);
                fDB.AddFact(newFact);

                // Enlève la règle des règles applicables
                usableRules.Remove(t.Item1);
            }
            else
            {
                // PLus de règles possible : on s'arrête
                moreRules = false;
            }
        }

        // Ecriture du résultat
        ihm.PrintFacts(fDB.Facts);
    }
예제 #10
0
 public Motor(HumanInterface _ihm)
 {
     ihm = _ihm;
     fDB = new FactsBase();
     rDB = new RulesBase();
 }
예제 #11
0
        /// <summary>
        /// Creates and returns RulesBase object from the given XML file, argument must be a valid xml file path, otherwise null is returned
        /// </summary>
        /// <param name="a_source">XML Source file path</param>
        /// <returns>RulesBase object generated from an XML file, null is returned if parsing is unsuccessful</returns>
        public RulesBase CreateRulesBase(object a_source)
        {
            if (a_source != null)
            {
                try
                {
                    string    fileName = (string)a_source;
                    XDocument xmlDoc   = XDocument.Load(fileName);

                    var ruleElements = from XElement element in xmlDoc.Descendants("Rule")
                                       select element;

                    foreach (XElement element in ruleElements)
                    {
                        Rule newRule = ParseRule(element);
                        if (newRule == null)
                        {
                            throw new NullReferenceException(); // Pour affecter errorCode => voir catch
                        }
                        rulesBase.Rules.Add(newRule);
                    }

                    name = xmlDoc.Descendants("RulesBaseInfo").FirstOrDefault().Descendants("Name").FirstOrDefault().Value;

                    float version = 0.0f;
                    if (float.TryParse(xmlDoc.Descendants("RulesBaseInfo").FirstOrDefault().Descendants("Issue").FirstOrDefault().Value, out version))
                    {
                        this.version = version;
                    }
                    int  day            = 1;
                    bool isDayCorrect   = int.TryParse(xmlDoc.Descendants("RulesBaseInfo").FirstOrDefault().Descendants("Date").FirstOrDefault().Attribute("day").Value, out day);
                    int  month          = 1;
                    bool isMonthCorrect = int.TryParse(xmlDoc.Descendants("RulesBaseInfo").FirstOrDefault().Descendants("Date").FirstOrDefault().Attribute("month").Value, out month);
                    int  year           = 0;
                    bool isYearCorrect  = int.TryParse(xmlDoc.Descendants("RulesBaseInfo").FirstOrDefault().Descendants("Date").FirstOrDefault().Attribute("year").Value, out year);
                    if (isDayCorrect && isMonthCorrect && isYearCorrect)
                    {
                        try
                        {
                            date = new DateTime(year, month, day);
                        }
                        catch (Exception)
                        {
                            // Format de la date incorrect
                            // Pas d'action, donnée non essentielle
                        }
                    }
                }
                catch (XmlException)
                {
                    errorCode = XmlRulesBaseParserErrorCode.ERROR_NOT_XML_FILE;
                    rulesBase = null;
                }
                catch (NullReferenceException)
                {
                    errorCode = XmlRulesBaseParserErrorCode.ERROR_INCOMPLETE_XML_FILE;
                    rulesBase = null;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType() + "   " + ex.Message + "    " + ex.Source.ToString());
                    errorCode = XmlRulesBaseParserErrorCode.ERROR_UNKNOWN;
                    rulesBase = null;
                }
            }
            return(rulesBase);
        }
예제 #12
0
 /// <summary>
 /// Initializes a new instance of the LinqGame class.
 /// </summary>
 /// <param name="formatter">The formatter to output state by.</param>
 /// <param name="rules">The rules for running the game.</param>
 public LinqGame(RulesBase rules)
     : base(rules)
 {
     generation = 0;
     universe   = new Universe();
 }
예제 #13
0
 public TestGame(RulesBase rules)
     : base(rules)
 {
     generation = 0;
 }