Pathfinding Algorithm For Pacman [closed] - path-finding

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 5 years ago.
Improve this question
I wanted to implement the game Pacman. For the AI, I was thinking of using the A* algorithm, having seen it on numerous forums. However, I implemented the Breadth First Search for some simple pathfinding (going from point a to point b with certain obstacles in between) and found it gave the optimum path always. I guess it might be because in a game like pacman which uses simple pathfinding, there is no notion of costs in the graph. So, will it be OK if I use BFS instead of A* for pathfinding in Pacman?

Well this depends, do you actually want to make the ghosts work like they do in Pac-Man?
Here's a description of how the ghosts' chase AI works (they each work differently). Make sure to read the above Chapter too about how they actually try to get to their target tile. That page is a wonderfully in-depth analysis of Pac-Man, interesting read.

For path-finding, note the following
BFS will look at a lot more nodes than A* will, which makes it much slower
A* will come up with the same answer as BFS
A* is really easy to implement
Use Manhattan Distance as your heuristic - this is insanely easy to implement, and leads to very efficient searches
Look at http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html for more information (the entire series is really interesting)
If you're talking about the ghost AI, check out the page Chad mentioned: The Pac-Man Dossier - the ghosts actually just use the euclidean distance when determining how to make it to their target tiles, which makes them very bad at finding Pac Man in some cases.

It depends. BFS is both complete and optimal (in the sense it finds the optimal solution)
The downside? It may take a long, long, LONG time to find it! Also, depending on the ramification factor of your problem you may run out of memory fast.
If you have no performance issues, then keep BFS, but if you want to try it in a huge maze then it may take a while to get the solution.
I suggest you try A*, the best search strategy IMHO. Even if you are not having problems with BFS, A* is a nice algorithm to implement, and you will learn a lot of cool stuff.

You may want to consider the anti-object approach that the original designers of Pacman used, you can read about it here and here.
However, to answer your question, use what works! If you are getting good results from BFS, use it. Just remember to abstract the pathfinding enough that you can replace it later if you find something better.
Good luck!

BFS will always give the shortest path if no edge weights are used. If you have no need for edge weights, I would use that. You can always switch later.

Related question, which probably answers your question: Path finding in a Java 2d Game?

Related

Linear programming to find a graph circuit

The question itself is pretty simple... This is a vechicle routing problem.
I have a directed graph
I need to get a linear programming model that will somehow tell me the shortest circuit that visits all nodes, and starts and ends at the star. You are allowed to go over an edge more than once. A node is any crossing on the image.
We had like 4 hours of this in class, I have no idea where to even start...
I'm not expection anyone to give me the full model, but I was hoping someone would tell a strategy so I could do this.
Thank you in advance.
I would start from Dijkstra's algorithm for undirected graphs. There are some variants with similar or better performance. Take a look at https://en.wikipedia.org/wiki/Shortest_path_problem#Undirected_graphs, pick a choice, and keep us informed ... :)
The answer here seems to be very easy. (That is, very easy in theory, very hard and a lot of work to code in practice).
This seems like a straight-forward TSP (Travelling Salesperson Problem). Read about some general literature on TSP. You need to set up and solve a TSP where your nodes are the "cities" in a TSP. You also need to include your star as a city in the TSP.
The Dijkstra algorithm will not give you a solution. The Dijkstra algorithm is used for finding fastest/shortest paths between a node and other nodes in a (typically road-) network. However, distance-wise your problem is super-simple: Getting the cheapest travel cost (and path) from one node to another node in your problem is (almost) trivial.
If you are to solve this problem "for real" (not just discuss it), you need to acquire a TSP solver that is able to take your network (both edges and nodes) as input. Your input needs to specify which edges are directed and which are uni-directed. A lot of work in practice: Even if you use a tool, you still need to familiarize yourself with the tool.

