Home » Stars! 2.6/7 » The Academy » Problem with randomness in planet distrtibution
[LONG] Re: Problem with randomness in planet distrtibution |
Fri, 12 October 2007 22:54 |
|
ck_drknes | | Crewman 2nd Class | Messages: 17
Registered: May 2007 Location: Why do you want to know? | |
|
Hmm... I'm running into a bit of the same problem in my clone (flash AS 3 AIR). It gens pretty fast for flash (10 HW, 1000 planets, 5 sec on a 2ghz) but the hw distribution seems off . I'm just dividing the screen into equal plots and placing the hw inside them randomly. Sometimes it works out pretty nicely, but other times it looks like there's a lot of unused space in some corner.
Is there a way to maybe "push" the hws into that space?
If you want heres the actual app (also saves the map in uncompressed xml)http://www.chasekernan.com/FlashNova.air
if you don't have AIR its a 9 meg download at http://www.adobe.com/go/getair
and heres the code (very sloppy right now, format is a little screwed up, but it works (I'm hoping there's not a problem with me posting it its a bit long):
/**
* Just generates a basic map for now, replacing any planets that are too close.
* Dimensions are a vector of width and height
* numberOfPlanets is the total number of planets in the map
* players is an array of players that should be included on the map
* names is the array of names to be used
* germanium is the germanium of all hw (if -1, gens random from between min_hw and max
*/
public function generateRectMap(dimensions:Vector, numberOfPlanets:uint, players:Array, names:Array, germanium:int = -1):void
{
_objects = [];
//check to make sure all obs in races are actually races
for(var i:int = 0; i < players.length; i++)
{
if(!(players[i] is Player))
throw new Error("players must contain all player instances");
}
//check to make surea all obs in names are strings
for(i = 0; i < names.length; i++)
{
if(!(names[i] is String))
throw new Error("names must contain all strings");
}
//if germanium is -1, gen random
if(germanium == -1) germanium = Math.random() * (MineralConcentrations.$MAX_CONC - MineralConcentrations.$MIN_HW_CONC) + MineralConcentrations.$MIN_HW_CONC;
if(germanium < MineralConcentrations.$MIN_HW_CONC || germanium > MineralConcentrations.$MAX_CONC)
throw new Error("germanium value must fall inbetween the values specified by the MinConcentrations class.");
var sqrtPlanets :int = Math.ceil(Math.sqrt(numberOfPlanets));
var plotSize :Vector = new Vector(dimensions.x / sqrtPlanets, dimensions.y / sqrtPlanets);
var excessPlots :int = int(sqrtPlanets * sqrtPlanets - numberOfPlanets);
//randomize player order
var newPlayers :Array = [];
for(i = players.length - 1; i >= 0; i--)
{
newPlayers.push(players.splice(Math.floor(Math.random() * (players.length - 0.0001)), 1)[0]);
}
players = newPlayers;
//randomize name order
var newNames :Array = [];
for(i = names.length - 1; i >= 0; i--)
{
newNames.push(names.splice(Math.floor(Math.random() * (names.length - 0.0001)), 1)[0]);
}
names = newNames;
//border so planets arn't quite so close to eachother
var border :Number = 0.05 * Math.min(plotSize.x, plotSize.y);
var curPlanet :int = 0;
//generic planet var
var p :Planet;
//counter
var j :int;
var randomIntX :int;
var randomIntY :int;
//planets to remove:
var remove :Array = [];
//setup array
for(i = 0; i < sqrtPlanets; i++)
{
remove[i] = [];
for(j = 0; j < sqrtPlanets; j++)
{
remove[i][j]= 1;
}
}
for(i = 0; i < excessPlots; i++)
{
do {
randomIntX = int(Math.random() * (sqrtPlanets - 0.0001));
randomIntY = int(Math.random() * (sqrtPlanets - 0.0001));
} while (remove[randomIntX][randomIntY] == 0);
remove[randomIntX][randomIntY] = 0;
}
//create all of the planets
for(i = 0; i < sqrtPlanets; i++)
{
for(j = 0; j < sqrtPlanets; j++)
{
if(remove[i][j] == 0) continue;
var xloc :int = i * plotSize.x + border + Math.random() * (plotSize.x - border * 2);
var yloc :int = j * plotSize.y + borde
...
Report message to a moderator
|
|
|
|
|
Problem with randomness in planet distrtibution
By: RobO on Fri, 17 August 2007 08:30
|
|
|
Re: Problem with randomness in planet distrtibution
By: Ptolemy on Fri, 17 August 2007 11:12
|
|
|
Re: Problem with randomness in planet distrtibution
By: PaulCr on Fri, 17 August 2007 12:04
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Fri, 17 August 2007 13:34
|
|
|
Re: Problem with randomness in planet distrtibution
By: PaulCr on Fri, 17 August 2007 13:58
|
|
|
Re: Problem with randomness in planet distrtibution
By: Ptolemy on Fri, 17 August 2007 14:11
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Fri, 17 August 2007 14:33
|
|
|
Re: Problem with randomness in planet distrtibution
By: Ptolemy on Fri, 17 August 2007 15:34
|
|
|
Re: Problem with randomness in planet distrtibution
By: iztok on Sat, 18 August 2007 14:04
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Sat, 18 August 2007 14:14
|
|
|
Re: Problem with randomness in planet distrtibution
By: iztok on Sat, 18 August 2007 15:18
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Sat, 18 August 2007 01:54
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Mon, 20 August 2007 01:00
|
|
|
Re: Problem with randomness in planet distrtibution
By: gible on Mon, 20 August 2007 02:57
|
|
|
Re: Problem with randomness in planet distrtibution
By: RobO on Mon, 20 August 2007 06:08
|
|
|
Re: Problem with randomness in planet distrtibution
By: Soobie on Fri, 12 October 2007 05:56
|
|
|
Re: Problem with randomness in planet distrtibution
By: PaulCr on Fri, 12 October 2007 06:36
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
By: yartrebo on Fri, 12 October 2007 11:58
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
By: yartrebo on Fri, 12 October 2007 16:25
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
[LONG] Re: Problem with randomness in planet distrtibution
|
|
|
Re: [LONG] Re: Problem with randomness in planet distrtibution
|
|
|
Re: [LONG] Re: Problem with randomness in planet distrtibution
|
|
|
Re: [LONG] Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
By: PaulCr on Fri, 12 October 2007 16:22
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
|
|
|
Re: Problem with randomness in planet distrtibution
|
Goto Forum:
Current Time: Tue Jun 04 16:10:27 EDT 2024
|