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

int positionValue(int pos);
int valueMoveComputer(int pos, int alpha, int beta);
int valueMoveHuman(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;
}

int valueMoveComputer(int pos, int alpha, int beta) {
    cout<<"pos = "<<setw(2)<<pos<<" alpha = "<<setw(2)<<alpha<<" beta = "<<setw(2)<<beta<<endl; 
   	int value(positionValue(pos));
	if (value==-1) {
        value=alpha;
        for (int i(1); i<3 && value<beta; ++i) {
    	    int reply(valueMoveHuman(2*pos+i, alpha, beta));
    	    if (reply>value) {
                value=reply;
                alpha=value;
    	    }
	    }
    }
	return value;
}

int valueMoveHuman(int pos, int alpha, int beta) {
    cout<<"pos = "<<setw(2)<<pos<<" alpha = "<<setw(2)<<alpha<<" beta = "<<setw(2)<<beta<<endl; 
   	int value(positionValue(pos));
	if (value==-1) {
	    value=beta;
    	for (int i(1); i<3 && value>alpha; ++i) {
            int reply(valueMoveComputer(2*pos+i, alpha, beta));
    	    if (reply<value) {
    		    value=reply;
    		    beta=value;
    	    }
        } 
	}
	return value;
}

int main() {
    cout<<"Pos:  0"<<" Value: "<<setw(2)<<valueMoveComputer(0, 0, 15)<<endl;
    cin.get();
}

