First, initial release of the Sunflower engine (version 0.26) will come in a few days, so it’s about time to start giving information to anyone who might want to play and make games for it – starting with, how to make AI. Currently it has to be made in Java, but more languages might be supported in the future – especially if many people ask for it.
What you’ll need:
- The official Sunflower engine Jar file (which will be available for download within a few days).
- The AI interface of the game you want to make an AI player for. I still haven’t decided on the official AI interface format, so for now I’ll just write something down for the first game to be released for the engine (which will be Hearts).
- The ability to write and compile a Java class.
How to do it:
- Create a Java class that extends the class AIAgent, and place it in the package sunflower.ai.
- Create a constructor that accepts an AIAdapter and an int (which is the playerNum – identifier of the player in a multiplayer game).
- Override the getSupportedRulesets method, which returns an array of String, with the names of rulesets this AI can play on.
- Override the getName() method, to return whichever name you want to give your AI player.
- Override the play() method. For now, just put nothing but “return false” in it.
- Compile the class, and put the .class file in the resources/AI subfolder of the Sunflower folder.
By now, the player exists and is recognized by the engine. All that remains is to actually play against it.
- Open the resources/menus.xml file. Look for the “Start Game” button, and inside it look for the tag:
Change the value to the name of your own player (the one you returned in getName()).
- This is it – time to play with your new AI opponent!
Of course, it would be a little bit unimpressive to play against someone who doesn’t do anything. So in the next post we’ll see how to put some actual gameplay in the play() method. Stay tuned!
(Note – I was going to put code examples in this post, but my WordPress skills must be lacking, because I can’t get it to look good. So I’ll just put a link to a complete code example in the next post)