public dam(BayesNet Bnet) { this.bnet = Bnet; this.name = "dam"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.chanceToDuplicate = 0; this.priority = 16; }
public grass(BayesNet Bnet) { this.bnet = Bnet; this.name = "grass"; this.category = "Plant"; this.Speed = 0; this.iCanMove = false; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.1; this.priority = 15; }
public mountain(BayesNet Bnet) { this.bnet = Bnet; this.name = "mountain"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.DestroysCategory.Add("Land", true); this.chanceToDuplicate = 5; this.priority = 1; this.resouces.Add("stone", 25); }
public ground(BayesNet Bnet) { this.bnet = Bnet; this.name = "ground"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.DestroysCategory.Add("Land", true); this.DestroysCategory.Add("Fish", true); this.chanceToDuplicate = 0; this.priority = 1; }
public monkey(BayesNet Bnet) { this.bnet = Bnet; this.name = "monkey"; this.category = "Animal"; this.Speed = 2; this.iCanMove = true; this.DestroysCategory.Add("Land", true); this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.02; this.maxSquare = 25; }
public dolphin(BayesNet Bnet) { this.bnet = Bnet; this.name = "dolphin"; this.category = "Animal"; this.Speed = 2; this.iCanMove = true; this.DestroysCategory.Add("Water", true); this.cannotBeWith.Add("land", true); this.chanceToDuplicate = 0.02; this.maxSquare = 20; }
public rabbit(BayesNet Bnet) { this.bnet = Bnet; this.name = "rabbit"; this.category = "Animal"; this.Speed = 2; this.iCanMove = true; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.4; this.priority = 11; this.resouces.Add("meat", 12); this.maxSquare = 25; }
public Agent(BayesNet Bnet, EnvironmentObject home) { this.bnet = Bnet; this.name = "Agent"; this.category = "Animal"; this.Speed = 1; this.iCanMove = true; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.8; this.priority = 15; this.resouces.Add("meat", 25); this.maxSquare = 500; this.goal = "hunt"; if (home.name.Equals("Cave")) { Cave cave = (Cave)home; if (cave.moveIn(this)) this.Home = cave; else this.goal = "findNewHouse"; } else if (home.name.Equals("House")) { House house = (House)home; if (house.moveIn(this)) this.Home = house; else this.goal = "findNewHouse"; } hunts.Add("rabbit", true); // can gather fruits from trees hunts.Add("tree", true); hunts.Add("garden", true); gathers.Add("tree", true); gathers.Add("woodmill", true); gathers.Add("mountain", true); this.Family.Add(this); myMap = new ArrayList[EnvironmentMap.sizeX, EnvironmentMap.sizeY]; // Initialize all ArrayLists to default size (empty) for (int row = 0; row < EnvironmentMap.sizeX; ++row) { for (int column = 0; column < EnvironmentMap.sizeY; ++column) { myMap[row, column] = new ArrayList(); } } }
public garden(BayesNet Bnet, House Owner) { this.bnet = Bnet; this.name = "garden"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.00; this.priority = 16; this.resouces.Add("fruit", 0); this.maxSquare = 5; this.owner = Owner; }
public fish(BayesNet Bnet) { this.bnet = Bnet; this.name = "fish"; this.category = "Fish"; this.Speed = 2; this.iCanMove = true; this.cannotBeWith.Add("ground", true); this.cannotBeWith.Add("mountain", true); this.chanceToDuplicate = 0.3; this.priority = 11; this.resouces.Add("meat", 5); this.maxSquare = 25; }
public tree(BayesNet Bnet) { this.bnet = Bnet; this.name = "tree"; this.category = "Plant"; this.Speed = 0; this.iCanMove = false; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.00; this.priority = 10; this.resouces.Add("wood", 20); this.resouces.Add("syrup", 10); this.resouces.Add("fruit", 5); this.maxSquare = 10; }
public wolf(BayesNet Bnet) { this.bnet = Bnet; this.name = "wolf"; this.category = "Animal"; this.Speed = 2; this.iCanMove = true; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.2; this.priority = 13; this.resouces.Add("meat", 20); this.maxSquare = 10; eats.Add("rabbit", true); eats.Add("jackal", true); }
public water(BayesNet Bnet) { this.bnet = Bnet; this.name = "water"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.priority = -1; this.DestroysCategory.Add("Land", true); this.DestroysCategory.Add("Plant", true); this.DestroysCategory.Add("Animal", true); this.cannotBeWith.Add("mountain", true); this.cannotBeWith.Add("dam", true); this.chanceToDuplicate = 0.05; }
public shark(BayesNet Bnet) { this.bnet = Bnet; this.name = "shark"; this.category = "Fish"; this.Speed = 4; this.iCanMove = true; this.cannotBeWith.Add("ground", true); this.cannotBeWith.Add("mountain", true); this.chanceToDuplicate = 0.2; this.priority = 13; this.resouces.Add("meat", 30); this.maxSquare = 10; eats.Add("fish", true); }
public jackal(BayesNet Bnet) { this.bnet = Bnet; this.name = "jackal"; this.category = "Animal"; this.Speed = 1; this.iCanMove = true; this.cannotBeWith.Add("water", true); this.chanceToDuplicate = 0.2; this.cannotBeWith.Add("mountain", true); this.cannotBeWith.Add("tree", true); this.priority = 12; this.resouces.Add("meat", 16); this.maxSquare = 10; eats.Add("rabbit", true); eats.Add("fish", true); }
public House(BayesNet Bnet) { this.bnet = Bnet; this.name = "House"; this.category = "Land"; this.Speed = 0; this.iCanMove = false; this.chanceToDuplicate = 0; this.priority = 20; this.cannotBeWith.Add("water", true); // setting up the requirements for upgrading int j = 0; Dictionary<string, int> requirements = new Dictionary<string,int>(); while(j < 6) { switch (j) { case 0: requirements.Add("wood", 50); requirements.Add("stone", 0); requirements.Add("NewStorage", 300); requirements.Add("NewCapacity", 20); Upgrades.Add(j, new Dictionary<string,int>(requirements)); break; case 1: requirements["wood"] = 50; requirements["stone"] = 25; requirements["NewStorage"] = 500; requirements["NewCapacity"] = 30; Upgrades.Add(j, new Dictionary<string, int>(requirements)); break; case 2: requirements["wood"] = 75; requirements["stone"] = 50; requirements["NewStorage"] = 700; requirements["NewCapacity"] = 50; Upgrades.Add(j, new Dictionary<string, int>(requirements)); break; case 3: requirements["wood"] = 100; requirements["stone"] = 150; requirements["NewStorage"] = 1000; requirements["NewCapacity"] = 75; Upgrades.Add(j, new Dictionary<string, int>(requirements)); break; case 4: requirements["wood"] = 150; requirements["stone"] = 200; requirements["NewStorage"] = 2000; requirements["NewCapacity"] = 100; Upgrades.Add(j, new Dictionary<string, int>(requirements)); break; case 5: requirements["wood"] = 300; requirements["stone"] = 300; requirements["NewStorage"] = 2500; requirements["NewCapacity"] = 150; Upgrades.Add(j, new Dictionary<string, int>(requirements)); break; } ++j; } }
//testing out creating a BayesNet... isn't that easy? =) public static void testNetAsGraph() { BayesNet bnet = new BayesNet(); /*bnet.addNode("cloudy", 0.5); bnet.addNode("raining", 0.2); bnet.addNode("cold", 0.33); bnet.addNode("snowing", 0.2); bnet.addNode("hailing", 0.1); bnet.addEdge("cloudy", "raining", 1.4, 0.2); //test inference here... bnet.addEdge("cloudy", "snowing", 1.2, 0.2); bnet.addEdge("cold", "snowing", 1.6, 0.2); bnet.addEdge("raining", "snowing", 0.4, 1.2); bnet.addEdge("raining", "hailing", 1.5); bnet.addEdge("snowing", "hailing", 1.5); //test inference here... //with just these influences we should be able to get chance of cloudy if it's snowing or raining. Console.WriteLine("BayesNet test:\n"); Console.WriteLine("Nodes:\n"+bnet.Nodes.toString()); //ya sorry, can't override using method extensions >=( Console.WriteLine("Edges:\n" + bnet.Edges.ToString()); Console.ReadKey(); // Now lets keep testing things // lets do some randomness double P = bnet.infer("cloudy"); double next = new double(); Random randnum = new Random(System.DateTime.Now.Millisecond); next = randnum.NextDouble(); if (P < next) bnet["cloudy"].ObservedValue = false; else bnet["cloudy"].ObservedValue = true; P = bnet.infer("cold"); next = randnum.NextDouble(); if (P < next) bnet["cold"].ObservedValue = false; else bnet["cold"].ObservedValue = true; Console.WriteLine("BayesNet test:\n"); Console.WriteLine("Nodes:\n" + bnet.Nodes.toString()); //ya sorry, can't override using method extensions >=( Console.WriteLine("Edges:\n" + bnet.Edges.ToString()); Console.WriteLine("Chances of it raining:" + bnet.infer("raining")); Console.WriteLine("Chances of it snowing:" + bnet.infer("snowing")); Console.WriteLine("Chances of it hailing:" + bnet.infer("hailing")); Console.ReadKey(); // now lets see if its raining P = bnet.infer("raining"); next = randnum.NextDouble(); if (P < next) bnet["raining"].ObservedValue = false; else bnet["raining"].ObservedValue = true; Console.WriteLine("BayesNet test:\n"); Console.WriteLine("Nodes:\n" + bnet.Nodes.toString()); //ya sorry, can't override using method extensions >=( Console.WriteLine("Edges:\n" + bnet.Edges.ToString()); Console.WriteLine("Chances of it snowing:" + bnet.infer("snowing")); Console.WriteLine("Chances of it hailing:" + bnet.infer("hailing")); Console.ReadKey(); // now we check if its snowing P = bnet.infer("snowing"); next = randnum.NextDouble(); if (P < next) bnet["snowing"].ObservedValue = false; else bnet["snowing"].ObservedValue = true; Console.WriteLine("BayesNet test:\n"); Console.WriteLine("Nodes:\n" + bnet.Nodes.toString()); //ya sorry, can't override using method extensions >=( Console.WriteLine("Edges:\n" + bnet.Edges.ToString()); Console.WriteLine("Chances of it hailing:" + bnet.infer("hailing")); Console.ReadKey(); // and lastly we check if its hailing P = bnet.infer("hailing"); next = randnum.NextDouble(); if (P < next) bnet["hailing"].ObservedValue = false; else bnet["hailing"].ObservedValue = true; Console.WriteLine("BayesNet test:\n"); Console.WriteLine("Nodes:\n" + bnet.Nodes.toString()); //ya sorry, can't override using method extensions >=( Console.WriteLine("Edges:\n" + bnet.Edges.ToString()); Console.ReadKey();*/ }
public void setUpBnet() { bnet = new BayesNet(); EnvironmentMap.setup(); bnet.addNode("Season", new[] { "Spring", "Summer", "Fall", "Winter" }); bnet.addNode("Monsoon", new[] { "false", "true" }); bnet.addNode("temperature", new[] { "cool", "cold", "warm", "hot" }); bnet.addNode("humidity", new[] { "dry", "halfHumid", "humid" }); bnet.addNode("wind", new[] { "calmWinds", "windy", "strongWinds" }); bnet.addNode("clouds", new[] { "clearSky", "partiallyCloudy", "cloudy" }); bnet.addNode("precipitation", new[] { "noPrecepitation", "raining", "snowing", "hailing" }); bnet.addNode("lightning", new[] { "false", "true" }); //-- //CURRENT effects: //The seasons! //There are a lot of ways to do Intensity Matrices. bnet.addEdge("Season", "temperature") .addGeneralProbability("Spring", new[] { 0.2, 0.30, 0.4, 0.1 }, 3) //summer is hot .addGeneralProbability("Summer", new[] { 0.01, 0.25, 0.75, 0.5 }, 3) //fall is slightly cool .addGeneralProbability("Fall", new[] { 0.1, 0.4, 0.3, 0.2 }, 3) //winter is cold .addGeneralProbability("Winter", new[] { 0.5, 0.75, 0.25, 0.01 }, 3); bnet.addEdge("Season", "humidity") .addGeneralProbability("Spring", new[] { 0.2, 0.4, 0.4 }, 5); bnet.addEdge("Season", "wind") .addGeneralProbability("Spring", new[] {0.2, 0.4, 0.6}, 1); bnet.addEdge("Monsoon", "humidity") //no chance of no humidity, low chance of halfhumid, high chance of very humid. .addGeneralProbability("true", new[] { 0, 0.1, 0.9 }, 10); bnet.addEdge("Monsoon", "precipitation") .addGeneralProbability("true", new[] { 0.1, 0.6, 0.1, 0.2 }, 10); //more clouds, and humid it is, the higher chance of raining. bnet.addEdge("clouds", "precipitation") .addGeneralProbability("clearSky", new[] { 0.85, 0.05, 0.05, 0.05 }, 5) .addGeneralProbability("partiallyCloudy", new[] { 0.4, 0.2, 0.2, 0.2 }, 3) .addGeneralProbability("cloudy", new[] { 0.1, 0.3, 0.3, 0.3 }, 1); //TODO: make precipitation lower cloud distribution, and lack of precipitation increase cloud distribution. //bnet.addEdge("noPrecepitation", // new double[] { 0.4, 0.3, 0.25 }, true, true); bnet.addEdge("humidity", "precipitation") .addGeneralProbability("humid", new[] { 0.2, 0.25, 0.25, 0.3 }, 3) .addGeneralProbability("halfHumid", new[] { 0.5, 0.2, 0.2, 0.1 }, 2); bnet.addEdge("temperature", "precipitation") .addGeneralProbability("cold", new[] { 0.45, 0.05, 0.4, 0.1 }, 8) //when it snows, it keeps snowing for a long time? .addGeneralProbability("cool", new[] { 0.25, 0.25, 0.3, 0.2 }, 3) .addGeneralProbability("warm", new[] { 0.5, 0.45, 0.01, 0.04 }, 3) .addGeneralProbability("hot", new[] { 0.55, 0.43, 0.01, 0.01 }, 2); //tornedo is out of service, until I think of a better way to do it. Right now it's just hail... no tornedo =\ //bnet.addEdge("strongWinds", //I'm thinking tornados. // new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, // new double[] { 0.3, 0.2, 0.1, 0.4 }); bnet.addEdge("precipitation", "lightning") //raining = 1.2, 0.1); .addGeneralProbability("raining", new[] { 1.5, 1.0 }, 1); //storm is out of commission until I can do it better. //bnet.addEdge("wind", "lightning") //strongWinds = 1.3, 0.1); //I guess this implies a storm? // .addGeneralProbability("strongWinds", new[] { 1.3, 0.1 }); //PREVIOUS //from my understanding, humidity builds up clouds. If it is really humid a number of days in summer, you expect a large storm. bnet.addEdge("humidity", "clouds") .addGeneralProbability("humid", new[] { 0.15, 0.35, 0.5 }, 5) .addGeneralProbability("dry", new[] { 0.5, 0.3, 0.2 }, 3); //if it's windy the clouds may have passed. bnet.addEdge("wind", "clouds") .addGeneralProbability("strongWinds", new[] { 0.5, 0.25, 0.25 }, 1); bnet.InitializeRandomStartValues(); bnet.Initialize(); #region oldEdgeCode /* * bnet.addEdge("Spring", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.1, 0.35, 0.35, 0.2 }); bnet.addEdge("Spring", new string[] { "humid", "halfHumid", "dry" }, new double[] { 0.45, 0.35, 0.2 }); //summer is hot bnet.addEdge("Summer", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.05, 0.2, 0.35, 0.4 }); //fall is slightly cool, and windy bnet.addEdge("Fall", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.2, 0.35, 0.35, 0.1 }); bnet.addEdge("Spring", new string[] { "strongWinds", "windy", "calmWinds" }, new double[] { 0.45, 0.35, 0.2 }); //winter is cold bnet.addEdge("Winter", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.4, 0.35, 0.2, 0.05 }); bnet.addEdge("Monsoon", new string[] { "humid", "halfHumid", "dry" }, new double[] { 0.9, 0.1, 0.0 }); bnet.addEdge("Monsoon", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.1, 0.6, 0.1, 0.2 }); //more clouds, and humid it is, the higher chance of raining. bnet.addEdge("cloudy", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.1, 0.3, 0.3, 0.3 }); bnet.addEdge("partiallyCloudy", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.4, 0.2, 0.2, 0.2 }); bnet.addEdge("clearSky", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.85, 0.05, 0.05, 0.05 }); bnet.addEdge("humid", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.2, 0.25, 0.25, 0.3 }); bnet.addEdge("dry", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.5, 0.2, 0.2, 0.1 }); bnet.addEdge("cold", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.45, 0.05, 0.4, 0.1 }); bnet.addEdge("cool", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.25, 0.25, 0.3, 0.2 }); bnet.addEdge("warm", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.5, 0.45, 0.01, 0.04 }); bnet.addEdge("hot", new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.55, 0.43, 0.01, 0.01 }); bnet.addEdge("strongWinds", //I'm thinking tornados. new string[] { "noPrecepitation", "raining", "snowing", "hailing" }, new double[] { 0.3, 0.2, 0.1, 0.4 }); bnet.addEdge("raining", "lightning", 1.2, 0.1); bnet.addEdge("strongWinds", "lightning", 1.3, 0.1); //PREVIOUS //from my understanding, humidity builds up clouds. If it is really humid a number of days in summer, you expect a large storm. bnet.addEdge("humid", new string[] { "clearSky", "partiallyCloudy", "cloudy" }, new double[] { 0.15, 0.35, 0.5 }, true); bnet.addEdge("dry", new string[] { "clearSky", "partiallyCloudy", "cloudy" }, new double[] { 0.5, 0.3, 0.2 }, true); //temperature usually stays moderately consistant. This will help keep it from jumping from hot to cold so easily. bnet.addEdge("cold", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.35, 0.3, 0.2, 0.15 }, true); bnet.addEdge("cool", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.25, 0.3, 0.25, 0.2 }, true); bnet.addEdge("warm", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.2, 0.25, 0.3, 0.25 }, true); bnet.addEdge("hot", new string[] { "cold", "cool", "warm", "hot" }, new double[] { 0.15, 0.2, 0.3, 0.35 }, true); //if their was no raining, then the clouds should generally still exist. Unless ofcourse they passed. bnet.addEdge("noPrecepitation", new string[] { "cloudy", "partiallyCloudy", "clearSky" }, new double[] { 0.4, 0.3, 0.25 },true, true); //if it's windy the clouds may have passed. bnet.addEdge("windy", new string[] { "cloudy", "partiallyCloudy", "clearSky" }, new double[] { 0.25, 0.25, 0.5 }, true); * */ #endregion }