Player Creation — Version 0.7
Adding a new player is not a challenging task, it is just a laborious task. If we want our player to be included in future releases of KardsGT, we have to write an AI for each of the games in KardsGT. This may seem like a task in futility, but having a player play different is part of what makes KardsGT stand out from the other games. For our tutorial we are going to create a player named Tux.
Initial Creation
The first step in creating a new player is to create a folder for the new player in the player directory. The name of the directory must be the name of the player. So, for our example we'll create a folder called
tux
. Notice that the directory is lower cased, this is a requirement. In this directory is where we'll store all the code, images, and character specific information about our new player. Next step is to create an image file. If you are planning on submitting the player for inclusion into the game you'll want to create the player using Krita. If not you're free to use what ever you wish, as long as the image can eventually be made into a png or xpm file. The current player image sizes are 600 x 800, as we scale down from there.
AI Creation
Before you create the AI you should consider what type of character you're creating, what interest does he have, his dislikes, etc. Knowing this information will aid you in how you create the AI for each game, assuming you want inclusion into KardsGT. This information is not wasted when you plan to include your character in KardsGT, as you'll want to put it in the characters profile located in the doc directory. The first step is to create a class named after your character, in our case, Tux. This class will derive from AIBase. Once you have done this you are good to go for creating the AI for each game. A good way of keeping each strategy separate is to create a class using the pattern: Game_NameCharacter_NameAI. For a detailed example look at the other developed players.
Connecting the Player
Now that we have everything the way we like it, we need to add Tux to be compiled automatically. In the players.pro file in the HEADERS section add the new headers for your character, and in the SOURCES section add the new sources for your character. There is no need to specify each individual file. For our example we would add the HEADERS variable, tux/*.h.
In the playerfactory.cpp file, located in the src directory, you'll need to add your new character. In the headers only add the character header. For our example, we would add:
#include "players/tux/tux.h"
In the playerNames method add your character's name in the name listing. Finally in the setupAIBase method add:
else if (playersName == "tux")
m_ais.push_back(new Tux());
The very last step is to add the image file name with path in the src.pro file in the IMAGES section.
© 2007 - 2008 by John Schneiderman, released under the
GNU FDL
.
Last Updated: 13 Aug 2008