#include #include #include #include #include #include #define S (5) using namespace std; bool should_flip_board=false; struct Move; class Board; Move protocol_get_move(void); void protocol_put_move(ostream &s,Move m); int index_deltas[8][2]={{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}}; struct Move{ int neudir,from,dir; string str(void){ stringstream ss; ss<=S||y2<0||y2>=S||grid[S*y2+x2]!=0)return S*y+x; x=x2; y=y2; } } bool move(int at,int dir){ int newat=moved(at,dir); if(newat==at)return false; grid[newat]=grid[at]; grid[at]=0; if(grid[newat]==3)neuidx=newat; return true; } void undomove(int at,int dir){ int movedidx=moved(at,dir); movedidx+=S*index_deltas[dir][1]+index_deltas[dir][0]; grid[at]=grid[movedidx]; grid[movedidx]=0; if(grid[at]==3)neuidx=at; } bool isvalid(Move mv){ int oldneuidx=neuidx; //cerr<<"Called isvalid with move "; //protocol_put_move(cerr,mv); //print(); if(!move(oldneuidx,mv.neudir)){ //undomove(oldneuidx,mv.neudir); return false; } if(!move(mv.from,mv.dir)){ //undomove(mv.from,mv.dir); undomove(oldneuidx,mv.neudir); return false; } undomove(mv.from,mv.dir); undomove(oldneuidx,mv.neudir); return true; } void print(void){ int x,y; if(should_flip_board){ for(y=S-1;y>=0;y--){ for(x=S-1;x>=0;x--)cerr< poss; Move m; int nd,fr,d; int newneu; //bd.print(); for(nd=0;nd<8;nd++){ newneu=bd.moved(bd.neuidx,nd); if(newneu==bd.neuidx)continue; for(fr=0;fr>m.neudir>>m.from>>m.dir; if(should_flip_board){ m.neudir=flip_dir(m.neudir); m.from=flip_index(m.from); m.dir=flip_dir(m.dir); } cerr<<"Got: "; protocol_put_move(cerr,m); cin.ignore(1024,'\n'); return m; } void protocol_put_move(ostream &s,Move m){ if(should_flip_board){ s<