#include #include #include // fail is 0 when we have a score, -1 when position didnt change alpha ( < alpha) and 1 when > beta. harray objects are used to store hashing info for a position. struct harray { _int64 hnumber; int fail; int value; int depth; }; class games { public: int board[120]; int tops[8]; int killers[100]; int maxX; int maxY; int aborts; long theTime; int turn; long counter; int hashcounter; int gamenumber; int themove; int bonus[7]; int type; int bonus2[9]; int maxscore; int return0; _int64 hashtoggle; _int64 startnumber; _int64 oldstartnumber; _int64 hashboard[120][3]; long hashmax; struct harray *hasharray; ~games() { return; if(sizeof(hasharray)>1000)// need to fix this delete hasharray; } void computestarthash() { startnumber=oldstartnumber; for(int a=0; a<120; a++) if(board[a]>0) startnumber=hashboard[a][board[a]]^startnumber; } games() { // hashing srand((unsigned) time(NULL)); for(int a=0; a<120; a++) for(int b=1; b<3; b++) { hashboard[a][b]=rand()*rand(); } hashtoggle=rand()*rand(); startnumber=rand()*rand(); hashmax=1024*1024*2; oldstartnumber=startnumber; //hasharray=malloc(sizeof(struct harray) * hashmax); bonus[0]=0; bonus[1]=0; bonus[2]=10; bonus[3]=30; bonus[4]=10; bonus[5]=0; bonus[6]=0; bonus2[0]=0; bonus2[1]=0; bonus2[2]=10; bonus2[3]=20; bonus2[4]=20; bonus2[5]=10; bonus2[6]=0; bonus2[7]=0; for(a=0; a<120; a++) board[a]=-1; for(a=0; a<8; a++) tops[a]=0; maxX=7; maxY=6; turn=0; gamenumber=0; } int translate(int j) { int i=tops[j]; return 10+i*10+1+j; } void makemove(int x) { if(type!=0) { maxX=8; maxY=8; } hashcounter=0; for(int y=0; y<100; y++) killers[y]=-1; // makeing and deleting the hash array here in the move receiver / maker // actually works ok because the hash array only exists for a move // with multiple games at once sometimes and variable times between opponents moveing, // dont have to have the overhead of keeping it for a whole game for every game hasharray= new struct harray[hashmax]; for(long h=0; h 1) { for(zz=0; zz-1 && themove theTime+1000) { aborts = 1; return 0; } } if(depth1 == 0) { int resultscore=0; if(type==2) { for(int j=0; j -1) { int opp1; int opp2; int comp1; int comp2; for(int j=0; j 0 && side > 1) && ( alpha > -40000 && beta < 40000)) { if(currenthash==hasharray[currenthash%hashmax].hnumber) if(hasharray[currenthash%hashmax].depth>=depth1) { hashcounter++; if(hasharray[currenthash%hashmax].fail==1 && hasharray[currenthash%hashmax].value>=beta) return beta; if(hasharray[currenthash%hashmax].fail==-1 && hasharray[currenthash%hashmax].value<=alpha) return alpha; if(hasharray[currenthash%hashmax].fail==0) if(hasharray[currenthash%hashmax].value< beta && hasharray[currenthash%hashmax].value> alpha) return hasharray[currenthash%hashmax].value; } } gotmate = 0; int alphachanged=0; for(int a1=0; a1 alpha) { alpha = points; alphachanged=1; } if(points >= beta && side > 1) { killers[side]=a; hasharray[currenthash%hashmax].hnumber=currenthash; hasharray[currenthash%hashmax].fail=1; hasharray[currenthash%hashmax].depth=depth1; hasharray[currenthash%hashmax].value=beta; return beta; } if(side == 1) myscores[a] = points; if(side > 1 && gotmate == 1) break; } else if(side == 1) // an illegal drop myscores[a] = -100000; } if(alphachanged==0 && side > 1) { hasharray[currenthash%hashmax].hnumber=currenthash; hasharray[currenthash%hashmax].fail=-1; hasharray[currenthash%hashmax].depth=depth1; hasharray[currenthash%hashmax].value=alpha; } else if(alphachanged==1 && side > 1) { hasharray[currenthash%hashmax].hnumber=currenthash; hasharray[currenthash%hashmax].fail=0; hasharray[currenthash%hashmax].value=alpha; hasharray[currenthash%hashmax].depth=depth1; } if(side > 1) return alpha; if(side == 1) { b = moves[0]; for(int a = 0; a< maxX; a++) { int a1=moves[a]; if(myscores[a1] > myscores[b]) b = a1; } } if(side==1 && aborts==0) maxscore=myscores[b]; return b; } int findFour(int x, int token) { //token is 1 or 2 int win=0; int max=4; if(type==2) max=5; // diagonal down int count; count=1; int a; for(a=1; a= max) win=1; count=1; for(a=1; a= max) win=1; count=1; for(a=1; a= max) win=1; count=1; for(a=1; a= max) win=1; return win; } int evaluate(int side, int x, int j, int call) // original { int token=board[x]; if(token==2 && call==1) return 0; if(token==1 && call==2) return 0; if(board[x]==0) return 0; if(board[x]==-1) printf("er"); //token is 1 or 2 int eval=0; /*if(type==0) eval+=bonus[j]; // piece square bonus were j is collum 0-6 else eval+=bonus2[j]; */ // diagonal down int max=4; if(type==2) max=5; int count; int sum=0; int left, right; left=right=0; int broke=0; count=1; int a; for(a=1; a0)// only finds broke on one of the set of 3 eval+=110; if(count > 2 && sum==1) eval+=75; if(count >2 && sum==2) eval+=100; } else { //if(count == 3 && sum==1 && broke==0) //eval+=40; if(count == 3 && sum==2 && broke==0) eval+=15; // broke /*if(count == 2 && broke>0) eval+=25; if(count == 3 && broke>0) eval+=225; if(count > 3 && sum==1) eval+=175; if(count > 3 && sum==2) eval+=250; */ } return eval; } }; // end class