Example #1
0
 protected void _produce(BasicAgent agent, String commodity, double amount, double chance = 1.0)
 {
     if (chance >= 1.0 || Quick.rnd.NextDouble() < chance)
     {
         agent.produceInventory(commodity, amount);
     }
 }
Example #2
0
 public void replaceAgent(BasicAgent oldAgent, BasicAgent newAgent)
 {
     newAgent.id          = oldAgent.id;
     _agents[oldAgent.id] = newAgent;
     oldAgent.destroy();
     newAgent.init(this);
 }
Example #3
0
 public void ReplaceAgent(BasicAgent oldAgent, BasicAgent newAgent)
 {
     newAgent.Id         = oldAgent.Id;
     agents[oldAgent.Id] = newAgent;
     oldAgent.Destroy();
     newAgent.Init(this);
 }
Example #4
0
        override public void perform(BasicAgent agent, Market market)
        {
            var food       = agent.queryInventory("food");
            var metal      = agent.queryInventory("metal");
            var tools      = agent.queryInventory("tools");
            var need_tools = tools < 4;

            var has_food  = food >= 1;
            var has_metal = metal >= 1;

            //_consume(agent, "money", 0.5);//cost of living/business
            _consume(agent, "food", 1);//cost of living

            if (has_food && has_metal & need_tools)
            {
                //convert all metal into tools
                _consume(agent, "metal", metal);
                _produce(agent, "tools", metal);
            }
            else
            {
                //fined $2 for being idle
                //_consume(agent, "money", 2);
                if (!has_food && agent.get_inventoryFull())
                {
                    //make_room_for(agent, "food", 2); stub todo needed?
                }
            }
        }
Example #5
0
        override public void perform(BasicAgent agent, Market market)
        {
            var food  = agent.queryInventory("food");
            var tools = agent.queryInventory("tools");
            var ore   = agent.queryInventory("ore");

            if (ore > 4)
            {
                ore = 4;
            }
            var metal      = agent.queryInventory("metal");
            var need_metal = metal < 4;

            var has_food  = food >= 1;
            var has_tools = tools >= 1;
            var has_ore   = ore >= 1;

            //_consume(agent, "money", 0.5);//cost of living/business
            _consume(agent, "food", 1);//cost of living

            if (has_food && has_ore && need_metal)
            {
                if (has_tools)
                {
                    //convert all ore into metal, consume 1 food, break tools with 10% chance
                    _consume(agent, "ore", ore);
                    _consume(agent, "food", 1);
                    _consume(agent, "tools", 1, 0.1);
                    _produce(agent, "metal", ore);
                }
                else
                {
                    //convert up to 2 ore into metal, consume 1 food
                    var max = agent.queryInventory("ore");
                    if (max > 2)
                    {
                        max = 2;
                    }
                    _consume(agent, "ore", max);
                    _consume(agent, "food", 1);
                    _produce(agent, "metal", max);
                }
            }
            else
            {
                //fined $2 for being idle
                //_consume(agent, "money", 2);
                if (!has_food && agent.get_inventoryFull())
                {
                    //make_room_for(agent, "food", 2);
                }
            }
        }
Example #6
0
 public static int sortAgentId(BasicAgent a, BasicAgent b)
 {
     if (a.id < b.id)
     {
         return(-1);
     }
     if (a.id > b.id)
     {
         return(1);
     }
     return(0);
 }
Example #7
0
 protected void _consume(BasicAgent agent, String commodity, double amount, double chance = 1.0)
 {
     if (chance >= 1.0 || Quick.rnd.NextDouble() < chance)
     {
         //if (commodity == "money")
         //{
         //    agent.changeInventory(comm
         //    agent.money -= amount;
         //}
         //else
         //{
         agent.consumeInventory(commodity, -amount);
         //}
     }
 }
