|
Title: Siegfreide's Conundrum 01 - How to generate reliable random probability? Post by: Siegfreide on October 16, 2013, 11:23:05 AM When a player ventures forth into a dungeon in my game, they will inevitably run into treasure chests during their descent into the dungeon depths. I want these chests to be "randomized" based on two factors;
Dungeon rating - what the base difficulty of the dungeon is. Dungeon depth - the increasing difficulty of the dungeon based on how far you have descended from the first room. Both of these factors are then added together to form the "difficulty" variable. The par_chest then determines the "chance" quality of the generated chests based on the current difficulty of the dungeon. Once the chest quality is decided, par_chest then decides if the chest has already been looted and had all of its contents removed. If it has been looted, the chest is generated with an "open chest" sprite, and nothing happens if you activate it. Conversely, if it has not been looted, it is generated with a "closed sprite, and you're free to loot it yourself. The better the quality of the chest, the higher its percentage of already being looted. --------------------------------------------------------------------------------------- Now, to my problem; As it stands, when the dungeon difficulty is "chest level 1" generation threshold, theres supposed to be a 90% chance it will generate a level 1 "basic chest", or a 10% chance it will upgrade the level 1 "basic chest" into a level 2 "average chest". Also, even though there is only a 10% chance of a level 1 chest being already "looted" upon generation and a 20% chance of a level 2 chest already being looted upon generation, damn near all of the chests in my stress tests are open. I'll post 10 pictures of my chest generations (taken in a row, I did not cherry pick the pictures), and my par_chest code below. NOTE; I do not change any variables myself when restarting the game for new generation. Also, I would like to apologize in advance for how much space this one post takes up. I tried to use the spoiler system, but apparently that doesnt exist on this forum. --------------------------------------------------------------------------------------- Code: CREATE Event of par_chest------------------------------------------ [spoiler]////Randomize Chest Contents based on Dungeon Difficulty //Randomizes the GameMaker Seed for truly random results every time a chest is created randomize(); //Determines Dungeon Difficulty difficulty = 4 //(obj_control.dungeon_rating + floor(obj_control.dungeon_depth/5)) //Determines possible Chest Quality if difficulty < 5 { potential_contents=1; } if difficulty >= 5 && difficulty < 10 { potential_contents=choose(1,1,1,2,2); } if difficulty >= 10 && difficulty < 15 { potential_contents=choose(1,1,2,2,3); } if difficulty >= 15 && difficulty < 20 { potential_contents=choose(2,2,2,3,3); } if difficulty >= 20 { potential_contents=choose(2,2,3,3,4); } //Upgrade Chest Quality, Downgrade Chest Quality, or leave the Chest Quality unchanged. /* quality_change=ceil(random(10)); if potential_contents = 1 { if quality_change=10 { potential_contents+=1; } else potential_contents+=0; } if potential_contents > 1 { if quality_change=10 { potential_contents+=1; } if quality_change=1 { potential_contents-=1; } else potential_contents+=0; } */ //Upgrade Chest Quality, Downgrade Chest Quality, or leave the Chest Quality unchanged. if potential_contents = 1 { potential_contents += choose(0,0,0,0,0,0,0,0,0,1); } /* THIS IS WHAT IT WAS if potential_contents > 1 { potential_contents += choose(0,0,0,0,0,0,0,0,1,-1); }*/ //WHAT IT IS NOW else potential_contents += choose(0,0,0,0,0,0,0,0,1,-1); //Sets the Chest's Sprite based on final Chest Quality chest_quality=potential_contents; //Determine if the chest has already been looted if potential_contents = 1 //10% chance of already looted { total_contents = potential_contents + choose(0,0,0,0,0,0,0,0,0,-potential_contents); } if potential_contents = 2 //20% chance of already looted { total_contents = potential_contents + choose(0,0,0,0,-potential_contents); } if potential_contents = 3 //30% chance of already looted { total_contents = potential_contents + choose(0,0,0,0,0,0,0,-potential_contents,-potential_contents,-potential_contents); } if potential_contents = 4 //40% chance of already looted { total_contents = potential_contents + choose(0,0,0,-potential_contents,-potential_contents); } if potential_contents = 5 //50% chance of already looted { total_contents = potential_contents + choose(0,-potential_contents); } //Assigns "empty" or "full" Chest sprite based on contents if total_contents = 0 { if chest_quality=1 { instance_create(x,y,obj_basicChest); obj_basicChest.chest_opened=true; obj_basicChest.chest_name = "Ravaged Basic Chest"; } if chest_quality=2 { instance_create(x,y,obj_averageChest); obj_averageChest.chest_opened=true; obj_averageChest.chest_name = "Ravaged Average Chest"; } if chest_quality=3 { instance_create(x,y,obj_ornateChest); obj_ornateChest.chest_opened=true; obj_ornateChest.chest_name = "Ravaged Ornate Chest"; } if chest_quality=4 { instance_create(x,y,obj_exquisiteChest); obj_exquisiteChest.chest_opened=true; obj_exquisiteChest.chest_name = "Ravaged Exquisite Chest"; } if chest_quality=5 { instance_create(x,y,obj_legendaryChest); obj_legendaryChest.chest_opened=true; obj_legendaryChest.chest_name = "Ravaged Legendary Chest"; } } //Creates the Chests based on Chest Quality if total_contents = 1 { instance_create(x,y,obj_basicChest); } if total_contents = 2 { instance_create(x,y,obj_averageChest); } if total_contents = 3 { instance_create(x,y,obj_ornateChest); } if total_contents = 4 { instance_create(x,y,obj_exquisiteChest); } if total_contents = 5 { instance_create(x,y,obj_legendaryChest); } instance_destroy(); STEP Event of generated chests--------------------------------------------------- ////Open the Treasure Chest image_speed=0; if chest_opened=false { image_index=0; } else image_index=1; if place_meeting(x,y,obj_player) { if chest_opened=false { if keyboard_check_pressed(obj_control.key_interact) { chest_opened=true; obj_HUD.inventory_slot[1] = chest_slot[1]; } } } (http://i39.tinypic.com/kf2x7d.png) (http://i40.tinypic.com/344bblz.png) (http://i40.tinypic.com/e8u1hf.png) (http://i39.tinypic.com/xnrz81.png) (http://i39.tinypic.com/x3ehz5.png) (http://i40.tinypic.com/2mhbhxw.png) (http://i43.tinypic.com/2uqhesn.png) (http://i41.tinypic.com/27xf97p.png) (http://i43.tinypic.com/34ee3rp.png) (http://i44.tinypic.com/14lllq9.png) [/spoiler] Title: Re: Siegfreide's Conundrum 01 - How to generate reliable random probability? Post by: Rusk on October 17, 2013, 03:19:26 PM Since it looks pretty even... maybe choose ignores duplicate values? So that "choose(0,0,0,0,0,0,0,0,0,1);" becomes just " choose(0,1);"? Try rewriting that part with random instead:
if random(10)<1 { potential_contents=0; } Title: Re: Siegfreide's Conundrum 01 - How to generate reliable random probability? Post by: Siegfreide on October 17, 2013, 10:12:39 PM Since it looks pretty even... maybe choose ignores duplicate values? So that "choose(0,0,0,0,0,0,0,0,0,1);" becomes just " choose(0,1);"? Try rewriting that part with random instead: if random(10)<1 { potential_contents=0; } Hmmm... I hadnt considered that choose could have that implementation. I'll give random() a try, and see how that goes. Thanks for the suggestion, kind sir. |