#include <iostream> #include <string> #include <map> #include <vector> #include <algorithm> #include <cassert> #include <ctime> #include <cstdlib> #include <cstdio> #define DN 15 #define LB 10 #define SM "MISSED" #define HT 0 #define BT 1 using namespace std; int dx[]={0,1}; int dy[]={1,0}; map<string,int> shipLenght; vector<string> shipTypes; class Board { private: map<string,int> shots; bool isShot[DN][DN]; string type[DN][DN]; public: bool validate(int x,int y) { if(x<1 || y<1 || x>LB || y>LB) return 0; return 1; } Board() { for(int i=1; i<=LB; ++i) for(int j=1; j<=LB; ++j) { isShot[i][j]=0; type[i][j]=SM; } for(int i=0; i<shipTypes.size(); ++i) shots[shipTypes[i]]=0; } string shoot(int x,int y) { if(!validate(x,y)) return SM; if(isShot[x][y]) { if(type[x][y]==SM) return SM; else return "HIT"; } isShot[x][y]=1; if(type[x][y]==SM) return SM; ++shots[type[x][y]]; if(shots[type[x][y]]==shipLenght[type[x][y]]) return "SANK "+type[x][y]; return "HIT"; } bool setShip(int x,int y,int orientation,string ship) { if(orientation<0 || orientation>1) return 0; for(int i=0; i<shipLenght[ship]; ++i) { int ii=x+dx[orientation]*i,jj=y+dy[orientation]*i; if(!validate(ii,jj)) return 0; if(type[ii][jj]!=SM) return 0; } for(int i=0; i<shipLenght[ship]; ++i) { int ii=x+dx[orientation]*i,jj=y+dy[orientation]*i; type[ii][jj]=ship; } return 1; } bool finished() { for(int i=0; i<shipTypes.size(); ++i) if(shipLenght[shipTypes[i]]!=shots[shipTypes[i]]) return 0; return 1; } }; int hits[DN][DN]; int xx[]={1,0,-1,0}; int yy[]={0,1,0,-1}; int main(){ srand(time(NULL)); shipLenght["destroyer"]=2; shipLenght["cruiser"]=3; shipLenght["submarine"]=3; shipLenght["battleship"]=4; shipLenght["aircraft carrier"]=5; shipTypes.push_back("destroyer"); shipTypes.push_back("cruiser"); shipTypes.push_back("submarine"); shipTypes.push_back("battleship"); shipTypes.push_back("aircraft carrier"); Board *b=new Board(); b->setShip(1, 2, 1, shipTypes[0]); b->setShip(2, 4, 1, shipTypes[1]); b->setShip(4, 6, 1, shipTypes[2]); b->setShip(4, 8, 1, shipTypes[3]); b->setShip(3, 10, 1, shipTypes[4]); /* for(int i=0; i<shipTypes.size(); ++i) { int x=0,y=0,o=0; while(!b->setShip(x,y,o,shipTypes[i])) { x=rand()%LB+1; y=rand()%LB+1; o=rand()%2; } cout<<x<<' '<<y<<' '<<o<<'\n'; cout.flush(); } */ for(int i=1; i<=DN; ++i) for(int j=1; j<=DN; ++j) if(!hits[i][j] && (i+j)%3==1) { cout<<i<<' '<<j<<'\n'; cout.flush(); //cerr<<i<<' '<<j<<'\n'; hits[i][j]=1; string res; cin>>res; if(res=="HIT") { int ok=1; for(int d=0; d<4 && ok; ++d) { int ii=i+xx[d],jj=j+yy[d]; for(;b->validate(ii,jj);ii+=xx[d],jj+=yy[d]) { cout<<ii<<' '<<jj<<'\n'; cout.flush(); hits[ii][jj]=1; cin>>res; if(res==SM) break; if(res.find("SANK")!=string::npos) { ok=0; break; } } } } } for(int i=1; i<=DN; ++i) for(int j=1; j<=DN; ++j) if(!hits[i][j] && (i+j)%3==2) { cout<<i<<' '<<j<<'\n'; cout.flush(); //cerr<<i<<' '<<j<<'\n'; hits[i][j]=1; string res; cin>>res; if(res=="HIT") { int ok=1; for(int d=0; d<4 && ok; ++d) { int ii=i+xx[d],jj=j+yy[d]; for(;b->validate(ii,jj);ii+=xx[d],jj+=yy[d]) { cout<<ii<<' '<<jj<<'\n'; cout.flush(); hits[ii][jj]=1; cin>>res; if(res==SM) break; if(res.find("SANK")!=string::npos) { ok=0; break; } } } } } } /* ooxooxooxo oxooxooxoo xooxooxoox ooxooxooxo oxooxooxoo xooxooxoox ooxooxooxo oxooxooxoo xooxooxoox ooxooxooxo */