Tips for an AI for a 2D racing game [closed] - c++

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have a school project to build an AI for a 2D racing game in which it will compete with several other AIs.
We are given a black and white bitmap image of the racing track, we are allowed to choose basic stats for our car (handling, acceleration, max speed and brakes) after we receive the map. The AI connects to the game's server and gives to it several times a second numbers for the current acceleration and steering. The language I chose is C++, by the way.
The question is
What is the best strategy or algorithm (since I want to try and win)? I currently have in mind some ideas found on the net and one or two of my own, but I would like before I start to code that my perspective is one of the best.
What good books are there on that matter?
What sites should I refer to?

There's no "right answer" for this problem - it's pretty open-ended and many different options might work out.
You may want to look into reinforcement learning as a way of trying to get the AI to best determine how to control the car once it's picked the different control statistics. Reinforcement learning models can train the computer to try to work toward a good system for making particular maneuvers in terms of the underlying control system.
To determine what controls you'll want to use, you could use some flavor of reinforcement learning, or you may want to investigate supervised learning algorithms that can play around with different combinations of controls and see how good of a "fit" they give for the particular map. For example, you might break the map apart into small blocks, then try seeing what controls do well in the greatest number of blocks.
In terms of plotting out the path you'll want to take, A* is a well-known algorithm for finding shortest paths. In your case, I'm not sure how useful it will be, but it's the textbook informed search algorithm.
For avoiding opponent racers and trying to drive them into trickier situations, you may need to develop some sort of opponent modeling system. Universal portfolios are one way to do this, though I'm not sure how useful they'll be in this instance. One option might be to develop a potential field around the track and opponent cars to help your car try to avoid obstacles; this may actually be a better choice than A* for pathfinding. If you're interested in tactical maneuvers, a straightforward minimax search may be a good way to avoid getting trapped or to find ways to trap opponents.
I am no AI expert, but I think the above links might be a good starting point. Best of luck with the competition!

What good books are there on that matter?
The best book I have read on this subject is "Programming Game AI by Example" by Mat Buckland. It has chapters on both path planning and steering behaviors, and much more (state machines, graph theory, the list goes on).

All the solutions above are good, and people have gone to great length to test them out. Look up "Togelius and Lucas" or "Loiacono and Lanzi". They have tries things like neuroevolution, imitation (done via reinforcement learning), force fields, etc. From my point of view the best way to go is center line. That will take an hour to implement. In contrast, neuroevolution (for example) is neither easy nor fast. I did my dissertation on that and it can easily take several months full time, if you have the right hardware.

Related

