Java sources of
Programming Game AI by Example

About

Programming Game AI by Example is a book written by Mat Buckland.
(September 30, 2004 | ISBN-10: 1556220782 | ISBN-13: 978-1556220784 | Edition: 1)
It is a good book about artificial intelligence in games. Very good for beginners.

But its example sources are written in C++, use Windows libraries and are designed for Visual Studio 2006 and VS 2008. It was very complicated for me to force them to compile in VS 2010 (Express edition). I had to repair some source code, set up VS 2010 (set include and library directories), download and compile new version of luabind etc.
At the end I succeded to setup it – but it is impossible to do it under Linux!

And because I prefere Linux to Windows (no surprise, right?) and Java to C++, I decided to rewrite all examples from C++ to Java. Other reason to do it was that It helped me to practice Java (I am new in Java programming) and it also helped me to understand better all the examples from the book.

Now I decided to provide all my Java source to the world. I hope it could help other people struggling with the C++ source, and Linux (or MAC) users. I also hope to becomme famous all over the world, so don't forget to like my facebook page (a way how you can say thank you :-).

Example

Java applet SimpleSoccer

Updates

  • 09.08.2014
    I have repaired bugs in method PlayerBase.InHotRegion() (in SimpleSoccer project - this bug is also in the original C++ source) and SteeringBehavior.Hide(). Thanks to Nakasya Masuta and Shane Feehily for sending this bugs.
  • 19.05.2014
    I have repaired a bug in classes Smoother.java and SmootherV2.java, where variable m_ZeroValue was not copied to variable sum, but only a reference of m_ZeroValue was assigned to sum. Thanks to Nakasya Masuta for sending this bug.
  • Raven
    28.04.2013
    Raven game is out! This is the last update unless someone send me a bug report.
  • 21.04.2013
    I have repaired a lot of bugs in Raven game and it is almost ready to be published!
  • 14.04.2013
    I have repared method clamp and it's usage in all chapters.
  • 07.04.2013
    I have repared methods PopLuaNumber, PopLuaString and PopLuaBool in LuaHelperFunctions class in all projects in Chapter6.
    Good news! I worked on Chapter7 for a while, and I am able to run it now. But it is still not working as it should, therefore it is not ready to be published yet.
  • 16.01.2013
    I have repaired in a WestwoodMessaging project In GoHomeAndSleepTilRested.java theEnter method – the closing bracket for the if clause needs to include the message dispatch. And I have improved CruderTime.GetCurrentTime so it produces results similar to C++ code. (Both thaks to A. Rick Anderson who send me this patches).
  • 26.10.2012
    I have created How to set up Visual Studio (Express Edition) page.
  • 06.09.2012
    I have repared the Telegram class in Chapter 4 Simple Soccer. HashCode did not always return the same value for two equals telegram.

Chapters

  1. All chapters (3.8 MiB, ZIP)
    This includes all chapters listed below (as NetBeans projects).
    You don't need to download anything else.
  2. Chapter 2 State Machines (203 KiB, ZIP)
    First project in the book. I have rewritten only those parts of the source code, witch I have to. In every other chapter there is rewritten more code from the "common" directory. There might be some differences between "common" packages in the others chapters (the newer the better).
    Remember, that i tried to write the code as similar to the original C++ source as possible. Therefore I used a lot of "import static" and other weird concepts, witch are not a "good Java practise".
  3. Chapter 3 Steering Behaviors (86 KiB, ZIP)
    Code for individual and group movement including the behaviors of seek, flee, arrive, pursuit, wander, evade, obstacle avoidance, wall avoidance etc.
  4. Chapter 4 Simple Soccer (113 KiB, ZIP)
    Implementation of a simple but entertaining artificial intelligence for a team based sports game.
  5. Chapter 5 Pathfinder (98 KiB, ZIP)
    Code of graph node class, graph edge class, graph class, depth first search, breadth first search, edge relaxation, shortest path trees, Dijkstra's search and A*.
  6. Chapter 6 Scripting Source (2.2 MiB, ZIP)
    This chapter is about using lua language with C and C++ source. It describes lua and luabind. But in Java, there are different projects providing lua support. I decided to use LuaJ.
    I managed to rewrite all examples without the need of changing any lua script, but I had to write help lua scripts imitating luabind behavior.
  7. Chapter 7 – 10 Raven (1.1 MiB, ZIP)
    This last 3 chapters sum all knowledge acquired before and add more (for example path planer, goal arbitration or fuzzy logic).
  8. Python code for Blender 3D.
    Bonus: A ported AI code from Programming Game AI By Example Cap.3 'How to Create Autonomously Moving Game Agents' to Python (Blender Game Engine) by Nakasya Masuta.

Subscribe

Subscribe, if you want to be notified about all updates:

3 + 5 =
(antispam check)

References

Message Bug report
Created: 07/21/2012
Last Modified: 05/19/2014
Tato stánka používá ke svému běhu cookies, díky kterým je možné monitorovat, co tu provádíte (ne že bych to bez cookies nezvládl). Také vás tu bude špehovat google analytics. Jestli si myslíte, že je to problém, vypněte si cookies ve vašem prohlížeči, nebo odejděte a už se nevracejte :-). Prohlížením tohoto webu souhlasíte s používáním cookies. Dozvědět se více..