Increased desired chance of success for lock population
This commit is contained in:
parent
03f0f7859e
commit
fd1700d650
13 changed files with 34 additions and 15 deletions
|
|
@ -1,4 +1,13 @@
|
||||||
using DiceProbabilities;
|
using DiceProbabilities;
|
||||||
|
|
||||||
Console.WriteLine(DiceRollProbability.RollFourPickTwoPickTwoAgainOdds());
|
string input = Console.ReadLine();
|
||||||
|
while (input != "")
|
||||||
|
{
|
||||||
|
|
||||||
|
List<string>? inputtedOptions = input?.Split(',').ToList();
|
||||||
|
float odds = RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(inputtedOptions);
|
||||||
|
Console.WriteLine(odds);
|
||||||
|
input = Console.ReadLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -11,7 +11,7 @@ namespace DiceProbabilities
|
||||||
{"=", .6296f },
|
{"=", .6296f },
|
||||||
{"2", .1319f},
|
{"2", .1319f},
|
||||||
{"3", .2330f},
|
{"3", .2330f},
|
||||||
{"4", 3557f},
|
{"4", .3557f},
|
||||||
{"5", .4475f},
|
{"5", .4475f},
|
||||||
{"6", .5610f},
|
{"6", .5610f},
|
||||||
{"7", .6435f},
|
{"7", .6435f},
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -7,11 +7,11 @@ namespace DungeonMapGenerator
|
||||||
{
|
{
|
||||||
public static class DungeonLockPopulator
|
public static class DungeonLockPopulator
|
||||||
{
|
{
|
||||||
private const float ACCEPTABLE_ERROR = .1319f;
|
private const float ACCEPTABLE_ERROR = .02f;
|
||||||
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
|
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
|
||||||
{
|
{
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
float desiredSuccessChance = .80f;
|
float desiredSuccessChance = .995f;
|
||||||
|
|
||||||
List<Room> currentRooms = dungeon.GetEntranceRooms();
|
List<Room> currentRooms = dungeon.GetEntranceRooms();
|
||||||
HashSet<Room> seenRooms = new HashSet<Room>(currentRooms);
|
HashSet<Room> seenRooms = new HashSet<Room>(currentRooms);
|
||||||
|
|
@ -21,12 +21,14 @@ namespace DungeonMapGenerator
|
||||||
int entranceRoomLock = 1;
|
int entranceRoomLock = 1;
|
||||||
foreach (Room entranceRoom in currentRooms)
|
foreach (Room entranceRoom in currentRooms)
|
||||||
{
|
{
|
||||||
entranceRoom.Lock = new Lock((entranceRoomLock + 1.ToString()));
|
entranceRoomLock += 1;
|
||||||
|
entranceRoom.Lock = new Lock((entranceRoomLock.ToString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
while (currentRooms.Count > 0)
|
while (currentRooms.Count > 0)
|
||||||
{
|
{
|
||||||
List<Room> locklessRooms = new List<Room>();
|
List<Room> locklessRooms = new List<Room>();
|
||||||
|
List<Room> alreadyLockedRooms = new List<Room>();
|
||||||
List<Room> adjacentRooms = new List<Room>();
|
List<Room> adjacentRooms = new List<Room>();
|
||||||
|
|
||||||
// Get all adjacent rooms that haven't been locked at
|
// Get all adjacent rooms that haven't been locked at
|
||||||
|
|
@ -42,13 +44,12 @@ namespace DungeonMapGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the odds of locks already set.
|
// Sort locked and not locked rooms
|
||||||
foreach (Room adjacentRoom in adjacentRooms.ToList())
|
foreach (Room adjacentRoom in adjacentRooms.ToList())
|
||||||
{
|
{
|
||||||
List<float> odds = new List<float>();
|
|
||||||
if (adjacentRoom.Lock != null)
|
if (adjacentRoom.Lock != null)
|
||||||
{
|
{
|
||||||
odds.Add(adjacentRoom.Lock.GetOdds());
|
alreadyLockedRooms.Add(adjacentRoom);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -56,10 +57,17 @@ namespace DungeonMapGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get locks of locked rooms
|
||||||
|
List<Lock> pregeneratedLocks = new List<Lock>();
|
||||||
|
foreach (Room room in alreadyLockedRooms)
|
||||||
|
{
|
||||||
|
pregeneratedLocks.Add(room.Lock);
|
||||||
|
}
|
||||||
|
|
||||||
if (locklessRooms.Count > 0)
|
if (locklessRooms.Count > 0)
|
||||||
{
|
{
|
||||||
// Add locks to the rooms with odds adding to within the difficulty range
|
// Add locks to the rooms with odds adding to within the difficulty range
|
||||||
List<Lock> locks = GenerateLocks(locklessRooms.Count, desiredSuccessChance);
|
List<Lock> locks = GenerateLocks(pregeneratedLocks, locklessRooms.Count, desiredSuccessChance);
|
||||||
for (int i = 0; i < locklessRooms.Count; i++)
|
for (int i = 0; i < locklessRooms.Count; i++)
|
||||||
{
|
{
|
||||||
locklessRooms[i].Lock = locks[i];
|
locklessRooms[i].Lock = locks[i];
|
||||||
|
|
@ -70,10 +78,10 @@ namespace DungeonMapGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Lock> GenerateLocks(int numLocks, float successChance)
|
private static List<Lock> GenerateLocks(List<Lock> pregeneratedLocks, int numLocks, float successChance)
|
||||||
{
|
{
|
||||||
List<Lock> locks = new List<Lock>();
|
List<Lock> locks = new List<Lock>();
|
||||||
if (FindCombination(locks, numLocks, successChance, Lock.PossibleLocks))
|
if (FindCombination(pregeneratedLocks, locks, numLocks, successChance, Lock.PossibleLocks))
|
||||||
{
|
{
|
||||||
return locks;
|
return locks;
|
||||||
}
|
}
|
||||||
|
|
@ -81,11 +89,13 @@ namespace DungeonMapGenerator
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool FindCombination(List<Lock> generatedLocks, int numLocks, float successChance, List<Lock> lockOptions)
|
private static bool FindCombination(List<Lock> pregeneratedLocks, List<Lock> generatedLocks, int numLocks, float successChance, List<Lock> lockOptions)
|
||||||
{
|
{
|
||||||
if (generatedLocks.Count == numLocks)
|
if (generatedLocks.Count == numLocks)
|
||||||
{
|
{
|
||||||
List<string> locksAsStrings = generatedLocks.Select(_lock => _lock.GetLock()).ToList();
|
List<Lock> allLocks = new List<Lock>(pregeneratedLocks);
|
||||||
|
allLocks.AddRange(generatedLocks);
|
||||||
|
List<string> locksAsStrings = allLocks.Select(_lock => _lock.GetLock()).ToList();
|
||||||
|
|
||||||
// Return true if given the current locks the chance of being able to open one is close to difficulty
|
// Return true if given the current locks the chance of being able to open one is close to difficulty
|
||||||
float probalityOfAtleastOneUnlocking = RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings);
|
float probalityOfAtleastOneUnlocking = RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings);
|
||||||
|
|
@ -103,7 +113,7 @@ namespace DungeonMapGenerator
|
||||||
if (RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings) <= successChance)
|
if (RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings) <= successChance)
|
||||||
{
|
{
|
||||||
generatedLocks.Add(new Lock(_lock.GetLock()));
|
generatedLocks.Add(new Lock(_lock.GetLock()));
|
||||||
if (FindCombination(generatedLocks, numLocks, successChance, lockOptions))
|
if (FindCombination(pregeneratedLocks, generatedLocks, numLocks, successChance, lockOptions))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue