コード例 #1
0
ファイル: Agent.cs プロジェクト: Lynxa/Lambent
        public Agent(String id, List<KVP> items, AgentDataDictionary iAgentDataDictionary,Dispatcher uiThread)
        {
            ID = id;
            _imageDictionary = iAgentDataDictionary;
            
            _name = iAgentDataDictionary.GetAgentNameByID(id);

            Items = Item.KvpToItems(items, iAgentDataDictionary, uiThread);

            int tsc = 0;
            Item tIt = null;
            foreach (var item in Items)
            {
                if (item.Key.StartsWith("account"))
                {
                    tsc = Int32.Parse(item.Amount);
                    tIt = item;
                    break;
                }
            }

            _account = tsc;

            _uiDispatcher = uiThread;
            _uiDispatcher.Invoke(() =>
            {
                _bg = new SolidColorBrush(Colors.LightYellow);
                _brd = new SolidColorBrush(ColorAndIconAssigner.GetOrAssignColorById(id));
                if (tIt!=null) Items.Remove(tIt);
            });

            st = ElementStatus.New;
        }
コード例 #2
0
ファイル: SystemEvent.cs プロジェクト: Lynxa/Lambent
        public SystemEvent(KVP kvp, AgentDataDictionary ag) 
        {
            foreach (var k in kvp.ListOfItems)
            {
                if (k.Key == "description")
                {
                    String ts = k.Value;
                    
                    ts = ts.Remove(0, k.Value.IndexOf("(") + 1);
                    ts = ts.Remove(ts.Length - 1, 1);

                    String subject = ts.Substring(0, ts.IndexOf(","));
                    ts = ts.Remove(0, ts.IndexOf(",") + 1);

                    String action = ts.Substring(0, ts.LastIndexOf(","));
                    ts = ts.Remove(0, ts.LastIndexOf(",") + 1);

                    String successfully = ts;

                    String obj = "";

                    if (action.Contains("("))
                    {
                        obj = action.Substring(action.IndexOf("(")+1, action.LastIndexOf(")")-action.IndexOf("(")-1);
                        action = action.Remove(action.IndexOf("("), action.LastIndexOf(")") - action.IndexOf("(")+1);
                    }

                    if (action.StartsWith("initializ"))
                    {
                        _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " +
                                   "has successfully initialized the simulation.";
                    }
                    else if (action.StartsWith("admit"))
                    {
                        _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " +
                                   "has admitted " + (!obj.Equals("") ? ag.GetAgentNameByID(obj)+ "(" + obj + ")": "" + ".");
                    }
                    else if (action.StartsWith("dismiss"))
                    {
                        _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " +
                                  "has dismissed " + (!obj.Equals("") ? ag.GetAgentNameByID(obj) + "(" + obj + ")" : "" + ".");
                    }
                    else if (action.StartsWith("dismiss"))
                    {
                        _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " +
                                  "has enforced the following punishments: " + obj + ".";
                    }
                    else if (successfully.Equals("successfully"))
                    {
                        if (action.StartsWith("open_auction"))
                        {
                            String _objAuction = obj.Substring(0, obj.IndexOf(','));
                            String obj1 = (obj.Remove(0, obj.IndexOf(',') + 1)).Replace(" ", "");
                            String _objItem = obj1.Substring(0, obj1.IndexOf(","));
                            String _objPrice = (obj1.Remove(0, obj1.IndexOf(',') + 1));

                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + "has created the auction \"" + _objAuction + "\" for " +
                                       _objItem + " with opening price of " + _objPrice;
                        }
                        else if (action.StartsWith("close_auction"))
                        {
                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + "has closed the auction \"" +
                                       obj +"\"";
                        }
                        else if (action.StartsWith("place_bid"))
                        {
                            String _objAuction = obj.Substring(0, obj.IndexOf(','));
                            String _objPrice = (obj.Remove(0, obj.IndexOf(',') + 1)).Replace(" ", "");
                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + "has placed the bid of " + _objPrice +
                                       " in auction \"" + _objAuction +"\".";
                        }
                        else if (action.StartsWith("sell"))
                        {
                            String _objItem = obj.Substring(0, obj.IndexOf(','));
                            String obj1 = (obj.Remove(0, obj.IndexOf(',') + 1)).Replace(" ", "");
                            String _objPrice = obj1.Substring(0, obj1.IndexOf(","));
                            String _objAgent = (obj1.Remove(0, obj1.IndexOf(',') + 1));
                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + "has sold the item " + _objItem +
                                       " for " +_objPrice +" to " + ag.GetAgentNameByID(_objAgent) + "(" + _objAgent + ")";
                        }
                        else if (action.StartsWith("flip_coin"))
                        {
                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + "has flipped the coin.";
                        }
                        else
                        {
                            _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + successfully +
                                       " performed the following action: " +
                                       action + (!obj.Equals("") ? "(" + obj + ")" : "") + ".";
                        }
                    }
                    else
                    {
                        _message = "Agent " + ag.GetAgentNameByID(subject) + "(" + subject + ") " + successfully +
                                   " tried to perform the following action: " +
                                   action + (!obj.Equals("") ? "(" + obj + ")" : "") + ".";
                    }


                }
                if (k.Key == "happened_at")
                {
                    _timestamp = (k.Value.Contains('.')) ? k.Value.Substring(0, k.Value.LastIndexOf('.') + 2) : k.Value;
                }
            }
        }
