/// <summary>
        /// Erzeugt eine XML-Node für den übergebenen Gast.
        /// </summary>
        /// <param name="aGast">Der Gast, dessen XML-Node erzeugt werden soll.</param>
        /// <returns>Die XML-Node.</returns>
        private XElement CreateXmlNodeForGast(Gast aGast)
        {
            XElement gastNode = new XElement("gast");

            gastNode.SetAttributeValue("name", aGast.name);
            gastNode.SetAttributeValue("beruf", aGast.beruf);
            gastNode.Add(CreateXYNode("startposition", aGast.position.X, aGast.position.Y));
            XElement wunschabstaendeListNode = new XElement("wunschabstaende");

            gastNode.Add(wunschabstaendeListNode);

            foreach (Gast otherGast in list_gaesteliste.Items)
            {
                var wunschabstandNode = new XElement("wunschabstand");
                // TODO Konfiguration: Exception, wenn Wunschabstand fehlt?
                int wunschabstand = 0;
                if (aGast.wunschabstaende.ContainsKey(otherGast.name))
                {
                    wunschabstand = aGast.wunschabstaende[otherGast.name];
                }
                wunschabstandNode.SetAttributeValue("gast", otherGast.name);
                wunschabstandNode.SetAttributeValue("distanz", wunschabstand);

                wunschabstaendeListNode.Add(wunschabstandNode);
            }
            return(gastNode);
        }
Exemple #2
0
        /// <summary>
        /// Berechnet die Befindlichkeit einer Person
        /// </summary>
        /// <param name="person"></param>
        /// <param name="gaesteliste"></param>
        /// <returns></returns>
        public static Dictionary <Point, double> GetBefindlichkeit(Gast person, List <Gast> gaesteliste)
        {
            Dictionary <Point, double> befindlichkeiten = new Dictionary <Point, double>();
            double sum = 0;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    //Für jede andere Person in Gästeliste
                    foreach (Gast otherpers in gaesteliste)
                    {
                        if (otherpers != person)
                        {
                            //Berechne Abstand zur aktuell anderen Person
                            double abstand = GetAbstand(person.position.X + x, person.position.Y + y, otherpers.position);
                            int    wabs    = 0;
                            //Hole den W-Abstand und subtrahiere diesen von tatsächlichen Abstand
                            person.wunschabstaende.TryGetValue(otherpers.name, out wabs);
                            sum += abstand - wabs;
                        }
                    }
                    Point akt = new Point(person.position.X + x, person.position.Y + y);
                    befindlichkeiten.Add(akt, sum);
                    sum = 0;
                }
            }
            return(befindlichkeiten);
        }
        public void BewegePerson(Gast person, Dictionary <string, Gast> liste, List <Point> tisch, Tuple <int, int> raum)
        {
            //Die Befindlichkeiten der umliegenden Punkte werden abgerufen

            Dictionary <Point, double> befi = Befindlichkeit.GetBefindlichkeit(person, liste.Values.ToList(), tisch);

            //Nicht zugängliche Punkte werden ausgeschlossen
            for (int y = -1; y <= 1; y++)
            {
                for (int x = -1; x <= 1; x++)
                {
                    int   xakt = person.position.X + x;
                    int   yakt = person.position.Y + y;
                    Point pakt = new Point(xakt, yakt);

                    //Prüfung auf Wand
                    if (xakt < 0 || yakt < 0 || xakt > raum.Item1 || yakt > raum.Item2)
                    {
                        befi[pakt] = 999;
                        continue;
                    }

                    //Prüfung auf Tisch
                    foreach (Point pkt in tisch)
                    {
                        if (pakt == pkt)
                        {
                            befi[pakt] = 999;
                            break;
                        }
                    }

                    if (befi[pakt] == 999)
                    {
                        continue;
                    }

                    //Prüfung, ob Punkt bereits besetzt ist
                    foreach (Gast gast in liste.Values)
                    {
                        if (xakt == gast.position.X && yakt == gast.position.Y && gast != person)
                        {
                            befi[pakt] = 999;
                            break;
                        }
                    }
                }
            }

            //der kleinste Wert der Befindlichkeiten ist gesucht

            var keyAndValue = befi.OrderBy(kvp => kvp.Value).First();

            person.position = keyAndValue.Key;

            //Schließlich wird die Person auf die neue Position gesetzt
        }