How does random map generation work [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am currently working on a text based zombie RPG simulator where there will be a randomly generated city to explore and do things in. I was originally planning to save the city in a 2D array, but then I realized that if I would do that, my array would take up gigabytes of data for just number storage. After doing some research I discovered something called perlin noise, which is an algorithm that generates virtually infinite and random looking terrain based on a single seed, and I'm curious if I could do something similar with my city. Any ideas guys?
I realize I didn't leave you guys with much information about what I need.
The city I want generated should be represented by a grid of coordinates, where each coordinate plots a separate
building on the map. Buildings however should be arranged in a specific way. If it is a financial district, then office buildings and should spawn more frequently. If it is a residential district then buildings like apartment buildings and laundromats should be generated more frequently. If it is a park, then no buildings should be generated.
Also, some buildings should take up more coordinates than others, such as malls and such.
Highways across the city should also be generated, but this is not important if it complicates the code too much, as this is meant to be a simple learning project.

Perlin noise mainly works by combining several "images" (see for instance here: http://devmag.org.za/2009/04/25/perlin-noise/) where some have lower frequencies and other higher. So what you could do is use the value at a certain coordinate of the lower frequencies to determine the type of area in your city. Say for instance the pixel of the image at the lowest frequency is less than 0.5 and that of the second lowest as well, you could state that you are in a financial part of your city. Then the higher frequencies (who vary more) determine the type of building or object (tree,...).
However you will have to experiment with parameters to make it quite realistic.
I know this is kind of a basic answer, but feel free to comment on this procedure.
Roads can probably not be generated using Perlin noise itself, but for instance by an algorithm that does some postprocessing (say for instance you are are in a financial district, you could program a rule that if there is a building on the left of a certain tile and on the right and there is no building at the tile itself, you should introduce a road.

You can use random points and a relaxation like in this tutorial: http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/. It also uses a delaunay triangulation and the dual voronoi-diagram and noisy edges.

Related

Algorithm to index 2d points by clusters [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a problem to solve for which I did not find any usable algorithms after an internet search and I have not been able to come up with a satisfying solution myself yet.
Problem definition:
I am given a set of N-many points, defined by their X- and Y-coordinates, and I am supposed to give each point a unique index between 0 and N. There are a few conditions though:
1) if the geometric distance between two points is small, the difference between their indices should be small too.
2) if point A has a higher X-coordinate as point B it should have a higher index value too.
3) if point A has a higher Y-coordinate as point B it should have a higher index value too.
Other:
The algorithm does not need to be particularly fast or efficient as the data is fairly small (50 ~ 100 points).
I need this algorithm for a user interface with only 2 buttons for navigation through a data set. With one button the user selects the next point and with the other the user selects the previous point.
All suggestions are welcome. Thanks in advance.
Example Image:
This is an example of what a result could look like. Please note how the conditions are not fulfilled for all points (as that would be impossible) but how the indices are still nicely distributed among the clusters.
Sort the points by the Morton curve aka Z-order (Wikipedia).
Then assign numbers.

Efficient way of gathering 4 point subimage, matrix transformation problems + antialiasing [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
QUICK RECAP OF THE PROJECT:
I'm making a car that would drive itself in between the obstacles of which picture will be taken by your phone. The picture should then be cropped to the size of the "area of movement" or the area where car can move. That should have been done automatically. In my case I’d do it like this:
Before you would take picture of the "obstacle map", you would have to put a paper sheet on the ground, so the program would recognize the size of the area/the way image should be transformed to be "perpendicular" to the ground.
In program you would mark the area where car can move and it would crop it. Then it would automatically transform the selected area to be as "perpendicular" as possible, so the obstacle map would be good enough for the car to move in it as it would be an obstacle map.
Then I have 2 options: either to automate obstacle recognition or to make it manual. If I would automate it, I would have to use some sort of OpenCV obstacle recognition. Else id just make a simple program for marking obstacles. After that you would mark a point, where the car should move to and it would calculate the most optimal path with A algorithm. This algorithm only gives the points where the car should move, so I connected with some professors in my school and they are now doing some help with steering of car and calculating the right angle the car should steer to come to certain location.*
I have 2 questions, both connected with BufferedImage.
Two questions back in the past, I asked how to get a sub image that is defined by 4 random points. I got no answers for doing that so I did it myself, but I know that this method is VERY INEFFICIENT and I'd like to know how can it be done better?
My second question is about matrix transformation. I have already been discussing about that and got this code which is basically a modded version of this one. The code is limiting me to the size of the input bufferedimage and i'd like to know how can I "remove" this limit, because in some cases the image needs to be upscaled, but the code keeps cropping it. Also I’d like to have some sort of AA (Anti Aliasing) on it, because the transformed image just looks weird/pixelated.
EDIT: In first question's code, there is a method line(Point p1, Point p2) in class Place_2D which basically creates an arraylist of points connecting 2 points in place, creating a line.
Antialiasing will be achieved by a better sampling scheme than nearest-neighbor. You will get a nice improvement by switching to bilinear interpolation.
Every back-projected point falls between four pixels. The fractional part of the coordinates allow you to compute mixing weights to be assign to the color values of these four pixels.
If the scaling factor is small (transformed image being less than a quarter of the original), you can blur the image beforehand to avoid other artifacts.

Java-How to create an explosion with drawn rectangles? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to make an explosion animation for my 2d Java swing game.
I need it with multiple yellow rectangles, that literally "explode".
My solution was to give each rectangle a different x and y because every rectangle has to go to another direction. The problem is, that I don't how to do this efficiently. Sorry for bad English, please help me. Any help is appreaciated
Here's a very rough outline of what you need to do. For anything more complicated you'll really need a more robust physics engine.
Each piece of the rectangle is represented by an instance of a class (Piece, shall we call it?). All of these Pieces are generated when the rectangle explodes. The Piece class stores information of their x and y positions, their velocity on the x and y axes, their rotation stored in radians, and their angular velocity. All of these values can pretty much be randomly generated if you're just going for a basic explosion effect.
You're going to have to constantly calculate the physics for the game (constantly simulate physics "ticks") and constantly draw the pieces onto the component. This could mean two separate loops, or you could do them together - just don't flood the EDT.
The "tick" is an operation that is applied at a constant rate (say 30 times per second) and does the following:
Add the x and y velocity of the pieces to the position variables, respectively
Add the rotation velocity variable to the rotation angle variable
Reduce the velocity variables towards zero, if you'd like a resistance effect applied on them
And after the tick is complete, you call repaint() on your component. The component can iterate over the Piece classes however you'd like and render them on screen (don't forget about the rotation).
Hopefully this gets you started. Obviously there are a lot of changes and optomizations that need to be made when you go for scalability in a physics engine - but this should give you an idea of how the concept works. I also haven't mentioned synchronization at all which is something you definitely need to take into account if you're dealing with Swing and a physics loop.
If you'd like to look into making physics engines a little more, I'd recommend this series. Hopefully you like math.

Clustering: Finding a Average Reading [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am looking into finding algorithm within the area of clustering or machine learning which will facilitate or creating a typical data reading for a group of readings. The issue is that it must facilitate time series data; thus some traditional (k-means) techniques are not as useful.
Can anyone recommend places to look or particular algorithms that would provide a typical reading and relatively simple to implement (in Java), manipulate and understand?
As an idea. Try to convert all data types into time, then you will have vectors of the same type (time), then any clustering strategy will work fine.
By converting to time I actually mean that any measurement or data type we know about has a time in its nature. Time is not a 4-th dimension, as many think! Time is actually 0-dimension. Even a point of no physical dimensions which may not exist in space, exists in time.
Distance, weight, temperature, pressure, directions, speed... all measures we do can be converted into certain functions of time.
I have tried this approach on several projects and it payed back with really nice solutions.
Hope, this might help you here as well.
For most machine learning problems in Java, weka usually works pretty well.
See, for example: http://facweb.cs.depaul.edu/mobasher/classes/ect584/weka/k-means.html

What data structure to choose, to implement circle with cuts [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I cannot figure out what data structure will be the best for this type of the problem:
I have a circle. It can have cuts at different positions(angle). Segments between cuts have color(say red or black). If there are no cuts all circle has one color.
What operations do I need on it?
[1] Change color of the segment.
[2] Add cut at some angle.
[3] For a given angle tell which segment it belongs.
[4] Join consecutive segments of the same color.
Right now I have class for a Segment storing angles of its ends and color.
And ArrayList to work with it.
Problems that I have:
[1]I want something faster than ArrayList. (TreeSet? something else?)
[2]I am treating circle without cuts as a special case. (two fake cuts at 0 and 0)
[3]I am treating Segments containing 0 angle as special case. Say Segments (7pi/8, pi/8) and (pi/8, 7pi/8) require different approach and enormous amount of if conditions.
The idiomatic way to do this in Java is not to use a data structure, but to create your own class. EG: a SegmentedCircle class. Give it the API you wish it had and then implement that as behavior. It'll probably delegate to other classes named Segment or Cut and may have a list of these.
It's usually a safe bet to get your API right/convenient first, then worry about performance second (and only if it's actually needed). In other words, don't pre-optimize.
Since you've told me that you need faster Adds and Removes, the right tool for the job may be a HashSet. From its documentation:
This class offers constant time performance for the basic operations (add, remove, contains and size)
Note: You need to make sure you implement equals and hashcode correctly on your classes for this to work propertly.

Categories

Resources