I've got to create an ant simulation for a a piece of coursework.
I've got to use a "2D discrete (grid based) world" to put the ants on. the problem is that I don't know how/what that is.
I just need someone to explain and show me what that is. Thanks a lot in advance!
yea its supposed to be really basic, like the ants are supposed to move around and find food and a nest. – D Goble
Decided to post a reply to the above in a comment, like I said you wont get the exact code you need without posting some of your own but what you need to do (and research) is.
Simulate your world. (There are better ways of doing this but for a simple world look at a 2D array with int values representing the tile e.g. 0 = empty, 1 = ant, 2 = food, 3 = nest, 4 = obstacle)
Store your objects in some sort of structure with properties. (e.g. you will want an Ant object with various actions like move, eat, ect. But if this is one of your first C# projects feel free to ignore this until you are a little more comfortable)
A game tick to progress your game, look up game state management or game loop. (Again this depends on experience, if you want something simple a basic loop will do).
A basic AI for your ants, are they just going to randomly move around (unless they try to hit an obstacle) or will they seek out the nearest source of food and then return to their nest? (If so there are plenty of pathfinding examples out there)
Draw your game, for this just use the console no need for anything fancy. There are loads of examples of C# console games out there that will show you how to do this.
If you do a bit of Googling around each of these terms that should get you most of the way there.
Related
I am new to unity, but I know C# very well.
I am working on a game similar to eu4.
When area is conquered, it should change color.
I have no idea how to do it, or what to search in the internet for a solution.
Here is the map:
(The borders separate the areas)
Any help please?
It's very simple, you just have sprites for each "country".
(So, in the dark color.)
Simply turn them on or off as you wish. That's all there is to it.
Another approach is you could learn how to make and use a typical "flood fill algorithm". But that is far beyond the scope of this question and is a general computer science issue. (You might look on, say, gamedev for starter tips on this. Additionally you'll have to become expert at generating textures dynamically in Unity.)
Check EU4 and CK2 map files. It might give you many ideas how to handle grand strategy maps.
You got some work to do to achieve this. But basically, there is a .bmp file in game files which every province is painted with a unique color. Here is an example of small portion which consist Italy:
Once you've done that, you will need some sort of data file (.csv in eu4's case) that includes which color includes which province, which provinces are neighboring, etc... In EU4, color info and adjadency info are in seperate files, but of course you're free to approach however you want.
Once you are done with "Data" part, you will need an algorithm that scans these files and distinguish each province in seperate game objects. Mainly, you must write a method that removes every color in an image except a certain one, instantiate it to the map and repeat process for each province. And you're done.
Edit: You can, of course, do these manually. But automated process is always better especially when you a lot of povinces to sepearate. Also making tweaks in map will be much easier that way, or you'll have a hard time recreating every single sprite for even small changes.
Another advantage is, you can easily add different mapmodes like heightmap, rivermap or such...
As your question doesn't give much in terms of your structure it's hard to give you examples.
The most straightforward for you probably is to separate your map into nodes (your bordered areas) and display them all as unique gameObjects. You can then access things like their Renderer to give them different colour.
We can give much better answers if you give us more information on how your data/graphics are structured.
TL;DR
Given a 2-dimensional plane (say, 800x600 pixels or even 4000x4000) that can contain obstacles (static objects) or entities (like tanks, or vehicles), how can computer-controlled tanks navigate the map without colliding with static objects while pursuing other tanks? Please note that every static object or entity has the ability to freely rotate at 360 degrees and has an arbitrary size.
Context
What I am really trying to do is to develop a game with tanks. It initially started as a modern alternative to an old arcade game called "Battle City". At first, it might have been easy to develop an AI, considering the 13x13 grid, fixed sizes and no rotation. But now, with free rotation and arbitrary sizes, I am unable to find a way of replicating such behavior in these circumstances.
The computer-controlled tanks must be able to navigate a map full of obstacles and pursue the player. I think that the main problem is generating all the possibilities for a tank to go to; the collision system is already implemented and awaiting to be used. For example, tanks might be able to fit through tight spaces (which can be diagonal, for instance) just by adjusting its angle of rotation.
Although I have quite some experience in programming, this is way beyond my reach. Even though I would prefer a broader answer regarding the implementationn of tank's artificial intelligence, a method for generating the said paths might suffice.
I initially though about using graphs, but I do not know how to apply them considering different tanks have different sizes and the rotation thing gives me a headache. Then again, if I would be using graphs, what will a node represent? A pixel? 16,000,000 nodes would be quite a large number.
What I am using
C# as the main programming language;
MonoGame (XNA Framework alternative) for rendering;
RotatedRectangle class (http://www.xnadevelopment.com/tutorials/rotatedrectanglecollisions/rotatedrectanglecollisions.shtml).
I am looking forward for your guidelines. Thank you for your time!
I've been working on a project of crowd simulation that included path finding and obstacles/other people avoidance.
We've used the Recast Navigation, a all-in-one library which implements state-of-the-art navigation mesh algorithms.
You can get more info here : https://github.com/memononen/recastnavigation
In our project, it has proven to be reliable and very configurable. Even if it's written in C++, you can easily find/make a wrapper (in our case, we've been using it wrapped in Javascript on a Nodejs server!)
If you don't want to use this library, you can still take a look at Navigation Meshes, which is the underlying theory behind Recast.
I hope it will help!
Navigation Mesh, that's what ur looking for. To explain a bit, it's in theory really easy. U build ur World (2D/3D) and after creation u generate a new mesh, that tells entities where they are allowed to move, without colliding with the surroundings. They then move on this mesh. Next is the path generation algorithm which is basically nothing else then checking in any mathematically form how to get on this mesh to it's target. On an actual navigation mesh, this get's rather complicated but easy if u think of a grid where u check which fields to move to get the shortest way.
So short answered, u need any type of additional layer of ur world, that tells the AI where it is allowed to move, and any kind of algorithm that fits ur type of layer to calculate the path.
As a hint, for unity as an example, there are many free good build solutions. Also u will find a bunch of good libraries to achieve this without a game engine like unity.
so after searching I've found only Java and C++, and I'm fond of and only know .net enough to complete my project. We're creating a random tile generating map (think terraria/flat minecraft kinda thing) and after creating almost all of the materials and a bunch of other code in Unity I've realized I can't quite figure this out (and know next to nothing about perlin and can't figure it out, so examples would be appreciated.)
I started in .net (MS VS) splitting the screen space into pieces I called parcels that are 32x32 and created a loop to fill it. But we're using Unity as it's already a game engine and aren't sure how to accomplish this.
First there's the different sprites the map must be made of, I already created classes and coded lists of what must go into what height but I don't know how to generate all random terrain out of nothing, since the world would need to be random and created before the player sees anything.
I tried a mesh but it uses too much memory looping the way it does; I also tried a plane and filling it with textures, but couldn't get the randomization right and then of course it's a flat object with images and not blocks that can be interacted with.
My direct question: How do we generate a world made of thousands of intractable tiles (we have a limit in mind already for both X & Y) out of random tiles that is in 2D space in C#? (Either strict C# or something that can be imported into Unity, similar to the games I mentioned already.)
Thanks in advance for any advice, hope I gave enough information. I know this is all about procedural generation and probably perlin noise algorithms, but neither of us know about those nor know where to start.
Edit: I was asked to give more information, so far I've been using for loops to create both single and chunks of random tiles. Using an IList to store what's gone where so as it's generating nothing overlaps. (I don't know a better way to do this.)
Both methods work great until I star passing about 150 blocks, then it simply locks up and has to be crashed. I've tried it without the list system thinking that data was the cause, it's not. I've tried using Tidy Tile Mapper in Unity, but the same problem exists once you pass about 200 tiles. I can't find the correct way to create objects the player can interact with without clogging memory.
Maybe you could show us a bit of code of what you've tried already. With these kind of things you will always have to manage memory to pull it off, so maybe you're trying the right thing with the wrong methods. This is not an easy question to answer and it would take more than a post here to do it right, besides being different for each different purpose.
I'm wondering what way would be best to render a 2D map for a shooter (these will be static maps) similar to Soldat. Multiple options I've considered are a tile based map (stored in txt files), or just creating different classes for the different terrains I plan to use and creating a data structure to read/store them in a file. (I want to also be able to include things like jumping/running on walls, sliding down walls/slopes ect)
I feel like there must be a better way than either of these, but haven't been able to find definitive information :/
Thanks :)
Soldat used a polygon based format to render and represent it's levels. The editor would have allowed the user to plot points and connections between them to make walls and structures when were then given textures and properties (such as collide = death). Items and images where then overlayed over this.
The soldat rendering engine would then use these structures to perform collision detection and to build up the polygon (triangles that are drawn) representation of the world.
I was going to go with the "just use a tile map," but then I looked at Soldat and it's a bit more complex.
I don't know what they're using, but I suspect they're using polygons and probably colliding against polygons as well. The levels are likely generated with the same sort of primitives you'd see in 3D games, but all in a plane. E.g. texture mapped triangles and collision against the edges of the surfaces rather than against the surface itself.
In my experience, "terrain" is usually an object in itself and the collision and visual representations are data inside that object (aggregated into that object, typically). The different pieces of terrain don't necessarily need to be different types of thing, indeed in all of the games I've made the entire world was generally a single object of type "Terrain" or "World" or something and it managed the doings of the various visible pieces coming into and out of view.
This doesn't feel like a great answer, but I thought I'd try to give you something.
Examples of platform games doing what you want are Braid and Aquaria. You can get Aquaria for 2 pennies litteraly, with the Humble Indie Bundle.
Here's the Aquaria's editor in action. I could not find a decent video of the Braid editor.
I found this other video about IndieLib, and a level editor that they have created which is similar to Aquaria's (Disclaimer: I haven't tried it myself).
Appart from that, googling for "Braid and Aquaria platform engine" should give you more results.
I would recommend reading the book Building XNA 2.0 Games: A Practical Guide for Independent Game Development. It walks you through the development of a 2D side-scoller game named Zombie Smashers (based on the author's award-winning The Dishwasher: Dead Samurai).
Chapter 4: The Map Editor is what you are looking for.
It will help you even if you don't plan on developing in XNA.
I know my question seems pretty vague, but I can't think of a better way to put it, so I'll start off by explaining what I'm trying to do.
I'm currently working on a project whereby I've been given a map and I'm coding a 'Critter' that should be able to navigate its way around the map; the critter has various other functions, but those are not relevant to the current question. The whole program and solution is being written in C#.
I can control the speed of the critter, and retrieve its current location on the map by returning its current X and Y position, I can also set its direction when it collides with the terrain that blocks it.
The only problem I have is that I can't think of a way to intelligently navigate my way around the map; so far I've been basing it on what direction the critter is facing when it collides with the terrain, and this is in no way a good way of moving around the map!
I'm not a games programmer, and this is for a software assignment, so I have no clue on AI techniques.
Here's a link to an image of what the maps and critters look like:
Map and Critter image
I'm in no way looking for anyone to give me a full solution, just a push in the general direction on map navigation.
If the only knowledge of the environment that you have is the position of your critter and its velocity the best you can do is a wall following algorithm I think. If you can detect some of the other things in your environment you have many more options.
Some of the more popular algorithm types are...
A* Search (The classic)
Visibility Graphs
Voronoi Diagrams (similar to the above)
Potential Fields
Potential Fields is a fancy way of saying every obstacle or wall has a "repulsive force" while every goal has an "attractive force". The strength of the force is based on the distance from the object and the "severity" of the object. (A pit of lava is much more severe to travel through than a bumpy road) After constructing the force fields the naive algorithm boils down to following the path of least resistance. Better versions can detect local minima and maxima and escape those wells.
Critter
-----\ /-------\
\ / \
\/ \
Local Minima Trap \
\
\
Goal
A* Search
Take a look at the A* pathfinding algorithm. It's essentially the standard approach for stuff like this.
Amit Patel's write up on pathfinding for games has a pretty good introduction to A* as well as popular variants of the algorithm.
You'll find a C# implementation here, and here
Dynamic A*
Let's say the terrain you'll be searching is not known ahead of time, but rather is discovered as the agent explores its environment. If your agent comes across a previously unknown obstacle, you could just update the agent's map of the terrain and then re-run A* to find a new path to the goal that routes around the obstruction.
While a workable solution, rerunning the planning algorithm from scratch every time you find a new obstacle results in a sizable amount of redundant computation. For example, once you're around the obstacle, it might be that the most efficient route to the goal follows the one you were planning on taking before you discovered the obstacle. By just rerunning A*, you'll need to recompute this section of the previous path.
You can avoid this by using Dynamic A* (D*). Since it keeps track of previously computed paths, when the agent finds a new obstacle, the system only needs to compute new routes in the area around the obstacle. After that, it can just reuse existing paths.
I would use a goal-oriented approach. Your question states the goal is than explore the map and avoid obstacles, so that's what we make our goal. But how do we explore the whole map? We explore what is unexplored.
From the outset you have only one unexplored area, the square you are on. The rest of the map is marked as unexplored. You choose an unexplored location, and make it your goal to explore it. But how do you get there? You create a subgoal to explore the location next to it. And how do you do that - explore the square next to that, and so on, until your original goal is broken down into a sequence of explorations, starting from your current square and navigating to the target square.
As you hit obstacles and discover features of the map, some of the subgoals may need to be changed. E.g. when you hit a wall, the subgoal to explore that square has to be scrubbed and you create a new plan to find an alternate route. This is known as backtracking.
That's basically it for the high level description. I hope it helps!
I seem to be late at the party. If your critter have a GPS and the full map at hand, the right thing to do is definitely A*, and if the map is small enough a simple BFS would do as well if you don't feel like coding up A* (A* has quite a few corner cases you want to handle right).
However a different question is what if your critter only knows the direction of the goal and can only observe locally what is around it? What if your critter does not know the full map?
In this case you would want to implement the "bug algorithm" for navigation. Link: http://www.cs.cmu.edu/~./motionplanning/lecture/Chap2-Bug-Alg_howie.pdf
It's a cute piece of algorithm that works for all unknown maps, you would have a blast coding it I'm sure.