#include #include #include #include "common.h" using namespace std; const int NPLAYOUTS=300; //returns +turns if `me` wins, -turns if an opponent wins int mcplayout(Board &bd,int me){ bool lost[NPLAYERS]; memset(lost,0,NPLAYERS*sizeof(bool)); int nlost=0; int win; int turnidx; for(turnidx=1;;turnidx++){ //turnidx=1: one after `me` const int onturn=(me+turnidx)%NPLAYERS; if(lost[onturn])continue; if(bd.ballcount(onturn)==0){ lost[onturn]=true; nlost++; if(nlost==NPLAYERS)break; //? someone would have won... continue; } bd.put(randommove(bd,onturn).idx(),onturn); win=bd.checkwin(); if(win!=-1)break; } if(win==-1)return 0; //? if(win==me)return turnidx; else return -turnidx; } Move calcmove(Board &bd,int me){ int i,j; int score,maxscore=INT_MIN,maxat=0; for(i=0;imaxscore){ maxscore=score; maxat=i; } } return Move(maxat%WID,maxat/WID); } int main(void){ struct timeval tv; gettimeofday(&tv,NULL); srand(tv.tv_sec*1000000+tv.tv_usec); Board bd; char c; Move mv; cin>>c; cin.ignore(1024,'\n'); int me=c-'A'; int x,y,i; while(true){ c=cin.peek(); if(c=='q'||c=='Q')break; for(i=me+1;i%NPLAYERS!=me;i++){ cin>>x>>y; if(x!=-1&&y!=-1)bd.put(x,y,i%NPLAYERS); } cin.ignore(1024,'\n'); mv=calcmove(bd,me); cout<