Compare commits
2 commits
ea1ca7a0cd
...
8de86aa1ac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8de86aa1ac | ||
|
|
03f0f7859e |
43 changed files with 13918 additions and 57 deletions
13
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/.gitignore
generated
vendored
Normal file
13
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/projectSettingsUpdater.xml
|
||||
/modules.xml
|
||||
/contentModel.xml
|
||||
/.idea.DiceProbabilities.iml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
8
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/indexLayout.xml
generated
Normal file
8
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/indexLayout.xml
generated
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/vcs.xml
generated
Normal file
6
DiceProbabilities/.idea/.idea.DiceProbabilities/.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
13
DiceProbabilities/DiceProbabilitesPrinter/Program.cs
Normal file
13
DiceProbabilities/DiceProbabilitesPrinter/Program.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using DiceProbabilities;
|
||||
|
||||
string input = Console.ReadLine();
|
||||
while (input != "")
|
||||
{
|
||||
|
||||
List<string>? inputtedOptions = input?.Split(',').ToList();
|
||||
float odds = RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(inputtedOptions);
|
||||
Console.WriteLine(odds);
|
||||
input = Console.ReadLine();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v9.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v9.0": {
|
||||
"DiceProbabilitesPrinter/1.0.0": {
|
||||
"dependencies": {
|
||||
"DiceProbabilities": "1.0.0"
|
||||
},
|
||||
"runtime": {
|
||||
"DiceProbabilitesPrinter.dll": {}
|
||||
}
|
||||
},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"runtime": {
|
||||
"DiceProbabilities.dll": {
|
||||
"assemblyVersion": "1.0.0",
|
||||
"fileVersion": "1.0.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"DiceProbabilitesPrinter/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net9.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "9.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
129
DiceProbabilities/DiceProbabilities/RollFourSumTwo.cs
Normal file
129
DiceProbabilities/DiceProbabilities/RollFourSumTwo.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DiceProbabilities
|
||||
{
|
||||
public static class RollFourSumTwo
|
||||
{
|
||||
public static readonly Dictionary<string, float> ResultOddsmapping = new Dictionary<string, float>()
|
||||
{
|
||||
{"=", .6296f },
|
||||
{"2", .1319f},
|
||||
{"3", .2330f},
|
||||
{"4", .3557f},
|
||||
{"5", .4475f},
|
||||
{"6", .5610f},
|
||||
{"7", .6435f},
|
||||
{"8", .5610f},
|
||||
{"9", .4475f},
|
||||
{"10", .3557f},
|
||||
{"11", .2340f},
|
||||
{"12", .1319f}
|
||||
|
||||
};
|
||||
|
||||
public static float GetProbalityOfAtleastOneUnlocking(List<string> options)
|
||||
{
|
||||
float probabilityNoDiceWillSumToLocks = 1;
|
||||
foreach (var option in options)
|
||||
{
|
||||
if (ResultOddsmapping.TryGetValue(option, out var value))
|
||||
{
|
||||
probabilityNoDiceWillSumToLocks *= (1 - value);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"{option} is not a valid result for the sum of two dice.");
|
||||
}
|
||||
}
|
||||
|
||||
return 1 - probabilityNoDiceWillSumToLocks;
|
||||
}
|
||||
|
||||
public static string RollFourPickTwoPickTwoAgainOdds()
|
||||
{
|
||||
// Total number of rolls (6^4 = 1296 possible outcomes)
|
||||
int possibleDiceCombosCount = 0;
|
||||
|
||||
// Counter for the possible sums
|
||||
Dictionary<(string, string), int> selectionsCounts = new Dictionary<(string, string), int>();
|
||||
double diceEqualCount = 0;
|
||||
|
||||
// Generate all possible rolls of 4 dice
|
||||
for (int d1 = 1; d1 <= 6; d1++)
|
||||
{
|
||||
for (int d2 = 1; d2 <= 6; d2++)
|
||||
{
|
||||
for (int d3 = 1; d3 <= 6; d3++)
|
||||
{
|
||||
for (int d4 = 1; d4 <= 6; d4++)
|
||||
{
|
||||
// Get all possible pairs of dice
|
||||
var possibleDiceSlections = new List<((int, int), (int, int))>
|
||||
{
|
||||
((d1, d2), (d3, d4)), ((d1, d3), (d2, d4)), ((d1, d4), (d2, d3)),
|
||||
((d2, d3), (d1, d4)), ((d2, d4), (d1, d3)),
|
||||
((d3, d4), (d1, d2))
|
||||
};
|
||||
|
||||
foreach (((int, int), (int, int)) selections in possibleDiceSlections)
|
||||
{
|
||||
possibleDiceCombosCount++;
|
||||
var firstSelection = selections.Item1;
|
||||
var secondSelection = selections.Item2;
|
||||
string firstSelectionResult;
|
||||
string secondSelectionResult;
|
||||
if (firstSelection.Item1 == firstSelection.Item2)
|
||||
{
|
||||
firstSelectionResult = "=";
|
||||
if (secondSelection.Item1 == secondSelection.Item2)
|
||||
{
|
||||
secondSelectionResult = "=";
|
||||
IncrementSelectionsCounts(selectionsCounts, (firstSelectionResult, secondSelectionResult));
|
||||
}
|
||||
|
||||
secondSelectionResult = (secondSelection.Item1 + secondSelection.Item2).ToString();
|
||||
IncrementSelectionsCounts(selectionsCounts, (firstSelectionResult, secondSelectionResult));
|
||||
}
|
||||
|
||||
firstSelectionResult = (firstSelection.Item1 + firstSelection.Item2).ToString();
|
||||
if (secondSelection.Item1 == secondSelection.Item2)
|
||||
{
|
||||
secondSelectionResult = "=";
|
||||
IncrementSelectionsCounts(selectionsCounts, (firstSelectionResult, secondSelectionResult));
|
||||
}
|
||||
|
||||
secondSelectionResult = (secondSelection.Item1 + secondSelection.Item2).ToString();
|
||||
IncrementSelectionsCounts(selectionsCounts, (firstSelectionResult, secondSelectionResult));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append("Sum\tProbability (%)" + Environment.NewLine);
|
||||
|
||||
// sb.Append($"=\t{diceEqualCount / possibleDiceCombosCount * 100:F2}%{Environment.NewLine}");
|
||||
foreach (var selections in selectionsCounts.Keys)
|
||||
{
|
||||
double probability = (double)selectionsCounts[selections] / possibleDiceCombosCount * 100;
|
||||
sb.Append($"{selections}\t{probability:F2}%{Environment.NewLine}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static void IncrementSelectionsCounts(Dictionary<(string, string), int> dict, (string, string) key)
|
||||
{
|
||||
if (!dict.ContainsKey(key))
|
||||
{
|
||||
dict[key] = 0;
|
||||
}
|
||||
|
||||
dict[key]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETStandard,Version=v2.0/",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETStandard,Version=v2.0": {},
|
||||
".NETStandard,Version=v2.0/": {
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "2.0.3"
|
||||
},
|
||||
"runtime": {
|
||||
"DiceProbabilities.dll": {}
|
||||
}
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.1.0": {},
|
||||
"NETStandard.Library/2.0.3": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Platforms": "1.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
},
|
||||
"Microsoft.NETCore.Platforms/1.1.0": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A==",
|
||||
"path": "microsoft.netcore.platforms/1.1.0",
|
||||
"hashPath": "microsoft.netcore.platforms.1.1.0.nupkg.sha512"
|
||||
},
|
||||
"NETStandard.Library/2.0.3": {
|
||||
"type": "package",
|
||||
"serviceable": true,
|
||||
"sha512": "sha512-st47PosZSHrjECdjeIzZQbzivYBJFv6P2nv4cj2ypdI204DO+vZ7l5raGMiX4eXMJ53RfOIg+/s4DHVZ54Nu2A==",
|
||||
"path": "netstandard.library/2.0.3",
|
||||
"hashPath": "netstandard.library.2.0.3.nupkg.sha512"
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
13
DiceProbabilities/Roll4Add2.txt
Normal file
13
DiceProbabilities/Roll4Add2.txt
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
Sum Probability (%)
|
||||
= 62.96%
|
||||
2 13.19%
|
||||
3 23.30%
|
||||
4 35.57%
|
||||
5 44.75%
|
||||
6 56.10%
|
||||
7 64.35%
|
||||
8 56.10%
|
||||
9 44.75%
|
||||
10 35.57%
|
||||
11 23.40%
|
||||
12 13.19%
|
||||
145
DiceProbabilities/Roll4Add2AddOther2.txt
Normal file
145
DiceProbabilities/Roll4Add2AddOther2.txt
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
Sum Probability (%)
|
||||
(=, =) 2.78%
|
||||
(=, 2) 0.46%
|
||||
(2, =) 0.46%
|
||||
(2, 2) 0.08%
|
||||
(=, 3) 0.93%
|
||||
(2, 3) 0.15%
|
||||
(3, =) 0.93%
|
||||
(3, 2) 0.15%
|
||||
(=, 4) 1.39%
|
||||
(2, 4) 0.23%
|
||||
(4, =) 1.39%
|
||||
(4, 2) 0.23%
|
||||
(=, 5) 1.85%
|
||||
(2, 5) 0.31%
|
||||
(5, =) 1.85%
|
||||
(5, 2) 0.31%
|
||||
(=, 6) 2.31%
|
||||
(2, 6) 0.39%
|
||||
(6, =) 2.31%
|
||||
(6, 2) 0.39%
|
||||
(=, 7) 2.78%
|
||||
(2, 7) 0.46%
|
||||
(7, =) 2.78%
|
||||
(7, 2) 0.46%
|
||||
(3, 3) 0.31%
|
||||
(3, 4) 0.46%
|
||||
(4, 3) 0.46%
|
||||
(3, 5) 0.62%
|
||||
(5, 3) 0.62%
|
||||
(3, 6) 0.77%
|
||||
(6, 3) 0.77%
|
||||
(=, 8) 2.31%
|
||||
(2, 8) 0.39%
|
||||
(3, 7) 0.93%
|
||||
(7, 3) 0.93%
|
||||
(8, =) 2.31%
|
||||
(8, 2) 0.39%
|
||||
(4, 4) 0.69%
|
||||
(4, 5) 0.93%
|
||||
(5, 4) 0.93%
|
||||
(4, 6) 1.16%
|
||||
(6, 4) 1.16%
|
||||
(=, 9) 1.85%
|
||||
(2, 9) 0.31%
|
||||
(4, 7) 1.39%
|
||||
(7, 4) 1.39%
|
||||
(9, =) 1.85%
|
||||
(9, 2) 0.31%
|
||||
(5, 5) 1.23%
|
||||
(5, 6) 1.54%
|
||||
(6, 5) 1.54%
|
||||
(=, 10) 1.39%
|
||||
(2, 10) 0.23%
|
||||
(5, 7) 1.85%
|
||||
(7, 5) 1.85%
|
||||
(10, =) 1.39%
|
||||
(10, 2) 0.23%
|
||||
(6, 6) 1.93%
|
||||
(=, 11) 0.93%
|
||||
(2, 11) 0.15%
|
||||
(6, 7) 2.31%
|
||||
(7, 6) 2.31%
|
||||
(11, =) 0.93%
|
||||
(11, 2) 0.15%
|
||||
(=, 12) 0.46%
|
||||
(2, 12) 0.08%
|
||||
(7, 7) 2.78%
|
||||
(12, =) 0.46%
|
||||
(12, 2) 0.08%
|
||||
(3, 8) 0.77%
|
||||
(8, 3) 0.77%
|
||||
(3, 9) 0.62%
|
||||
(4, 8) 1.16%
|
||||
(8, 4) 1.16%
|
||||
(9, 3) 0.62%
|
||||
(3, 10) 0.46%
|
||||
(5, 8) 1.54%
|
||||
(8, 5) 1.54%
|
||||
(10, 3) 0.46%
|
||||
(3, 11) 0.31%
|
||||
(6, 8) 1.93%
|
||||
(8, 6) 1.93%
|
||||
(11, 3) 0.31%
|
||||
(3, 12) 0.15%
|
||||
(7, 8) 2.31%
|
||||
(8, 7) 2.31%
|
||||
(12, 3) 0.15%
|
||||
(4, 9) 0.93%
|
||||
(9, 4) 0.93%
|
||||
(4, 10) 0.69%
|
||||
(5, 9) 1.23%
|
||||
(9, 5) 1.23%
|
||||
(10, 4) 0.69%
|
||||
(4, 11) 0.46%
|
||||
(6, 9) 1.54%
|
||||
(9, 6) 1.54%
|
||||
(11, 4) 0.46%
|
||||
(4, 12) 0.23%
|
||||
(7, 9) 1.85%
|
||||
(9, 7) 1.85%
|
||||
(12, 4) 0.23%
|
||||
(5, 10) 0.93%
|
||||
(10, 5) 0.93%
|
||||
(5, 11) 0.62%
|
||||
(6, 10) 1.16%
|
||||
(10, 6) 1.16%
|
||||
(11, 5) 0.62%
|
||||
(5, 12) 0.31%
|
||||
(7, 10) 1.39%
|
||||
(10, 7) 1.39%
|
||||
(12, 5) 0.31%
|
||||
(6, 11) 0.77%
|
||||
(11, 6) 0.77%
|
||||
(6, 12) 0.39%
|
||||
(7, 11) 0.93%
|
||||
(11, 7) 0.93%
|
||||
(12, 6) 0.39%
|
||||
(7, 12) 0.46%
|
||||
(12, 7) 0.46%
|
||||
(8, 8) 1.93%
|
||||
(8, 9) 1.54%
|
||||
(9, 8) 1.54%
|
||||
(8, 10) 1.16%
|
||||
(10, 8) 1.16%
|
||||
(8, 11) 0.77%
|
||||
(11, 8) 0.77%
|
||||
(8, 12) 0.39%
|
||||
(12, 8) 0.39%
|
||||
(9, 9) 1.23%
|
||||
(9, 10) 0.93%
|
||||
(10, 9) 0.93%
|
||||
(9, 11) 0.62%
|
||||
(11, 9) 0.62%
|
||||
(9, 12) 0.31%
|
||||
(12, 9) 0.31%
|
||||
(10, 10) 0.69%
|
||||
(10, 11) 0.46%
|
||||
(11, 10) 0.46%
|
||||
(10, 12) 0.23%
|
||||
(12, 10) 0.23%
|
||||
(11, 11) 0.31%
|
||||
(11, 12) 0.15%
|
||||
(12, 11) 0.15%
|
||||
(12, 12) 0.08%
|
||||
|
|
@ -15,6 +15,7 @@ class Program
|
|||
|
||||
// Call the method you want to run
|
||||
DungeonMap map = generator.GenerateDungeon(25, .5f);
|
||||
DungeonLockPopulator.PopulateLocksOfDungeon(map);
|
||||
DungeonMapSerializer.SerializeToFile(map, SAVED_DUNGEONS_PATH, DUNGEON_NAME );
|
||||
|
||||
// Print the map to the console (assuming it returns a string or something printable)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -23,8 +23,17 @@
|
|||
}
|
||||
},
|
||||
"System.Numerics.Vectors/4.6.0": {},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"runtime": {
|
||||
"DiceProbabilities.dll": {
|
||||
"assemblyVersion": "1.0.0",
|
||||
"fileVersion": "1.0.0.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"DungeonMapGenerator/1.0.0": {
|
||||
"dependencies": {
|
||||
"DiceProbabilities": "1.0.0",
|
||||
"Newtonsoft.Json": "13.0.3",
|
||||
"System.Numerics.Vectors": "4.6.0"
|
||||
},
|
||||
|
|
@ -57,6 +66,11 @@
|
|||
"path": "system.numerics.vectors/4.6.0",
|
||||
"hashPath": "system.numerics.vectors.4.6.0.nupkg.sha512"
|
||||
},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
},
|
||||
"DungeonMapGenerator/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -49,15 +49,14 @@ namespace DungeonMapGenerator
|
|||
|
||||
private void ConnectAllAdjacentRooms(DungeonMap dungeon)
|
||||
{
|
||||
Dictionary<Point, int> pointRoomMapping = dungeon.GetPointRoomIdMapping();
|
||||
Dictionary<Point, Room> pointRoomMapping = dungeon.GetPointRoomIdMapping();
|
||||
foreach (var room in dungeon.GetAllRooms())
|
||||
{
|
||||
foreach ((Point p, RoomSide side) in room.GetAdjacentPoints())
|
||||
{
|
||||
if (pointRoomMapping.ContainsKey(p))
|
||||
{
|
||||
int idForRoomPointIsIn = pointRoomMapping[p];
|
||||
room.AddAdjacentRoomId(idForRoomPointIsIn);
|
||||
room.AddAdjacentRoom(pointRoomMapping[p]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
130
DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs
Normal file
130
DungeonMapGenerator/DungeonMapGenerator/DungeonLockPopulator.cs
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DiceProbabilities;
|
||||
|
||||
namespace DungeonMapGenerator
|
||||
{
|
||||
public static class DungeonLockPopulator
|
||||
{
|
||||
private const float ACCEPTABLE_ERROR = .1319f;
|
||||
public static void PopulateLocksOfDungeon(DungeonMap dungeon)
|
||||
{
|
||||
Random random = new Random();
|
||||
float desiredSuccessChance = .80f;
|
||||
|
||||
List<Room> currentRooms = dungeon.GetEntranceRooms();
|
||||
HashSet<Room> seenRooms = new HashSet<Room>(currentRooms);
|
||||
|
||||
// Set entrance room locks to 2 - 12
|
||||
Shuffle(currentRooms);
|
||||
int entranceRoomLock = 1;
|
||||
foreach (Room entranceRoom in currentRooms)
|
||||
{
|
||||
entranceRoom.Lock = new Lock((entranceRoomLock + 1.ToString()));
|
||||
}
|
||||
|
||||
while (currentRooms.Count > 0)
|
||||
{
|
||||
List<Room> locklessRooms = new List<Room>();
|
||||
List<Room> adjacentRooms = new List<Room>();
|
||||
|
||||
// Get all adjacent rooms that haven't been locked at
|
||||
foreach (Room room in currentRooms.ToList())
|
||||
{
|
||||
foreach (Room adjacentRoom in room.GetAdjacentRooms())
|
||||
{
|
||||
if (!seenRooms.Contains(adjacentRoom))
|
||||
{
|
||||
adjacentRooms.Add(adjacentRoom);
|
||||
seenRooms.Add(adjacentRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the odds of locks already set.
|
||||
foreach (Room adjacentRoom in adjacentRooms.ToList())
|
||||
{
|
||||
List<float> odds = new List<float>();
|
||||
if (adjacentRoom.Lock != null)
|
||||
{
|
||||
odds.Add(adjacentRoom.Lock.GetOdds());
|
||||
}
|
||||
else
|
||||
{
|
||||
locklessRooms.Add(adjacentRoom);
|
||||
}
|
||||
}
|
||||
|
||||
if (locklessRooms.Count > 0)
|
||||
{
|
||||
// Add locks to the rooms with odds adding to within the difficulty range
|
||||
List<Lock> locks = GenerateLocks(locklessRooms.Count, desiredSuccessChance);
|
||||
for (int i = 0; i < locklessRooms.Count; i++)
|
||||
{
|
||||
locklessRooms[i].Lock = locks[i];
|
||||
}
|
||||
}
|
||||
|
||||
currentRooms = adjacentRooms;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Lock> GenerateLocks(int numLocks, float successChance)
|
||||
{
|
||||
List<Lock> locks = new List<Lock>();
|
||||
if (FindCombination(locks, numLocks, successChance, Lock.PossibleLocks))
|
||||
{
|
||||
return locks;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool FindCombination(List<Lock> generatedLocks, int numLocks, float successChance, List<Lock> lockOptions)
|
||||
{
|
||||
if (generatedLocks.Count == numLocks)
|
||||
{
|
||||
List<string> locksAsStrings = generatedLocks.Select(_lock => _lock.GetLock()).ToList();
|
||||
|
||||
// Return true if given the current locks the chance of being able to open one is close to difficulty
|
||||
float probalityOfAtleastOneUnlocking = RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings);
|
||||
return probalityOfAtleastOneUnlocking >= successChance - ACCEPTABLE_ERROR
|
||||
&& probalityOfAtleastOneUnlocking <= successChance + ACCEPTABLE_ERROR;
|
||||
}
|
||||
|
||||
Shuffle(lockOptions);
|
||||
|
||||
foreach (Lock _lock in lockOptions.ToList())
|
||||
{
|
||||
// if adding the lock won't bring us over the threshold difficulty.
|
||||
List<string> locksAsStrings = generatedLocks.Select(l => l.GetLock()).ToList();
|
||||
locksAsStrings.Add(_lock.GetLock());
|
||||
if (RollFourSumTwo.GetProbalityOfAtleastOneUnlocking(locksAsStrings) <= successChance)
|
||||
{
|
||||
generatedLocks.Add(new Lock(_lock.GetLock()));
|
||||
if (FindCombination(generatedLocks, numLocks, successChance, lockOptions))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// This combination didn't work. Remove the last one and try the next lock.
|
||||
generatedLocks.RemoveAt(generatedLocks.Count - 1);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Shuffle<T>(List<T> list)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
int n = list.Count;
|
||||
for (int i = n - 1; i > 0; i--)
|
||||
{
|
||||
int j = random.Next(i + 1);
|
||||
(list[i], list[j]) = (list[j], list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -33,15 +33,15 @@ namespace DungeonMapGenerator
|
|||
.Select(y => new Point(x,y))));
|
||||
}
|
||||
|
||||
public Dictionary<Point, int> GetPointRoomIdMapping()
|
||||
public Dictionary<Point, Room> GetPointRoomIdMapping()
|
||||
{
|
||||
var pointRoomMap = new Dictionary<Point, int>();
|
||||
var pointRoomMap = new Dictionary<Point, Room>();
|
||||
|
||||
foreach (var room in GetAllRooms())
|
||||
{
|
||||
foreach (var point in room.GetPointsInRoom())
|
||||
{
|
||||
pointRoomMap[point] = room.Id;
|
||||
pointRoomMap[point] = room;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +200,8 @@ namespace DungeonMapGenerator
|
|||
public List<Room> GetNodeRooms()
|
||||
{
|
||||
List<Room> nodeRooms = new List<Room>();
|
||||
nodeRooms.AddRange(_monsterRooms.SelectMany(room => room.GetAdjacentRooms()));
|
||||
nodeRooms.AddRange(_bossRoom.GetAdjacentRooms());
|
||||
nodeRooms.AddRange(_monsterRooms.SelectMany(room => room.GetAdjacentRoomsDict().Values.SelectMany(roomList => roomList)));
|
||||
nodeRooms.AddRange(_bossRoom.GetAdjacentRoomsDict().Values.SelectMany(roomList => roomList));
|
||||
return nodeRooms;
|
||||
}
|
||||
|
||||
|
|
|
|||
53
DungeonMapGenerator/DungeonMapGenerator/Lock.cs
Normal file
53
DungeonMapGenerator/DungeonMapGenerator/Lock.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using System.Collections.Generic;
|
||||
using DiceProbabilities;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DungeonMapGenerator
|
||||
{
|
||||
public class Lock
|
||||
{
|
||||
public static readonly List<Lock> PossibleLocks = new List<Lock>()
|
||||
{
|
||||
new Lock("="),
|
||||
new Lock("2"),
|
||||
new Lock("3"),
|
||||
new Lock("4"),
|
||||
new Lock("5"),
|
||||
new Lock("6"),
|
||||
new Lock("7"),
|
||||
new Lock("8"),
|
||||
new Lock("9"),
|
||||
new Lock("10"),
|
||||
new Lock("11"),
|
||||
new Lock("12"),
|
||||
};
|
||||
|
||||
[JsonProperty("LockType")]
|
||||
private string _lockType;
|
||||
|
||||
public Lock()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Lock(string lockType)
|
||||
{
|
||||
_lockType = lockType;
|
||||
}
|
||||
|
||||
public void SetLockType(string lockType)
|
||||
{
|
||||
_lockType = lockType;
|
||||
}
|
||||
|
||||
public string GetLock()
|
||||
{
|
||||
return _lockType;
|
||||
}
|
||||
|
||||
public float GetOdds()
|
||||
{
|
||||
return RollFourSumTwo.ResultOddsmapping[_lockType];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ namespace DungeonMapGenerator
|
|||
private static int _nextId = 1;
|
||||
|
||||
public RoomType TypeOfRoom { get; set; }
|
||||
public Lock Lock { get; set; }
|
||||
public int Height { get; set; }
|
||||
public int Width { get; set; }
|
||||
public Point PositionOfTopLeft { get; set; }
|
||||
|
|
@ -34,8 +35,9 @@ namespace DungeonMapGenerator
|
|||
|
||||
[JsonProperty("AdjacentRoomIds")]
|
||||
private HashSet<int> _adjacentRoomIds = new HashSet<int>();
|
||||
private List<Room> _adjacentRooms = new List<Room>();
|
||||
private readonly Dictionary<RoomSide, List<Room>> _adjacentRoomsBySide = new Dictionary<RoomSide, List<Room>>();
|
||||
|
||||
|
||||
public Room()
|
||||
{
|
||||
|
||||
|
|
@ -50,10 +52,12 @@ namespace DungeonMapGenerator
|
|||
PositionOfTopLeft = positionOfTopLeft;
|
||||
}
|
||||
|
||||
public void AddAdjacentRoomId(int id)
|
||||
public void AddAdjacentRoom(Room room)
|
||||
{
|
||||
_adjacentRoomIds.Add(id);
|
||||
_adjacentRooms.Add(room);
|
||||
_adjacentRoomIds.Add(room.Id);
|
||||
}
|
||||
|
||||
|
||||
public HashSet<int> GetAdjacentRoomIds()
|
||||
{
|
||||
|
|
@ -108,7 +112,7 @@ namespace DungeonMapGenerator
|
|||
|
||||
public IEnumerable<Room> GetAdjacentRooms()
|
||||
{
|
||||
return _adjacentRoomsBySide.Values.SelectMany(roomList => roomList);
|
||||
return new List<Room>(_adjacentRooms);
|
||||
}
|
||||
|
||||
public Dictionary<RoomSide, List<Room>> GetAdjacentRoomsDict()
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -9,6 +9,7 @@
|
|||
".NETStandard,Version=v2.0/": {
|
||||
"DungeonMapGenerator/1.0.0": {
|
||||
"dependencies": {
|
||||
"DiceProbabilities": "1.0.0",
|
||||
"NETStandard.Library": "2.0.3",
|
||||
"Newtonsoft.Json": "13.0.3",
|
||||
"System.Numerics.Vectors": "4.6.0"
|
||||
|
|
@ -38,6 +39,14 @@
|
|||
"fileVersion": "4.600.24.56208"
|
||||
}
|
||||
}
|
||||
},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"runtime": {
|
||||
"DiceProbabilities.dll": {
|
||||
"assemblyVersion": "1.0.0",
|
||||
"fileVersion": "1.0.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -74,6 +83,11 @@
|
|||
"sha512": "sha512-t+SoieZsRuEyiw/J+qXUbolyO219tKQQI0+2/YI+Qv7YdGValA6WiuokrNKqjrTNsy5ABWU11bdKOzUdheteXg==",
|
||||
"path": "system.numerics.vectors/4.6.0",
|
||||
"hashPath": "system.numerics.vectors.4.6.0.nupkg.sha512"
|
||||
},
|
||||
"DiceProbabilities/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
2010
Dungeons/dungeon03.json
Normal file
2010
Dungeons/dungeon03.json
Normal file
File diff suppressed because it is too large
Load diff
1878
Dungeons/dungeon04.json
Normal file
1878
Dungeons/dungeon04.json
Normal file
File diff suppressed because it is too large
Load diff
1872
Dungeons/dungeon05.json
Normal file
1872
Dungeons/dungeon05.json
Normal file
File diff suppressed because it is too large
Load diff
1918
Dungeons/dungeon06.json
Normal file
1918
Dungeons/dungeon06.json
Normal file
File diff suppressed because it is too large
Load diff
1738
Dungeons/dungeon08.json
Normal file
1738
Dungeons/dungeon08.json
Normal file
File diff suppressed because it is too large
Load diff
1823
Dungeons/dungeon09.json
Normal file
1823
Dungeons/dungeon09.json
Normal file
File diff suppressed because it is too large
Load diff
1986
Dungeons/dungeon10.json
Normal file
1986
Dungeons/dungeon10.json
Normal file
File diff suppressed because it is too large
Load diff
BIN
PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll
Normal file
BIN
PuzzleGameProject/Assets/Plugins/DiceProbabilities.dll
Normal file
Binary file not shown.
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a9fb44c02fd9e0043a5a54660bfc4a95
|
||||
Binary file not shown.
|
|
@ -86,7 +86,6 @@ GameObject:
|
|||
- component: {fileID: 9187907134033443523}
|
||||
- component: {fileID: 3406749035128918688}
|
||||
- component: {fileID: 4547043864789539458}
|
||||
- component: {fileID: 3534050844455123390}
|
||||
- component: {fileID: 1770509300873928573}
|
||||
- component: {fileID: 4019891345885281529}
|
||||
m_Layer: 0
|
||||
|
|
@ -150,20 +149,6 @@ MonoBehaviour:
|
|||
diamonds: 0
|
||||
damage: 0
|
||||
chest: 0
|
||||
--- !u!114 &3534050844455123390
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2435349004046080434}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f021f4903d50cb4b8bea2c40701ad58, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
blockingRoom: {fileID: 0}
|
||||
number: 7
|
||||
--- !u!212 &1770509300873928573
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -86,7 +86,6 @@ GameObject:
|
|||
- component: {fileID: 9187907134033443523}
|
||||
- component: {fileID: 3406749035128918688}
|
||||
- component: {fileID: 4547043864789539458}
|
||||
- component: {fileID: 3914409103375474668}
|
||||
- component: {fileID: 1770509300873928573}
|
||||
- component: {fileID: 4019891345885281529}
|
||||
- component: {fileID: -1465197196826248026}
|
||||
|
|
@ -151,20 +150,6 @@ MonoBehaviour:
|
|||
diamonds: 0
|
||||
damage: 0
|
||||
chest: 0
|
||||
--- !u!114 &3914409103375474668
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2435349004046080434}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f021f4903d50cb4b8bea2c40701ad58, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
blockingRoom: {fileID: 0}
|
||||
number: 7
|
||||
--- !u!212 &1770509300873928573
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ GameObject:
|
|||
- component: {fileID: 9187907134033443523}
|
||||
- component: {fileID: 849256457500513523}
|
||||
- component: {fileID: 6904757263627452010}
|
||||
- component: {fileID: 840456052578583509}
|
||||
- component: {fileID: 1770509300873928573}
|
||||
- component: {fileID: 4019891345885281529}
|
||||
- component: {fileID: -1465197196826248026}
|
||||
|
|
@ -74,20 +73,6 @@ MonoBehaviour:
|
|||
diamonds: 0
|
||||
damage: 0
|
||||
chest: 0
|
||||
--- !u!114 &840456052578583509
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2435349004046080434}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 0f021f4903d50cb4b8bea2c40701ad58, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
blockingRoom: {fileID: 0}
|
||||
number: 7
|
||||
--- !u!212 &1770509300873928573
|
||||
SpriteRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
|||
|
|
@ -28,12 +28,14 @@ namespace DungeonGenerator
|
|||
|
||||
GameObject bossRoomGO = PrefabUtility.InstantiatePrefab(bossRoomPrefab, gameObject.transform) as GameObject;
|
||||
bossRoomGO.transform.position = ConvertToUnityPosition(map.GetBossRoom().GetCenterOfRoom(), map.Width, map.Height);
|
||||
AddLockToRoomObject(bossRoomGO, map.GetBossRoom().Lock.GetLock());
|
||||
_roomIdToGameObject[map.GetBossRoom().Id] = bossRoomGO;
|
||||
|
||||
foreach (var monsterRoom in map.GetMonsterRooms())
|
||||
{
|
||||
GameObject monsterRoomGO = PrefabUtility.InstantiatePrefab(monsterRoomPrefab, gameObject.transform) as GameObject;
|
||||
monsterRoomGO.transform.position = ConvertToUnityPosition(monsterRoom.GetCenterOfRoom(), map.Width, map.Height);
|
||||
AddLockToRoomObject(monsterRoomGO, monsterRoom.Lock.GetLock());
|
||||
_roomIdToGameObject[monsterRoom.Id] = monsterRoomGO;
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +43,7 @@ namespace DungeonGenerator
|
|||
{
|
||||
GameObject normalRoomGO = PrefabUtility.InstantiatePrefab(normalRoomPrefab, gameObject.transform) as GameObject;
|
||||
normalRoomGO.transform.position = ConvertToUnityPosition(normalRoom.GetCenterOfRoom(), map.Width, map.Height);
|
||||
AddLockToRoomObject(normalRoomGO, normalRoom.Lock.GetLock());
|
||||
_roomIdToGameObject[normalRoom.Id] = normalRoomGO;
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +52,7 @@ namespace DungeonGenerator
|
|||
GameObject entranceRoomGO = PrefabUtility.InstantiatePrefab(normalRoomPrefab, gameObject.transform) as GameObject;
|
||||
entranceRoomGO.transform.position = ConvertToUnityPosition(entranceRoom.GetCenterOfRoom(), map.Width, map.Height);
|
||||
entranceRoomGO.GetComponent<Room>().IsEntrance = true;
|
||||
AddLockToRoomObject(entranceRoomGO, entranceRoom.Lock.GetLock());
|
||||
_roomIdToGameObject[entranceRoom.Id] = entranceRoomGO;
|
||||
}
|
||||
|
||||
|
|
@ -70,5 +74,35 @@ namespace DungeonGenerator
|
|||
|
||||
return new Vector3(newX, newY, 0f);
|
||||
}
|
||||
|
||||
private void AddLockToRoomObject(GameObject room, string lockString)
|
||||
{
|
||||
NumberLock _lock;
|
||||
switch (lockString)
|
||||
{
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
case "9":
|
||||
case "10":
|
||||
case "11":
|
||||
case "12":
|
||||
_lock = room.AddComponent<NumberLock>();
|
||||
_lock.SetNumber(Int32.Parse(lockString));
|
||||
break;
|
||||
case "=":
|
||||
room.AddComponent<MatchingDiceLock>();
|
||||
break;
|
||||
case null:
|
||||
Debug.Log("Lock for room was null when imported. Using 1 as lock");
|
||||
_lock = room.AddComponent<NumberLock>();
|
||||
_lock.SetNumber(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ public class NumberLock : Lock
|
|||
return false;
|
||||
}
|
||||
|
||||
public void SetNumber(int num)
|
||||
{
|
||||
number = num;
|
||||
}
|
||||
|
||||
public int GetNumber()
|
||||
{
|
||||
return number;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue