#ifndef AI_H#define AI_H#include "cocos2d.h"USING_NS_CC;class SceneGame;class Step : public CCObject{public:int _moveid;int _killid;int _xFrom;int _yFrom;int _xTo;int _yTo;static Step* create(int moveid, int killid, int xFrom, int yFrom, int xTo, int yTo){Step* step = new Step;step->_killid = killid;step->_moveid = moveid;step->_xFrom = xFrom;step->_xTo = xTo;step->_yFrom = yFrom;step->_yTo = yTo;step->autorelease();return step;}};class AI{public:AI(SceneGame *game);SceneGame *_game;Step *GenOneMove(int level=2);int getScore();staticint _score[7];CCArray *getAllPossibleMove();void getAllPossibleMove(int idx,CCArray *arr);int getMinValue(int level,int maxScore);int getMaxValue(int level,int minScore);Step *_step;};#endif // AI_H
得分表
int AI::_score[7]=
{1000,10,10,100,50,50,20
};
創建一步
Step *AI::GenOneMove(int level)
{int maxScore=-10000;Step *ret;//find all possible access an calcute the hights scoreCCArray *possibleMOve=getAllPossibleMove();CCObject *obj;CCARRAY_FOREACH(possibleMOve,obj){Step *step=(Step*)obj;_game->fakeMove(step);int score=getMinValue(level-1,maxScore);//int score=getScore();_game->unfakeMove(step);if(score>maxScore){maxScore=score;ret=step;}}return ret;}