Finished the friendship randomization.

Added a probability to spread out better the results.

Signed-off-by: RosimInc <rosim_inc@hotmail.com>
This commit is contained in:
RosimInc 2015-08-13 03:16:42 -04:00
parent f91fcd3eb4
commit bbf3de222f
4 changed files with 23 additions and 21 deletions

View File

@ -260,10 +260,11 @@ MonoBehaviour:
LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2} LinkObj: {fileID: 11495142, guid: fab430cecad80ad4391987a06b550cb7, type: 2}
PersonObj: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2} PersonObj: {fileID: 11406500, guid: 646dd6566f9e1374caa3af8ad37c43d3, type: 2}
NumPeople: 100 NumPeople: 100
AvgNumFriends: 20 AvgNumFriends: 10
FriendshipLikeliness: .300000012
SphereRadius: 7 SphereRadius: 7
rotationSpeed: .699999988 rotationSpeed: .699999988
torqueForce: 35 torqueForce: .100000001
--- !u!54 &736567790 --- !u!54 &736567790
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -7,12 +7,14 @@ namespace DeathBook.Model
{ {
private int numPeople; private int numPeople;
private int avgConnections; private int avgConnections;
private float probability;
private float radius; private float radius;
public Level GenerateLevel(int numPeople, int avgFriends, float radius) public Level GenerateLevel(int numPeople, int avgFriends, float probability, float radius)
{ {
this.numPeople = numPeople; this.numPeople = numPeople;
this.avgConnections = avgFriends; this.avgConnections = avgFriends;
this.probability = probability;
this.radius = radius; this.radius = radius;
List<Person> people = CreatePeople(); List<Person> people = CreatePeople();
@ -55,7 +57,7 @@ namespace DeathBook.Model
private List<Friendship> CreateFriendships(List<Person> people) private List<Friendship> CreateFriendships(List<Person> people)
{ {
Debug.Log("Creating friendships"); Debug.Log("Creating friendships" + probability);
List<Friendship> friendships = new List<Friendship>(); List<Friendship> friendships = new List<Friendship>();
Person p1, p2; Person p1, p2;
@ -67,7 +69,6 @@ namespace DeathBook.Model
for (int i = 0; i < totalCount; i++) for (int i = 0; i < totalCount; i++)
{ {
Debug.Log("Person " + (i+1));
p1 = people[i]; p1 = people[i];
missing = avgConnections - p1.numFriends; // TODO Add randomness missing = avgConnections - p1.numFriends; // TODO Add randomness
@ -86,10 +87,13 @@ namespace DeathBook.Model
while (list.Count > 0 && missing > 0) while (list.Count > 0 && missing > 0)
{ {
DistanceNode smallest = list.First.Value; DistanceNode smallest = list.First.Value;
//Lerp between probability and 1, depending on how many are left and how many are missing
float prob = Mathf.Lerp(probability, 1, missing / list.Count);
foreach (DistanceNode node in list) foreach (DistanceNode node in list)
{ {
if (node.dist < smallest.dist) if (node.dist < smallest.dist && Random.value < prob)
//TODO Add probabilities
smallest = node; smallest = node;
} }
//TODO Code/use a heap instead //TODO Code/use a heap instead

View File

@ -8,7 +8,8 @@ public class SphereSR : MonoBehaviour
public FriendshipLink LinkObj; public FriendshipLink LinkObj;
public PersonTest PersonObj; public PersonTest PersonObj;
public int NumPeople = 50; public int NumPeople = 50;
public int AvgNumFriends = 20; public int AvgNumFriends = 20;
public float FriendshipLikeliness = 0.4f;
public float SphereRadius = 1f; public float SphereRadius = 1f;
public float rotationSpeed = 0.7f; public float rotationSpeed = 0.7f;
@ -24,7 +25,7 @@ public class SphereSR : MonoBehaviour
void Awake() void Awake()
{ {
LevelGenerator lGen = new LevelGenerator(); LevelGenerator lGen = new LevelGenerator();
Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, SphereRadius); Level lvl = lGen.GenerateLevel(NumPeople, AvgNumFriends, FriendshipLikeliness, SphereRadius);
InstantiateNodes(lvl); InstantiateNodes(lvl);
AssignLinks(lvl); AssignLinks(lvl);

View File

@ -3,14 +3,17 @@
--- !u!129 &1 --- !u!129 &1
PlayerSettings: PlayerSettings:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
serializedVersion: 7 serializedVersion: 6
AndroidProfiler: 0 AndroidProfiler: 0
defaultScreenOrientation: 4 defaultScreenOrientation: 4
targetDevice: 2 targetDevice: 2
targetGlesGraphics: -1
targetIOSGraphics: -1
targetResolution: 0 targetResolution: 0
accelerometerFrequency: 60 accelerometerFrequency: 60
companyName: DefaultCompany companyName: DefaultCompany
productName: DeathBook productName: DeathBook
cloudProjectId:
defaultCursor: {fileID: 0} defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0} cursorHotspot: {x: 0, y: 0}
m_ShowUnitySplashScreen: 1 m_ShowUnitySplashScreen: 1
@ -23,6 +26,7 @@ PlayerSettings:
m_ActiveColorSpace: 0 m_ActiveColorSpace: 0
m_MTRendering: 1 m_MTRendering: 1
m_MobileMTRendering: 0 m_MobileMTRendering: 0
m_UseDX11: 1
m_Stereoscopic3D: 0 m_Stereoscopic3D: 0
iosShowActivityIndicatorOnLoading: -1 iosShowActivityIndicatorOnLoading: -1
androidShowActivityIndicatorOnLoading: -1 androidShowActivityIndicatorOnLoading: -1
@ -77,7 +81,6 @@ PlayerSettings:
metroEnableIndependentInputSource: 0 metroEnableIndependentInputSource: 0
metroEnableLowLatencyPresentationAPI: 0 metroEnableLowLatencyPresentationAPI: 0
xboxOneDisableKinectGpuReservation: 0 xboxOneDisableKinectGpuReservation: 0
virtualRealitySupported: 0
productGUID: 402278fad2098ce4eab29439139ae9ad productGUID: 402278fad2098ce4eab29439139ae9ad
AndroidBundleVersionCode: 1 AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 9 AndroidMinSdkVersion: 9
@ -120,7 +123,6 @@ PlayerSettings:
iOSLaunchScreenCustomXibPath: iOSLaunchScreenCustomXibPath:
AndroidTargetDevice: 0 AndroidTargetDevice: 0
AndroidSplashScreenScale: 0 AndroidSplashScreenScale: 0
androidSplashScreen: {fileID: 0}
AndroidKeystoreName: AndroidKeystoreName:
AndroidKeyaliasName: AndroidKeyaliasName:
AndroidTVCompatibility: 1 AndroidTVCompatibility: 1
@ -134,7 +136,6 @@ PlayerSettings:
resolutionDialogBanner: {fileID: 0} resolutionDialogBanner: {fileID: 0}
m_BuildTargetIcons: [] m_BuildTargetIcons: []
m_BuildTargetBatching: [] m_BuildTargetBatching: []
m_BuildTargetGraphicsAPIs: []
webPlayerTemplate: APPLICATION:Default webPlayerTemplate: APPLICATION:Default
m_TemplateCustomTags: {} m_TemplateCustomTags: {}
actionOnDotNetUnhandledException: 1 actionOnDotNetUnhandledException: 1
@ -196,7 +197,6 @@ PlayerSettings:
ps4ApplicationParam2: 0 ps4ApplicationParam2: 0
ps4ApplicationParam3: 0 ps4ApplicationParam3: 0
ps4ApplicationParam4: 0 ps4ApplicationParam4: 0
ps4GarlicHeapSize: 2048
ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ ps4Passcode: frAQBc8Wsa1xVPfvJcrgRYwTiizs2trQ
ps4pnSessions: 1 ps4pnSessions: 1
ps4pnPresence: 1 ps4pnPresence: 1
@ -339,7 +339,8 @@ PlayerSettings:
blackberrySquareSplashScreen: {fileID: 0} blackberrySquareSplashScreen: {fileID: 0}
tizenProductDescription: tizenProductDescription:
tizenProductURL: tizenProductURL:
tizenSigningProfileName: tizenCertificatePath:
tizenCertificatePassword:
tizenGPSPermissions: 0 tizenGPSPermissions: 0
tizenMicrophonePermissions: 0 tizenMicrophonePermissions: 0
stvDeviceAddress: stvDeviceAddress:
@ -397,9 +398,4 @@ PlayerSettings:
- WebGL::template - WebGL::template
WebGL::emscriptenArgs: WebGL::emscriptenArgs:
WebGL::template: APPLICATION:Default WebGL::template: APPLICATION:Default
firstStreamedSceneWithResources: 0 firstStreamedLevelWithResources: 0
cloudProjectId:
projectId:
projectName:
organizationId:
cloudEnabled: 0