I am making a two player strategy game and I have the local multiplayer ready. Now for single player mode, I want to implement an AI that gets the state of the game (I already have a variable for that), and then the AI should refer a file that tells it which move to play in that state.
Is it possible to do something like this, maybe with a xml file like how SpriteFrameName works? The xml file would contain keys for each state which store the move to be played from that state.
Of course it’s possible! it may be difficult, but it is certainly possible…
Say you were doing it for noughts and crosses (tic tac toe for our American cousins).
If you enumerated each possible position and decided which of the nine squares the AI should choose, then in the XML you would have something like
Thanks for the reply. I’ve already figured out how to get the game states and the next move, and they’re both integer values so it’ll be something like this
<key>156</key>
<integer>4</integer>
What I want to know is how do I read the values in cocos2d-x. I have no experience with XML files so I need a little help.
Alright, so I can either generate my AI into a plist file and use the in-built cocos2d-x functions to read it or I can generate a xml and use @doanhieuthien’s code to read it.
At this line I am getting a warning [quote=“doanhieuthien, post:5, topic:21913”] const char* pXmlBuffer = (const char*)FileUtils::getInstance()->getFileData("actors_attr.xml", "rb", nSize);
[/quote]
Saying that getFileData is deprecated.
I think you should read the file .xml and load informations to the memory only one time at begin… (load all variables into the array of class - ex:Vector< ClassOfCharacter* > )
if necessary show the “loading…” during loading.
And then just working with array in memory only, not access to file more than one time…
Turns out the delay was due to using RandomHelper::random_real().
I switched it for RandomHelper::random_int() and I was able to do the AI within the game itself without the need of loading it from a file