Example #8
0
        override public void Perform(BasicAgent agent, Market market)
        {
            var food     = agent.QueryInventory("food");
            var hasFood  = food >= 1;
            var work     = agent.QueryInventory("work");
            var needWork = work < 1;

            Consume(agent, "food", 1);
            //_consume(agent, "money", 0.5);//cost of living/business

            if (needWork)
            {
                Produce(agent, "work", 1);
            }
        }
Example #9
0
        override public void Perform(BasicAgent agent, Market market)
        {
            var wood     = agent.QueryInventory("wood");
            var tools    = agent.QueryInventory("tools");
            var food     = agent.QueryInventory("food");
            var needFood = food < 10;
            var work     = agent.QueryInventory("work");

            var hasWood  = wood >= 1;
            var hasTools = tools >= 1;
            var hasWork  = work >= 1;

            //_consume(agent, "money", 0.5);//cost of living/business

            if (needFood)
            {
                if (hasWood && hasTools && hasWork)
                {
                    //produce 4 food, consume 1 wood, break tools with 10% chance
                    Consume(agent, "wood", 1, 1);
                    Consume(agent, "tools", 1, 0.1);
                    Consume(agent, "work", 1, 1);
                    Produce(agent, "food", 6, 1);
                }
                else if (hasWood && !hasTools && hasWork)
                {
                    //produce 2 food, consume 1 wood
                    Consume(agent, "wood", 1, 1);
                    Consume(agent, "work", 1, 1);
                    Produce(agent, "food", 3, 1);
                }
                else //no wood
                {
                    //produce 1 food,
                    Produce(agent, "food", 1, 1);
                }
            }
            else
            {
                //fined $2 for being idle
                //_consume(agent, "money", 2);
            }
        }
Example #10
0
        override public void perform(BasicAgent agent, Market market)
        {
            var food     = agent.queryInventory("food");
            var tools    = agent.queryInventory("tools");
            var ore      = agent.queryInventory("ore");
            var need_ore = ore < 4;

            var has_food  = food >= 1;
            var has_tools = tools >= 1;

            //_consume(agent, "money", 0.5);//cost of living/business
            _consume(agent, "food", 1);//cost of living

            if (has_food && need_ore)
            {
                if (has_tools)
                {
                    //produce 4 ore, consume 1 food, break tools with 10% chance
                    _consume(agent, "food", 1);
                    _consume(agent, "tools", 1, 0.1);
                    _produce(agent, "ore", 4);
                }
                else
                {
                    //produce 2 ore, consume 1 food
                    _consume(agent, "food", 1);
                    _produce(agent, "ore", 2);
                }
            }
            else
            {
                //fined $2 for being idle
                //_consume(agent, "money", 2);
                if (!has_food && agent.get_inventoryFull())
                {
                    //make_room_for(agent,"food",2);
                }
            }
        }
Example #11
0
        override public void Perform(BasicAgent agent, Market market)
        {
            var food     = agent.QueryInventory("food");
            var tools    = agent.QueryInventory("tools");
            var wood     = agent.QueryInventory("wood");
            var needWood = wood < 4;

            var hasFood  = food >= 1;
            var hasTools = tools >= 1;

            //_consume(agent, "money", 0.5);//cost of living/business
            Consume(agent, "food", 1);//cost of living

            if (hasFood && needWood)
            {
                if (hasTools)
                {
                    //produce 2 wood, consume 1 food, break tools with 10% chance
                    Consume(agent, "food", 1);
                    Consume(agent, "tools", 1, 0.1);
                    Produce(agent, "wood", 2);
                }
                else
                {
                    //produce 1 wood, consume 1 food
                    Consume(agent, "food", 1);
                    Produce(agent, "wood", 1);
                }
            }
            else
            {
                //fined $2 for being idle
                //_consume(agent, "money", 2);
                if (!hasFood && agent.GetInventoryFull())
                {
                    //make_room_for(agent, "food", 2);
                }
            }
        }
