public void MSTest_pack_moveException() { Pack pack = new Pack("Pack1", 4); Node node1 = new Node(); Node node2 = new Node(); pack.location = node1; pack.move(node2); }
public void MStest_move_to_nonconnected_node() { Node N0 = new Node("N0"); Node N1 = new Node("N1"); Pack p = new Pack("pid", 3); p.location = N0; N0.packs.Add(p); p.move(N1); }
public void MStest_move_when_able() { Dungeon d = new Dungeon(5); Pack p = new Pack("pid", 3); p.dungeon = d; p.location = d.zone[1][0]; d.zone[1][0].packs.Add(p); p.move(d.zone[1][1]); Assert.IsTrue(p.location == d.zone[1][1]); }
public void MStest_move_with_insufficient_capacity() { Dungeon d = new Dungeon(5); Pack p = new Pack("pid", 3); Pack q = new Pack("qid", (d.M * (d.level(d.zone[1][1]) + 1))); p.dungeon = d; q.dungeon = d; p.location = d.zone[1][0]; q.location = d.zone[1][1]; d.zone[1][0].packs.Add(p); d.zone[1][1].packs.Add(q); p.move(d.zone[1][1]); Assert.IsTrue(p.location == d.zone[1][0]); }
public void MSTest_pack_move_success() { Pack pack = new Pack("Mover", 3); Node node = new Node("node1"); Node node2 = new Node("node2"); Dungeon dungeon = new Dungeon(3, 3); pack.location = node; pack.dungeon = dungeon; node.packs.Add(pack); node.neighbors.Add(node2); pack.move(node2); Assert.AreNotEqual(pack.location, node); Assert.AreEqual(pack.location, node2); }
/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player) { if (packs.Count == 0 || player == null) { return; } // calculate flee probability Pack pack = packs[0]; int currentHP = pack.currentTotalHP(); float probability = (1f - currentHP / pack.startingHP) / 2f; float percentage = probability * 100; float randomNr = RandomGenerator.rnd.Next(0, 101); // pack attempts to flee if (randomNr <= percentage) { // move to first node which is not overpopulated foreach (Node n in neighbors) { // calculate max capacity uint capacity = pack.dungeon.M * (pack.dungeon.level(n) + 1); // calculate current population in node int population = 0; foreach (Pack p in n.packs) { population += p.members.Count; } // move to node if pack fits in it and pack remains in its own zone (level) if (population + pack.members.Count <= capacity && pack.dungeon.level(pack.location) == pack.dungeon.level(n)) { pack.move(n); break; } } } // pack attacks player else { pack.Attack(player); } }
public void MSTest_pack_move_fullcapacity() { Pack pack = new Pack("Hero", 3); Pack pack2 = new Pack("Gatekeeper", 3); Node node = new Node(); Node node2 = new Node(); Dungeon dungeon = new Dungeon(3, 3); pack.location = node; pack2.location = node2; pack.dungeon = dungeon; pack2.dungeon = dungeon; node.packs.Add(pack); node2.packs.Add(pack2); node.neighbors.Add(node2); pack.move(node2); Assert.AreNotEqual(pack.location, node2); Assert.AreEqual(pack.location, node); }
/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player, Dungeon dungeon) { //select pack Pack randomPack = packs.GetRandomItem(); //calc pack HP int currentHP = 0; foreach (Monster member in randomPack.members.ToList()) { currentHP += member.HP; } float fleeProbability = (1 - (float)currentHP / (float)randomPack.startingHP) / 2 * 100; //Console.WriteLine(fleeProbability); //%%%%%%%%%%% Pack Turn %%%%%%%%%%% if (fleeProbability > (float)RandomGenerator.rnd.Next(0, 100)) { //the pack flees Node randomNeighbor = randomPack.getRandomValidNeighbour(dungeon); if (randomNeighbor != null) { Console.WriteLine("Pack {0} flees.", randomPack.id); randomPack.move(randomNeighbor, player.location); if (this.packs.Count == 0) { contested = false; return; } randomPack = packs.GetRandomItem(); } } //pack attack randomPack.Attack(player); player.location.contested = player.location.packs.Count > 0 && player.HP > 0; }
/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player, int seed, bool withSeed) //now runs a single enemy turn { if (withSeed) { RandomGenerator.initializeWithSeed(seed); } rnd = RandomGenerator.rnd; /*Possibly to do: * - Attack after failed flee attempt? (currently present)*/ //throw new NotImplementedException(); //still missing node contest check Pack attackPack = packs[rnd.Next(packs.Count - 1)]; double fleeCheck = rnd.NextDouble(); double packHP = attackPack.CurrentHP(); double fleeTreshold = (1 - (packHP / attackPack.startingHP)) / 2; if (fleeCheck <= fleeTreshold) { Logger.log("A pack tries to flee"); foreach (Node n in attackPack.location.neighbors) { attackPack.move(n); if (n.packs.Contains(attackPack)) { Logger.log("A pack flees!"); packs.Remove(attackPack); if (contested(player)) { attackPack = packs[rnd.Next(packs.Count - 1)]; } break; } } } if (contested(player)) { attackPack.Attack(player); } }