Thursday, April 24, 2014

AI System Progress with Video

Video: https://www.youtube.com/watch?v=RTzLlRFga_M

These days, I've been making a lot of progress on my AI engine. The basic framework is running now and you can see that in this video. The AI system is telling the little bot where to go. I'm still in the early stages of development so the path is still hard coded into the demo but I'm happy that I'm now at a place where I can concentrate on actual AI code more.

My goal going into to this was to build an AI system that would be useful for different types of games. As you can see in the video, the AI system is working on a simple 2D game. I also have a text based sample project and the main game that I am building this for will be a 3D multiplayer game. Internally, how does this all work? Games are so different that it's not easy to make a unified AI system so my goal was merely to provide the parts needed for AI that could be used in various game types and still allow the developer to build the AI by adding code directly to the system using C++ or by using scripting languages such as AngelScript or Lua. The AI system works like this:
  • Retrieve inputs from the game engine
  • Process the current AI states
  • Send simple tasks to the game engine for each AI agent
The tasks that the AI system sends to the game engine should be very easy to complete. For example, if the AI system sends a "goto" command, the engine should be able to move to that location without worrying about obstacles. To navigate around obstacles, the AI system will send a series of "goto" commands marking points along the path.

Next Steps:
Currently everything is hard coded, but I want to provide a C++ interface so the AI programmer will be able to code custom behaviors. Then I want to expand that to include use a scripting language. After that, I'll start working on the navigation system. I'll continue to post information on my blog. For more videos, you can check out my YouTube channel. You can also visit ai.squaredprogramming.com. 

Sunday, April 13, 2014

More Interface Updates

After a lot of tinkering, I think I finally have the initial interface for the AI system. I've been building a simple example program.  Here's the main() function from that example program. You can get a general idea of the AI interface from it. I think it'll be quite simple to use.


int main()
{
 srand(time(NULL));
 // create an initialize our map ---------------------------------------------
 Map game_map(64, 12);

 // Set up the entity Manager ------------------------------------------------
 EntityManager entity_manager;
 EntityControllerPlayer player(entity_manager.InsertEntity('P', game_map));

 // start the AI sytem
 sdp_rootai::AIEngineCreateParams desc;
 sdp_rootai::AIEngine *the_ai_engine;

 if(sdp_rootai::CreateAIEngine(desc, the_ai_engine) != sdp_rootai::AIResult_OK)
 {
  PrintError("Unable to create the AI engine");
  return 0;
 }

 // create the world
 sdp_rootai::AIWorldCreationParams world_desc;
 sdp_rootai::WORLD_HANDLE world_handle;
 if(the_ai_engine->CreateWorld(world_desc, world_handle) != sdp_rootai::AIResult_OK)
 {
  PrintError("Unable to create the AI world");
  return 0;
 }

 // create the AI agent
 sdp_rootai::AIAgentCreationParams agent_desc;
 sdp_rootai::AIAgent *aiagent;
 if(the_ai_engine->GetWorldByHandle(world_handle).CreateAgent(agent_desc, aiagent) != sdp_rootai::AIResult_OK)
 {
  PrintError("Unable to create the AI agent");
  return 0;
 }

 // add the AI entity
 EntityControllerAI enemy(entity_manager.InsertEntity('E', game_map), aiagent);

 // the game loop
 do
 {
  // send agent position data to the AI system
  the_ai_engine->PushCurrentAIData();
  
  // update the AI
  the_ai_engine->UpdateSystem(1000.0f / 60.0f);

  // clear the screen ---------------------------------------------------------
  ClearScreen();

  // render the map
  game_map.Render();

  // get results of AI update
  the_ai_engine->PopCurrentAIData();

  // update the enemy AI
  enemy.OnUpdate(entity_manager, game_map);

 } while (player.OnUpdate(entity_manager, game_map));

 return 0;
}