Example #12
0
        /// <summary>
        /// Figures out which which agent is currently most profitable.
        /// This is currently used for bankrupt agents.
        /// </summary>
        /// <param name="market"></param>
        /// <param name="agent"></param>
        private void replaceAgent(Market market, BasicAgent agent)
        {
            var bestClass = market.GetMostProfitableAgentClass();

            //Special case to deal with very high demand-to-supply ratios
            //This will make them favor entering an underserved market over
            //Just picking the most profitable class
            var bestGood = market.GetHottestGood();

            if (bestGood != "")
            {
                var bestGoodClass = GetAgentClassThatMakesMost(bestGood);
                if (bestGoodClass != "")
                {
                    bestClass = bestGoodClass;
                }
            }

            var newAgent = getAgent(market.GetAgentClass(bestClass));

            market.ReplaceAgent(agent, newAgent);
        }
Example #13
0
 public virtual void SignalBankrupt(Market market, BasicAgent agent)
 {
     //no implemenation -- provide your own in a subclass
 }
Example #14
0
        //public function new(?data:Dynamic)
        //{
        //    //no implemenation -- provide your own in a subclass
        //}

        /**
         * Perform this logic on the given agent
         * @param	agent
         */

        public virtual void perform(BasicAgent agent, Market market)
        {
            //no implemenation -- provide your own in a subclass
        }
Example #15
0
        /**
         * Parse a market settings file to construct everything
         * @param	data		the JSON file definition for your Market
         * @param	getAgent	a function to create agents
         */

        public static MarketData fromJSON(string json, BasicAgent getAgent)
        {
            //var goods:Array<Good> = [];

            ////Create goods index
            //var jsonGoods:Array<Dynamic> = json.goods;
            //for (g in jsonGoods)
            //{
            //    goods.push(new Good(g.id, g.size));
            //}

            //var agentTypes:Array<AgentData> = [];

            ////Create agent classes
            //var jsonAgents:Array<Dynamic> = json.agents;

            //for (a in jsonAgents)
            //{
            //    var agentData:AgentData =
            //    {
            //        className:a.id,
            //        money:a.money,
            //        inventory:InventoryData.fromJson(a.inventory),
            //        logicName:a.id,
            //        logic:null
            //    }

            //    for (g in goods)
            //    {
            //        agentData.inventory.size.set(g.id, g.size);
            //    }

            //    agentTypes.push(agentData);
            //}

            ////Make the agent list
            //var agents:Array<BasicAgent> = [];

            ////Get start conditions
            //var startConditions:Dynamic = json.start_conditions;
            //var starts = Reflect.fields(startConditions.agents);

            //var agentIndex:Int = 0;
            ////Make given number of each agent type

            //for (classStr in starts)
            //{
            //    var val:Int = Reflect.field(startConditions.agents, classStr);
            //    var agentData = null;
            //    for (i in 0...agentTypes.length) {
            //        if (agentTypes[i].className == classStr)
            //        {
            //            agentData = agentTypes[i];
            //            break;
            //        }
            //    }

            //    for (i in 0...val)
            //    {
            //        var a:BasicAgent = getAgent(agentData);
            //        a.id = agentIndex;
            //        agentIndex++;
            //        agents.push(a);
            //    }
            //}

            //return new MarketData(goods, agentTypes, agents);
            return(null);
        }
Example #16
0
 //TODO: convert these to refs
 public static int SortAgentAlpha(BasicAgent a, BasicAgent b)
 {
     return(string.Compare(a.ClassName, b.ClassName));
 }
Example #17
0
 public static int sortAgentAlpha(BasicAgent a, BasicAgent b)
 {
     return(String.Compare(a.className, b.className));
 }
Example #18
0
 /// <summary>
 /// An agent ran out of money and now will be replaced!
 /// </summary>
 /// <param name="market"></param>
 /// <param name="agent"></param>
 public override void SignalBankrupt(Market market, BasicAgent agent)
 {
     replaceAgent(market, agent);
 }
Example #19
0
 public override void signalBankrupt(Market m, BasicAgent a)
 {
     replaceAgent(m, a);
 }