• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
RLS0812

Can You Guess What This Is Used For

7 posts in this topic

 Sometimes my test code can look very weird when I am attempting to figure something out.

Can you guess what this code block is used to test for ?

                 int num1 = 50;
		 int num2 = 75;
		 int num3 = 100;
		 int num4 = 125;
		 
		 int catche = 0;
		 List<Integer> dump = new ArrayList<Integer>();
		 List<Integer> low = new ArrayList<Integer>();
		 List<Integer> high = new ArrayList<Integer>();
		 
		 dump.add(num1);
		 low.add(catche + 1);
		 catche += num1;
		 high.add(catche);

		 dump.add(num2);
		 low.add(catche + 1);
		 catche += num2;
		 high.add(catche);

		 dump.add(num3);
		 low.add(catche + 1);
		 catche += num3;
		 high.add(catche);

		 dump.add(num4);
		 low.add(catche + 1);
		 catche += num4;
		 high.add(catche);
		 
		 int one = 0;
		 int two = 0;
		 int three = 0;
		 int four = 0;
		 
		 int cnt = 0;
		 while ( cnt != 1001){
		 int temp_rand = rand.nextInt(catche);
		 
		 for (int i = 0; i < dump.size(); i ++ ){
			 if (temp_rand >= low.get(i) && temp_rand <= high.get(i) ){
				 switch (i){
				 case 0: one ++; break;
				 case 1: two ++; break;
				 case 2: three ++; break;
				 case 3: four ++; break;
				 default:break;
				 }
                            //say("\n" + dump.get(i));
			 }
		 }
		 cnt ++;
		 }
		 say("One: " + (int)(((double)one / cnt)* 100)  + "% Two: " + (int)(((double)two / cnt)* 100)  + "% Three: " + 
		 (int)(((double)three / cnt)* 100)  + "% Four: " + (int)(((double)four / cnt)* 100) + "%" );

public void say(String x){
		System.out.println(x);
	}

 The answer is: determining probability by weight

Explained -

 One object must be picked out of a list of objects, but each object has a different "weight" ( likelihood ) of being picked.

Real Life Example -

You have 5 red marbles.

Your friend has 10 green marbles.

Your second friend has 15 yellow marbles.

Your third friend has 20 blue marbles.

 If you put them all in a bag, and pulled out just one, which color would likely be picked?

 What is the chance for each color  ?

Edited by Shippou
0

Share this post


Link to post
Share on other sites

If anyone cares, here is what that code morphed into

.

public class ProbSelect {
	Random rand;

	public ProbSelect(){
		rand = new Random();
	}
	
	public InteractiveObject selectItem (List<InteractiveObject> eo2){

		int ammount = eo2.size();
		int catche = 0;
		List<Integer> dump = new ArrayList<Integer>();
		List<Integer> low = new ArrayList<Integer>();
	        List<Integer> high = new ArrayList<Integer>();
	    
		for (int i = 0; i < ammount ; i ++){
			 
			 dump.add(eo2.get(i).getRarity() );
			 low.add(catche + 1);
			 catche += eo2.get(i).getRarity();
			 high.add(catche);
		}
		
		int pick = rand.nextInt(catche) + 1;
		int ii;

		 
		 for (ii = 0; ii < dump.size(); ii ++ ){
			 if ( pick >= low.get(ii) && pick <= high.get(ii) ){
				 //System.out.println(eo2.get(ii).getName() );
				 return eo2.get(ii);

				 }
			 }

			  System.out.println("Error returning EnvObjects\n Total: " + catche + "\nPicked: " + pick);
			  return null;

		 }
		 
		
	}
Edited by Shippou
0

Share this post


Link to post
Share on other sites

Hey, I solved the same problem last week in a hobby project of mine :)

 

Here is my C++11 implementation of it:

// Select a random segment using a distribution array defining what types to create and with what probability.
// Array must be normalized before used.
//
// Example usage:
//
// std::vector<DistEntry> distribution = {
//   {55.0f,createFoot},
//   {4.0f,createArc},
//   {39.0f,createZigZag},
//   {4.0f,createSmoothDiagonal},
//   {10.0f,createBezier}
// };
//
// normalizeDistribution(distribution);
//
// Segment* segment = randomSegmentFromDistribution(nullptr, distribution);
//
Segment* randomSegmentFromDistribution(Segment* parent, const std::vector<DistEntry>& normDist)
{
  float r = drand48();
  for(auto e : normDist) {
    if(e.first >= r) {
      return e.second(parent);
    } else {
      r -= e.first;
    }
  }
  assert(0); // something went wrong, is the distribution normalized?
  return nullptr;
}


void normalizeDistribution(std::vector<DistEntry>& distribution)
{
  std::sort(std::begin(distribution), std::end(distribution));
  float sum = 0;
  for(auto& e : distribution) {
    sum += e.first;
  }
  for(auto& e : distribution) {
    e.first /= sum;
  }
}

Also supports floats in the distribution... 

I'm pretty sure it works as intended, but it is easy to get confused when working with probabilities for some reason.

2

Share this post


Link to post
Share on other sites


OK, I'll have a go.  Here's a complete working tested C++11 program that chooses 10 marbles from Shippou's bag, with replacement

 

Oh, thanks for the <random> example, hadn't got around to looking through that one yet :)

0

Share this post


Link to post
Share on other sites

Just an update ... that code I posted earlier has been incorporated into a map generator.

I'll attach the compiled project if ya want to poke fun at it ( Java 1.7 ) [Download LINK]

 

from DOS:

java -jar test.jar

 

N S E W to move

Q to quit

MAP to regen map

 

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0