#include #include #include #include #include #define S (5) using namespace std; int index_deltas[8][2]={{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}}; class Move{ public: 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; 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; } }; Move calculate_move(Board &bd){ vector poss; Move m; int nd,fr,d; int newneu,newidx; 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.from=flip_index(m.from); m.dir=flip_dir(m.dir); } return m; } void protocol_put_move(Move m){ if(should_flip_board){ cout<