Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *$Id: framework.h,v 1.2 2012/10/03 16:55:26 Ben Exp Ben $
- $Log: framework.h,v $
- Revision 1.2 2012/10/03 16:55:26 Ben
- Mostly Working, few bugs
- Revision 1.1 2012/10/03 04:13:26 Ben
- Initial revision
- */
- #ifndef framework
- #define framework
- #include "player.h"
- #include <vector>
- #include <map>
- #include "takeawayClass.h"
- #include <iostream>
- #include "player.h"
- #include <map>
- using namespace std;
- template <typename T>
- class Framework {
- public:
- Framework<T>(){};
- void move(T game, player p){
- int move=0;
- game.printBoard();
- cout<<"Player "<<p.getPlayerNum()<<"'s turn!"<<endl;
- if(p.getType()=="HU"){
- game.move(game.getHumanMove());
- }//end human move
- else if(p.getType()=="CO"){
- //move=findBestMove(tiles,*(new int(0)),*(new int(0)),1);
- move=findBestMove(game);
- cout<<"AI determined "<<move<<" was the best move"<<endl;
- game.move(move);
- }
- };
- int findBestMove(T game){
- //vector<T> games(10);
- int max=-100;
- T maxGame(0);
- vector<int> scores(game.possibleMoves().size());
- for(int i=0;i<(game.possibleMoves().size());i++){
- // games[i]=game.possibleMoves().at(i);
- scores[i]=findBestMoveHelper(game.possibleMoves()[i],1);
- cout<<"Move: "<<game.penniesLeft()-game.possibleMoves()[i].penniesLeft()<<" Score: "<<scores[i]<<endl;
- if(scores[i]>max){
- T newMax(game.possibleMoves()[i].penniesLeft());
- maxGame=newMax;
- max=scores[i];
- }
- }
- cout<<"Move: "<<game.penniesLeft()-maxGame.penniesLeft()<<endl;
- };
- int findBestMoveHelper(T game, int turn){
- //else{
- //cout<<"Helper called on: "<<game.penniesLeft()<<endl;
- int score=0;
- if(turn==0){
- if(game.possibleMoves().size()==1){
- return -1;
- }
- else if(game.possibleMoves().size()==0){
- return 1;
- }
- else{
- for(int i =0; i < game.possibleMoves().size(); i++){
- // cout<<game.possibleMoves()[i].penniesLeft()<<endl;
- T newGame(game.possibleMoves()[i].penniesLeft());
- score+= findBestMoveHelper(newGame,1);
- }
- return score;
- }
- }
- else if(turn==1){
- if(game.possibleMoves().size()==1){
- return 1;
- }
- else if(game.possibleMoves().size()==0){
- return -1;
- }
- else{
- for(int i =0; i < game.possibleMoves().size(); i++){
- // cout<<game.possibleMoves()[i].penniesLeft()<<endl;;
- T newGame(game.possibleMoves()[i].penniesLeft());
- score+= findBestMoveHelper(newGame,0);
- }
- return score;
- }
- }
- // }
- };
- T returnBestMove(player p){
- return findBestMove();
- }
- bool contains( int name ) const{
- return memo.find(name)!=memo.end();
- };
- private:
- map<int, int> memo;
- };
- #endif
Add Comment
Please, Sign In to add comment