#include <iostream>
#include <iomanip>
using namespace std;

int positionValue(int pos);
pair<int, int> chooseMoveComputer(int pos, int alpha, int beta);
pair<int, int> chooseMoveHuman(int pos, int alpha, int beta);

int positionValue(int pos) {
    static const int value[16]={4,5,3,2,6,7,8,9,1,10,2,11,12,13,14,14};
    if (pos>=15 && pos<31)
        return value[pos-15];
    return -1;
}

pair<int, int> chooseMoveComputer(int pos, int alpha, int beta) {
   	int value(positionValue(pos));
   	int bestNextPos(pos);
	if (value==-1) {
        value=alpha;
        for (int i(1); i<3 && value<beta; ++i) {
    	    pair<int, int> reply(chooseMoveHuman(2*pos+i, alpha, beta));
    	    if (reply.first>value) {
                value=reply.first;
                alpha=value;
                bestNextPos=2*pos+i;
    	    }
	    }
    }
	return make_pair(value, bestNextPos);
}

pair<int, int> chooseMoveHuman(int pos, int alpha, int beta) {
   	int value(positionValue(pos));
   	int bestNextPos(pos);
	if (value==-1) {
	    value=beta;
    	for (int i(1); i<3 && value>alpha; ++i) {
            pair<int, int> reply(chooseMoveComputer(2*pos+i, alpha, beta));
    	    if (reply.first<value) {
    		    value=reply.first;
    		    beta=value;
                bestNextPos=2*pos+i;
    	    }
        } 
	}
	return make_pair(value, bestNextPos);
}

int main() {
    pair<int, int> res(chooseMoveComputer(0, 0, 15));    
    cout<<"Pos:  0"<<" Value: "<<setw(2)<<res.first<<" BestPos: "<<setw(2)<<res.second<<endl;
    cin.get();
}

