Powargrid
  • Home
  • Blog
  • Buy
  • Demo
  • Media
  • Press
  • The Daily Blobbie
  • Blobbie Meme Maker
  • Forums

AI scripting interface: interacting with the game

30/9/2016

0 Comments

 
  • Part 1: introduction
  • Part 2: debugging tools
  • Part 3: interacting with the game
  • Part 4: under the hood
Welcome to part 3 in the series on our AI scripting framework! See part 1 for the introduction and part 2 for a short description of the debugging tools.
This time, we'll look into the functions you can use to interact with the game. The technical term for this is the "API": the Application Programming Interface. Or in this case, maybe it's an AI Programming Interface!
The API defines the functions your code can call do to get information about the current game, and to perform game actions like building things and charging weapons.
Your AI script has access to two global objects with useful functions: Game and Debug. Debug just lets you write stuff to the console. The Game object is what lets you see and manipulate the game grid. It has functions to look at the current game state, like GetMyPower(), GetPiece(x, y), GetHitPoints(x, y), and functions to take actions: Build(piece, x, y, direction) and Charge(x, y).
Of course, those are very low level functions, and to make your life easier, we include several modules with useful functions, including an A* pathfinding implementation for navigating the grid. These are written in Lua, so you can look at the source code and copy/modify/reuse whatever you like! In ailib.lua, you'll find higher level function like ailib.findPieces(pieceType, player),ailib.canHitFrom(tile, withTower, withCannon, cannonDirection) and ailib.getBuildCost(pieceType, tile).
Picture

Pathfinding

There are many ways to figure out where to go on the grid and how to get there, but you'll probably want some sort of pathfinding algorithm, and A* is great! It's my favourite algorithm. My wife thinks it's strange that I even HAVE a favourite algorithm, but hey, that's what she gets for marrying a nerd :)
If you want to know more about pathfinding in general and how we used it to create the built-in skirmish AI, check out this blog post: http://www.powargrid.com/blog/powargrid-ai-part-1-intro-and-pathfinding.

Documentation and example AI

You can find the descriptions for the Game and Debug modules, as well as the Lua utility modules, in the API documentation. If you're not sure how to use a particular function, see how the Daft Wullie example AI uses them. Still stuck? Ask us on the forum or our Steam community hub, we're happy to help!
​In the next installment we'll take a look under the hood of the AI framework.
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    Author

    We're Michiel and Willem. Hi!
    This blog is about the development of Powargrid and our experiences in doing so.

    Archives

    June 2017
    May 2017
    November 2016
    October 2016
    September 2016
    July 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    October 2015
    September 2015
    August 2015
    July 2015
    June 2015
    May 2015
    March 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014
    February 2014
    January 2014
    December 2013
    November 2013
    October 2013
    September 2013
    September 2012
    August 2012

    Categories

    All
    Game Design
    Marketing
    Progress
    Slacking
    Tech

    RSS Feed

© Wee Free Studio | Steam | Twitter | Facebook | RSS feed | Press | Contact