コード例 #3
0
ファイル: Item.cs プロジェクト: Lynxa/Lambent
        public Item(String key, List<KVP> list, CfgSettings cfg, AgentDataDictionary ag, Dispatcher uiDispatcher): base(key, new List<KVP>())
        {
            cfgSettings = cfg;
            if (key.StartsWith("oblig"))
            {
               // InstanceOf = "obligation";
            }
            ImageDictionary = ag;
            UIDispatcher = uiDispatcher;
            Status = ElementStatus.Unchanged;
            
            foreach (var l in list)
            {
                if (l.Key.Equals("held_by"))
                {
                    StringAttributeList.Add("Held by", ag.GetAgentNameByID(l.Value) + " (" + l.Value + ")");
                    _held_by = l.Value;
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("owned_by"))
                {
                    StringAttributeList.Add("Owned by", ag.GetAgentNameByID(l.Value) + " (" + l.Value + ")");
                    _owned_by = l.Value;
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("instance_of"))
                {
                    StringAttributeList.Add("Instance of", l.Value);
                    InstanceOf = l.Value;
                }
                else if (l.Key.Equals("weight"))
                {
                    StringAttributeList.Add("Weight", l.Value);
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("status"))
                {
                    StringAttributeList.Add("Status", l.Value);
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("auctioneer"))
                {
                    StringAttributeList.Add("Auctioneer", ag.GetAgentNameByID(l.Value) + " (" + l.Value + ")");
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("highest_bidder"))
                {
                    StringAttributeList.Add("Highest bidder", ag.GetAgentNameByID(l.Value) + " (" + l.Value + ")");
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("last_bid_time"))
                {
                    StringAttributeList.Add("Last bid time", l.Value.Substring(0, 5));
                    ListOfItems.Remove(l);
                }
                else if (l.Key.IndexOf("_") > 0)
                {
                    String st = l.Key.Replace("_", " ");
                    st = st[0].ToString().ToUpper()[0] + st.Substring(1);
                    StringAttributeList.Add(st, l.Value);
                    ListOfItems.Remove(l);
                }
                else if (l.Key.Equals("item"))
                {
                    StringAttributeList.Add("Item", l.Value);
                    InstanceOf = l.Value;
                }
                
                else if (l.Type == ItemType.Attribute)
                {
                   // String st = l.Key[0].ToString().ToUpper()[0] + l.k.Substring(1);
                    StringAttributeList.Add(l.Key, l.Value);
                    ListOfItems.Remove(l);
                }
                else
                {
                    ListOfItems.Add(l);
                }
            }
            UIDispatcher.Invoke(() =>
            {
                BorderBrush = getBrush();
                BorderBrush2 = getHeldBrush();
            });
            

        }