How should we set the number of the neurons in the hidden layer in neural network? [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 4 years ago.
Improve this question
In neural network theory - setting up the size of hidden layers seems to be a really important issue. Is there any criteria how to choose the number of neurons in a hidden layer?
Yes - this is a really important issue. Basically there are two ways to do that:
Try different topologies and choose best: due to the fact that number of neurons and layers are a discrete parameters you cannot differentiate your loss function with respect to this parameters in order to use a gradient descent methods. So the easiest way is to simply set up different topologies and compare them using either cross-validation or division of your training set to - training / testing / validating parts. You can also use a grid / random search schemas to do that. Libraries like scikit-learn have appropriate modules for that.
Dropout: the training framework called dropout could also help. In this case you are setting up relatively big number of nodes in your layers and trying to adjust a dropout parameter for each layer. In this scenario - e.g. assuming that you will have a two-layer network with 100 nodes in your hidden layer with dropout_parameter = 0.6 you are learning the mixture of models - where every model is a neural network with size 40 (approximately 60 nodes are turned off). This might be also considered as figuring out the best topology for your task.
There are also a few other algorithms for creating and pruning hidden layer neurons on the fly. The one I'm most familiar with is Cascade Correlation, which gets pretty good performance for many applications, despite the fact that the hidden layer starts with a single neuron and adds others as needed.
For further reading see:
The original paper by Scott E. Fahlman and Christian Lebiere, The Cascade-
Correlation Learning Architecture.
• Gábor Balázs' Cascade Correlation Neural Networks: A Survey.
• Lutz Precehelt's Investigation of the CasCor Family of Learning Algorithms Investigation of the CasCor Family of Learning Algorithms.
There are many other such algorithms for dynamically constructing the hidden layer, which can be found scattered across the Internet in various .pdf research papers. Some sleuthing may be worthwhile to avoid reinventing the wheel and may turn up just the right method for the problem you're trying to solve. Neural net research is spread out across many varied disciplines so there's no telling what else is out there; keeping track of all the new algorithms is a daunting prospect. I hope that helps though.
You have to set the number of neurons in hidden layer in such a way that it shouldn't be more than # of your training example. There are no thumb rule for number of neurons.
Ex: If you are using MINIST Dataset then you might have ~ 78K training example. So make sure that combination of Neural Network (784-30-10) = 784*30 + 30*10 which are less than training examples. but if you use like (784-100-10) then it exceeds the # of training example and highly probable to over-fit.
In short, make sure you are not over-fitting and hence you have good chances to get good result.

Computer Vision: Image Comparison and Counting? [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 was curious if it would be possible to count the number of things in a picture, let's say the number of ducks, by first taking a sample picture and then seeing where it matched in a separate picture. So to clarify, we would have 2 pictures (one picture with a single duck, and one picture with 4 ducks for the sake of the argument) and the program would see how many matches it could make in the 4 duck picture by overlaying the one duck picture--thereby counting how many ducks there are in the picture. I've been reading up on computer vision a little bit, and I know that opencv's site talked about using a Fourier transform to break an image into its magnitude and phase. I was hoping to possibly take the magnitude of the one duck picture into a matrix and then compare it to a series of matrices from the four duck picture.
I imagine this would be quite difficult, seeing as how I would have to somehow tell the program the shape of the initial duck and then store that duck's broken down image information into a matrix and then compare that to matrices broken down from the other picture. Any ideas/suggestions? I thought this would be a good learning experience, since I'm an electrical engineering student and I learned Fourier Transforms, DFTs, etc. last semester--it'd just be cool to actually apply them to something.
You are talking about object recognition - one of fundamental problems in computer vision. Your main idea - take a picture of the object, get some features from it and then find same set of features on other image - is correct. However, pixel by pixel comparison (no matter in time or frequency domain) is very error-prone and normally gives poor results. In most cases more high-level features give much better results.
To get started, take a look at Cascade Classifier in OpenCV which uses Haar-like features (small rectangles with particular gray level). It is most well-known for face detection and recognition, but can also be trained for other objects.
You may also be interested in SURF method, which searches for points with similar characteristics, or even AAMs, which try to model shape and appearance of an object.

frisbee trajectory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
This is my first post. I'm the lead programmer on a FIRST robotics team, and this year's competition is about throwing Frisbees. I was wondering if there was some sort of "grand unified equation" for the trajectory that takes into account the air resistance, initial velocity, initial height, initial angle, etc. Basically, I would like to acquire data from an ultrasonic rangefinder, the encoders that determine the speed of our motors, the angle of our launcher, the rotational force (should be pretty constant. We'll determine this on our own) and the gravitational constant, and plug it into an equation in real time as we're lining up shots to verify/guesstimate whether or not we'll be close. If anyone has ever heard of such a thing, or knows where to find it, I would really appreciate it! (FYI, I have already done some research, and all I can find are a bunch of small equations for each aspect, such as rotation and whatnot. It'll ultimately be programmed in C++). Thanks!
I'm a mechanical engineer who writes software for a living. Before moving to tech startups, I worked for Lockheed Martin writing simulation software for rockets. I've got some chops in this area.
My professional instinct is that there is no such thing as a "grand unified equation". In fact, this is a hard enough problem that there might not be very good theoretical models for this even if they are correct: for instance, one of your equations will have to be the lift generated from the frisbee, which will depend on its cross-section, speed, angle of attack, and assumptions about the properties of the air. Unless you're going to put your frisbee in a wind tunnel, this equation will be, at best, an approximation.
It gets worse in the real world: will you be launching the frisbee where there is wind? Then you can kiss your models goodbye, because as casual frisbee players know, the wind is a huge disturbance. Your models can be fine, but the real world can be brutal to them.
The way this complexity is handled in the real world is that almost all systems have feedback: a pilot can correct for the wind, or a rocket's computer removes disturbances from differences in air density. Unless you put a microcontroller with control surfaces on the frisbee, you're just not going to get far with your open loop prediction - which I'm sure is the trap they're setting for you by making it a frisbee competition.
There is a solid engineering way to approach the problem. Give Newton a boot and do they physics equations yourselves.
This is the empirical modeling process: launch a frisbee across a matrix of pitch and roll angles, launch speeds, frisbee spin speeds, etc... and backfit a model to your results. This can be as easy as linear interpolation of the results of your table, so that any combination of input variables can generate a prediction.
It's not guess and check, because you populate your tables ahead of time, so can make some sort of prediction about the results. You will get much better information faster than trying the idealized models, though you will have to keep going to fetch your frisbee :)

open source CRFs implementation for computer vision problems? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
There are several open source implementations of conditional random fields (CRFs) in C++, such as CRF++, FlexCRF, etc. But from the manual, I can only understand how to use them for 1-D problems such as text tagging, it's not clear how to apply them in 2-D vision problems, suppose I have computed the association potentials at each node and the interaction potentials at each edge.
Did anyone use these packages for vision problems, e.g., segmentation? Or they simply cannot be used in this way?
All in all, is there any open source packages of CRFs for vision problems?
Thanks a lot!
The newest version of dlib has support for learning pairwise Markov random field models over arbitrary graph structures (including 2-D grids). It estimates the parameters in a max-margin sense (i.e. using a structural SVM) rather than in a maximum likelihood sense (i.e. CRF), but if all you want to do is predict a graph labeling then either method is just as good.
There is an example program that shows how to use this stuff on a simple example graph. The example puts feature vectors at each node and the structured SVM uses them to learn how to correctly label the nodes in the graph. Note that you can change the dimensionality of the feature vectors by modifying the typedefs at the top of the file. Also, if you already have a complete model and just want to find the most probable labeling then you can call the underlying min-cut based inference routine directly.
In general, I would say that the best way to approach these problems is to define the graphical model you want to use and then select a parameter learning method that works with it. So in this case I imagine you are interested in some kind of pairwise Markov random field model. In particular, the kind of model where the most probable assignment can be found with a min-cut/max-flow algorithm. Then in this case, it turns out that a structural SVM is a natural way to find the parameters of the model since a structural SVM only requires the ability to find maximum probability assignments. Finding the parameters via maximum likelihood (i.e. treating this as a CRF) would require you to additionally have some way to compute sums over the graph variables, but this is pretty hard with these kinds of models. For this kind of model, all the CRF methods I know about are approximations, while the SVM method in dlib uses an exact solver. By that I mean, one of the parameters of the algorithm is an epsilon value that says "run until you find the optimal parameters to within epsilon accuracy", and the algorithm can do this efficiently every time.
There was a good tutorial on this topic at this year's computer vision and pattern recognition conference. There is also a good book on Structured Prediction and Learning in Computer Vision written by the presenters.

Bullet vs Newton Game Dynamics vs ODE physics engines [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I am trying to pick a physics engine for a simple software application. It would be to simulate a rather small number of objects so performance isn't a huge concern. I am mostly concerned with the accuracy of the motion involved. I would also like the engine to be cross-platform between windows/linux/mac and usable with c++ code. I was looking at Bullet, Newton Game Dynamics, and ODE because they are open source. However, if Havok/PhysX are significantly more accurate I would consider those too.
All I seem to find are opinions on the engines, are there any thorough comparisons between the options? Or does anyone have experience trying the various engines out. Since what I'm trying to do is relatively simple there probably isn't a huge difference between them, but I'd like to hear what people have to say about the options? Thanks!
There is a nice comparison of ODE and Bullet here:
http://blog.wolfire.com/2010/03/Comparing-ODE-and-Bullet
Hope it can be useful in making a choice.
Although it is a bit dated, there is a comprehensive comparison of (in alphabetical order) Bullet, JigLib, Newton, ODE, PhysX, and others available here:
http://www.adrianboeing.com/pal/papers/p281-boeing.pdf
The comparison considers integrators, friction models, constraint solvers, collision detection, stacking, and computational performance.
Sorry, but you will never find a real comparison with respect to accuracy. I am searching for three months now for my master thesis and have not found it. So I started to do the comparison on my own but it's still a long way to go. I'm testing with 3d engines and even 2d engines and for now Chipmunk is the one with the highest accuracy so far. So if you have no need for 3d I would reccomend it. However if you have an urgent need for 3d and your problem is as simple as you described it (don't want to expand it in the future?) Bullet and ODE will do it. I would prefer Bullet because it is much more up-to-date and is still actively maintained. At least there is Newton, with which I am fighting right now. Therefore I can't give you pros and cons except that it is a bit more work to get familiar with the (crucial) bad documentation.
Hope that helps. Best regards.
One thing I found really valuable in ODE is the ability to change pretty much every single parameter 'on the fly'. As an example, the engine doesn't seem to complain if you modify the inertia or even the shape of a body. You could replace a sphere with a box and everything would just keep working, or change the size of the sphere.
Other engines are not as flexible usually, because they do a lot of work internally for optimization purposes.
As for accuracy, as far as I know, ODE still supports a very accurate (but slow) solver which is obviously not very popular in the games industry because you can't play around with more than 25-30 objects in real time. Hope this helps.
Check out Simbody, which is used in engineering. It's particularly good for simulating articulated bodies. It has been used for more than 5 years to simulate human musculoskeletal dynamics. It's also one of the physics engines used in Gazebo, a robot simulation environment.
https://github.com/simbody/simbody
http://nmbl.stanford.edu/publications/pdf/Sherm2011.pdf
A physics abstraction layer supports a large number of physics engines via a unified API, making it easy to compare engines for your situation.
PAL provides a unique interface for these physics engines:
Box2D (experimental)
Bullet
Dynamechs(deprecated)
Havok (experimental)
IBDS (experimental)
JigLib
Meqon(deprecated)
Newton
ODE
OpenTissue (experimental)
PhysX (a.k.a Novodex, Ageia PhysX, nVidia PhysX)
Simple Physics Engine (experimental)
Tokamak
TrueAxis
According to the December 2007 paper linked in this answer:
Of the open source engines the Bullet engine provided the best results
overall, outperforming even some of the commercial engines. Tokamak
was the most computationally efficient, making it a good choice for
game development, however TrueAxis and Newton performed well at low
update rates. For simulation systems the most important property of
the simulation should be determined in order to select the best
engine.
Here is a September 2007 demo by the same author:
https://www.youtube.com/watch?v=IhOKGBd-7iw