Programmer understanding academic writings on maths [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
I would like to know in which order I should learn different areas of maths so I can have a robust overview of all the theory in case I need something for a computer programming problem.
So I've created this mind map
I do not intend to know all those small details about how to do a certain thing (e.g. "gauss-jordan reduction"), I would rather look over an example, but then do it with math software like sage-maths or mathematica.
I would like to know, for instance, how to get to a taylor series, given the analytical function (I know it already, I am merely illustrating the kind of knowledge depth I expect).
So all I all, I want to be able to read academic articles about maths which have applicability in computer science / programming, and actually understand something from those articles, so I can use that knowledge in solving actual programming problems.
The open question is:
(a) In what order do you suggest to learn about these areas, on what areas should I insiste more?
(b) Do you see any missing areas in the mind map?
I was recommended this book in a data structures and Algorithms class a few years ago. It covers a lot of relevant areas ( probability, graphs, counting, relations, etc.) and it's free! :-)
If you want to be serious, you should get a graduate level course on computer science in a university. There is no replacement for this.
You must know basic set theory, big O, basic data structures, basic real analysis. I suggest looking at Cormen et al. 'Introduction to Algorithms', and/or Manber's 'Introduction to Algorithms: A Creative Approach'. For number theory, check Victor Shoup's book - contains far too much, but it is readable at any level.
I suggest not bothering at all with topics such as: complex analysis, functional analysis, projective/inversive geometry, control theory, mathematical physics, until you know you need them.
Instead of making your graph bigger and bigger, make it as small as possible.
There is a good book, that I think would help you to get more out of computer science research papers and dissertations. It's called "Concrete Mathematics: A foundation for Computer Science", and it's available on Amazon:
http://www.amazon.com/Concrete-Mathematics-Foundation-Computer-Science/dp/0201558025/ref=sr_1_1?s=books&ie=UTF8&qid=1341081763&sr=1-1&keywords=math+computer+science
I think this would help because it will all be relevant, and its consolidated which will help expedite the learning process.
Even if you don't have any money, just Google it and take a look at the index to get an idea of what areas you might want to learn.
And here's one more interesting book.
This is almost impossible to answer as many programming tasks require no mathematical knowledge (other than counting and basic logic) at all. If you have specific interests in an area (such as numerical linear algebra or statistics for example) then start there. Still what I would suggest is getting a good grasp of how finite precision arithmetic works. Perhaps read an introductory text on numerical analysis as this will give a good understanding of what numerical stability is. A good book on analysis of algorithms (with regards to speed and efficiency) would do no harm, and if you plan on doing any kind of mathematical programming, getting a sound knowledge of linear algebra is a very good idea. Almost everything in applied mathematics reduces to ultimately solving a linear system of equations (or doing so iteratively).
There is no right answer to be honest.

Finite element method introduction references [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Could you recommend some good articles/notes/tutorials on finite element method (FEM)? I don't deal with advanced math every day, so a tutorial that introduces me to math needed to understand FEM will be great.
My goal is to write my own simulation of deformable bodies (+plasticity). I must use FEM, but it will be good if I will know BEM (Boundary element method) and FDM (Finite difference method) too.
Really understanding Finite Element Methods requires quite a bit of fairly advanced mathematics; unless you have a few years to devote to the cause, let's leave that aside for now.
That said, the basic ideas underlying FEM are fairly simple if you have some experience with ODE solvers. Can you tell us some more about your background and what you really want to learn so that we can suggest some appropriate resources? Do you want to learn the underlying mathematics, or do you just want to learn some cookbook recipes for applying FEM to a certain class of problem?
Your question is unclear. I don't know what you want to know, because it's impossible to tell what you're ignorant of here.
You don't deal with advanced math every day. What do you know about the finite element method? Here are topics you'll need to know:
Statics and dynamics; how to draw free body diagrams
Solid mechanics - strength of materials, elasticity,
Continuum mechanics for large strain models: Lagrangian and Eulerian formulations
Material models - elasticity and plasticity
Partial differential equations
Method of weighted residuals and integral equations
Linear algebra
Numerical methods
Geometric modeling - CAD for geometry and meshing for FEA models
Commercial or open source packages
You don't say whether you want to use a commercial package (ANSYS, NASTRAN, ABAQUS) or something that you'll write.
As far as references go, there are lots of books available now, but they aren't easy to read or absorb. I'd recommend T.J.R. Hughes' Dover book on the subject. It's cheap and good.
But it's not easy.
I just skimmed through the paper. It looks like a survey article, with nothing new to contribute to the state of the art. It covers a lot more than just small strain plasticity of metals. I see fabric models, large strain problems, etc.
It also mentions boundary element methods and finite difference methods. Do you want to know about those, too? Boundary element methods are completely different from finite elements. The former are based on Green's function formulations; the latter use method of weighted residuals.
The paper doesn't have a great deal of depth to it, but it's very broad. What do you want to know?
I don't think it's possible for someone with so little background to write their own. A better place to start would be FENICS.
I can recommend Introduction to Finite Element Methods by Carlos A. Felippa. It is relativly easy to read.
You can find it here, the Chapters are linked on the main page.
Only the direct stiffness method is covered, think of deformations of trusses without time considerations.
It follows a very nice 'hands-on' approach with examples in Mathematica which are well suited for developer folks.
A really good introduction to FEA for beginners is "Practical Stress Analysis with Finite Elements" by Bryan J Mac Donald. This concentrates on stress analysis but shows you how the method works from both a practical and a theoretical point of view. Unlike a lot of other books it is not specific to any particular software and it is written in plain, easy-to-understand language.

How can I learn higher-level programming-related math without much formal training? [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 6 years ago.
Improve this question
I haven't taken any math classes above basic college calculus. However, in the course of my programming work, I've picked up a lot of math and comp sci from blogs and reading, and I genuinely believe I have a decent mathematical mind. I enjoy and have success doing Project Euler, for example.
I want to dive in and really start learning some cool math, particularly discrete mathematics, set theory, graph theory, number theory, combinatorics, category theory, lambda calculus, etc.
My impression so far is that I'm well equipped to take these on at a conceptual level, but I'm having a really hard time with the mathematical language and symbols. I just don't "speak the language" and though I'm trying to learn it, I'm the going is extremely slow. It can take me hours to work through even one formula or terminology heavy paragraph. And yeah, I can look up terms and definitions, but it's a terribly onerous process that very much obscures the theoretical simplicity of what I'm trying to learn.
I'm really afraid I'm going to have to back up to where I left off, get a mid-level math textbook, and invest some serious time in exercises to train myself in that way of thought. This sounds amazingly boring, though, so I wondered if anyone else has any ideas or experience with this.
If you don't want to attend a class, you still need to get what the class would have given you: time in the material and lots of practice.
So, grab that text book and start doing the practice problems. There really isn't any other way (unless you've figured out how osmosis can actually happen...).
There is no knowledge that can only be gained in a classroom.
Check out the MIT Courseware for Mathematics
Also their YouTube site
Project Euler is also a great way to think about math as it relates to programming
Take a class at your local community college. If you're like me you'd need the structure. There's something to be said for the pressure of being graded. I mean there's so much to learn that going solo is really impractical if you want to have more than just a passing nod-your-head-mm-hmm sort of understanding.
Sounds like you're in the same position I am. What I'm finding out about math education is that most of it is taught incorrectly. Whether a cause or result of this, I also find most math texts are written incorrectly. Exceptions are rare, but notable. For instance, anything written by Donald Knuth is a step in the right direction.
Here are a couple of articles that state the problem quite clearly:
A Gentle Introduction To Learning
Calculus
Developing Your Intuition For
Math
And here's an article on a simple study technique that aims at retaining knowledge:
Teaching linear algebra
Consider auditing classes in discrete mathematics and proofs at a local university. The discrete math class will teach you some really useful stuff (graph theory, combinatorics, etc.), and the proofs class will teach you more about the mathematical style of thinking and writing.
I'd agree with #John Kugelman, classes are the way to go to get it done properly but I'd add that if you don't want to take classes, the internet has many resources to help you, including recorded lectures which I find can be more approachable than books and papers.
I'd recommend checking out MIT Open Courseware. There's a Maths for Computer Science module there, and I'm enjoying working through Gilbert Strang's Linear Algebra course of video lectures.
Youtube and videolectures.com are also good resources for video lectures.
Finally, there's a free Maths for CS book at bookboon.
To this list I would now add The Haskel Road to Logic, Maths, and Programming, and Conceptual Mathematics: A First Introduction to Categories.
--- Nov 16 '09 answer for posterity--
Two books. Diestel's Graph Theory, and Knuth's Concrete Mathematics. Once you get the hang of those try CAGES.
Find a good mentor who is an expert in the field who is willing to spend time with you on a regular basis.
There is a sort of trick to learning dense material, like math and mathematical CS. Learning unfamiliar abstract stuff is hard, and the most effective way to do it is to familiarize yourself with it in stages. First, you need to skim it: don't worry if you don't understand everything in the first pass. Then take a break; after you have rested, go through it again in more depth. Lather, rinse, repeat; meditate, and eventually you may become enlightened.
I'm not sure exactly where I'd start, to become familiar with the language of mathematics; I just ended up reading through lots of papers until I got better at it. You might look for introductory textbooks on formal mathematical logic, since a lot of math (especially in language theory) is based off of that; if you learn to hack the formal stuff a bit, the everyday notation might look a bit easier.
You should probably look through books on topics you're personally interested in; the inherent interest should help get you over the hump. Also, make sure you find texts that are actually introductory; I have become wary of slim, undecorated hardbacks labeled Elementary Foobar Theory, which tend to be elementary only to postdocs with a PhD in Foobar.
A word of warning: do not start out with category theory -- it is the most boring math I have ever encountered! Due to its relevance to language design and type theory, I would like to know more about it, but so far I have not been able to deal...
For a nice, scattershot intro to bits of many kinds of CS-ish math, I recommend Godel, Escher, Bach by Hofstadter (if you haven't read it already, of course). It's not a formal math book, though, so it won't help you with the familiarity problem, but it is quite inspirational.
Mathematical notation is is akin to several computer languages:
concise
exacting
based on many idioms
a fair amount of local variations and conventions
As with a computer language, you don't need to "wash the whole elephant at once": take it one part a at time.
A tentative plan for you could be
identify areas of mathematics that are interesting or important to you. (seems you already have a bit of a sense for that, CS has helped you develop quite a culture for it.)
take (or merely audit) a few formal classes in this area. I agree with several answers in this post, an in-person course, at local college is preferable, but, maybe at first, or to be sure to get the most of a particular class, first self-teaching yourself in this area with MIT OCW, similar online resources and associated books is ok/fine.
if an area of math introduces too high of a pre-requisite in terms of fluency with notation or with some underlying concept or (most often mechanical computation and transformation techniques). No problem! Just backtrack a bit, learn these foundations (and just these foundations!) and move forward again.
Find a "guru", someone that has a broad mathematical culture and exposure, not necessarily a mathematician, physics folks are good too, indeed they can often articulate math in a more practical fashion. Use this guru to guide you, as he/she can show you how the big pieces fit together.
Note: There is little gain to be had of learning mathematical notation for its own sake. Rather it should be learned in context, just like say a C# idiom is better memorized when used and when associated with a specific task, rather than learned in vacuo. A related SO posting however provides several resources to decipher and learn mathematical notation
Project Euler takes problems out of context and drops them in for people to solve them. Project Euler cannot teach you anything effectively. I think you should forget about it, if it is popular it does not mean anything. You cannot study Mathematics through Project Euler as it contains only bits and pieces(and some pretty high level pieces) that you're supposed to know in order to solve the problems. Learning mathematics means to consider a subject and a read a book about it and solving exercices or reading solutions, that's how you learn math. If it so happens that through your reading you find something that is close to some project euler thing, your luck , but otherwise Project euler is a complete waste of time. I think the time is much better invested choosing a particular branch of mathematics and studying that. Let me explain why: I solved 3 pretty advanced Projec Euler problems and they were all making appeal to knowledge from Number theory which I happened to have because i studies some part of it. I do not think Iearned anything from Project Euler, it just happened that I already knew some number theory and solved the problems.
For example, if you find out you like number theory, take H. Davenport -> Hardy & Wright -> Kenneth & Rosen's , study those.
If you like Graph Theory take Reinhard Diestel's book which is freely available and study that(or check books.google.com and find whichever is more appropriate to your taste) but don't spread your attention in 999999 directions just because Project Euler has problems ranging from dynamic programming to advanced geometry or to advanced number theory, that is clearly the wrong way to go and it will not bring you closer to your goal.
This sounds amazingly boring
Well ... Mathematics is not boring when you find some problem that you are attached to, which you like and you'd like to find the solution to, and when you have the sufficient time to reflect on it while not behind a computer screen. Mathematics is done with pen and paper mostly(yes you can use computers .. but that's not really the point).
So, if you find a real-world problem, or some programming problem that would benefit from
you knowing some advanced maths, and you know what maths you have to study , it can be motivating to learn in that way.
If you feel you are not motivated it is hard to study properly.
There is also the question of what you actually mean when you say learn. Does the learning process stop after you solved the problems at the end of the chapter of a book ? Well you decide. You can consider you have finished learning that subject, or you can consider you have not finished and read more about it. There are entire books on just one equation and variations of it.
The amount of programming-related math that you can learn without formal training is limited, but it's more than enough. But maybe you can self-teach yourself.
It all boils down to your resources and motivation.
To know mathematics you have to do mathematics not programming(project euler).
For beginning to learn category theory I recommend David Spivak's Category Theory for the Sciences (AKA Category Theory for Scientists) because its relatively comprehensible due to many examples that enable understanding by analogy and which quickly builds a foundation for understanding more abstract concepts.
It requires the ability to reason logically and an intuitive notion of what is a set. It proceeds from sets and functions through basic category theory to adjoint functors, categories of functors, sheaves, monads and an introduction to operads. Two main threads throughout are modeling databases in terms of categories and describing categories with annotated diagrams called ologs. The bibliography provides references to more advanced and specialized topics including recent papers by Dr. Spivak.
An expected outcome from reading this book is the capability of understanding category theory texts and papers written for mathematicians such as Mac Lane's Category Theory for the Working Mathematician.
In PDF format it is available from http://math.mit.edu/~dspivak/teaching/sp13/ (the dynamic version is recommended since its the most recent). The open access HTML version is available from https://mitpress.mit.edu/books/category-theory-sciences (which is recommended since it includes additional content including answers to some exercises).

Where can I find a "Math topic dependency tree" to assist my self-guided refresher on the subject? [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 11 years ago.
Improve this question
I'm trying to reteach myself some long forgotten math skills. This is part of a much larger project to effectively "teach myself software development" from the ground up (the details are here if you're interested in helping out).
My biggest stumbling block so far has been math - how can I learn about algorithms and asymptotic notation without it??
What I'm looking for is some sort of "dependency tree" showing what I need to know. Is calculus required before discrete? What do I need to know before calculus (read: components to the general "pre-calculus" topic)? What can I cut out to fast track the project ("what can I go back for later")?
Thank!
Here's how my school did it:
base:
algebra
trigonometry
analytic geometry
track 1 track 2 track 3
calc 1 linear algebra statistics
calc 2 discrete math 1
calc 3 (multivariable) discrete math 2
differential equations
The base courses were a prerequisite for everything, the tracks were independent and taken in order.
So to answer your specific question, only algebra is needed for discrete. If you want to fast track, do one of these:
algebra, discrete
algebra, linear algebra, discrete (if you want to cover matrices first)
HTH... It about killed me when I returned to school and took these, but I'm a much better programmer for it. Good Luck!
My advice is to lazily evaluate your own dependency tree. Study something you think is interesting -- when you hit something you don't know, go learn about it.
I always find it easier to learn something new when I already have a context in which I want to use it.
This is a particularly cool site for visualizing how everything in the math world fits together:
http://www.math.niu.edu/Papers/Rusin/known-math/index/mathmap.html
It's also got short summaries of many subfields you've probably never heard of, which is fun.
Usually, an overview of each field is a good thing to have when looking at any topic, but it's rare to have a genuine dependence the way we'd think of it. Algebra is always needed. I can't think of a time I've needed any trigonometry. (except to expand it with new things from calculus) I'm even quite sure people wouldn't agree on what a dependency graph would look like, or even in which field each topic belongs.
I think the right way to approach it is to just collect a wide range of topics from all of branches and read them in whatever order you feel like, recording dependencies between topics as you go. (respecting them, or not, as you please.) This should have the far more important property of keeping the student interested.
It's also my experience that if something just has you stumped, just mark it and set it aside for later.
As for my school, well, it was similar to Harrison's:
cominatorics,
linear algebra,
calculus,
numerical analysis (error analysis in particular.)
logic,
statistics, (with operations research / queueing therory.)
Take a look at MathWorld. Browse topics or search for one, you'll get your position in the overall tree.

Resources