吊打弱智
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
const int NR=25;
int mp[NR][NR];
void print()
{
system("cls");
for(int i=0;i<=14;i++)
{
for(int j=0;j<=14;j++)
{
if(i==0) printf("%-2d ",j);
else if(j==0) printf("%-2d",i);
else if(mp[i][j]==0) cout<<"十 ";
else if(mp[i][j]==1) cout<<"○ ";
else cout<<"● ";
}
cout<<'\n';
}
}
bool isvictory()
{
for(int i=1;i<=13;i++)
{
for(int j=1;j<=13;j++)
{
if((j<=9)&&(mp[i][j]==mp[i][j+1])&&(mp[i][j]==mp[i][j+2])&&(mp[i][j]==mp[i][j+3])&&(mp[i][j]==mp[i][j+4])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(mp[i][j]==mp[i+1][j])&&(mp[i][j]==mp[i+2][j])&&(mp[i][j]==mp[i+3][j])&&(mp[i][j]==mp[i+4][j])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(j<=9)&&(mp[i][j]==mp[i+1][j+1])&&(mp[i][j]==mp[i+2][j+2])&&(mp[i][j]==mp[i+3][j+3])&&(mp[i][j]==mp[i+4][j+4])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(j>=5)&&(mp[i][j]==mp[i+1][j-1])&&(mp[i][j]==mp[i+2][j-2])&&(mp[i][j]==mp[i+3][j-3])&&(mp[i][j]==mp[i+4][j-4])&&(mp[i][j]!=0))
{
return 1;
}
}
}
return 0;
}
void ask(bool g)
{
srand(time(0));
cout<<"你要下在哪里,";
if(g==0)
{
cout<<"1?\n";
int x,y;
x=rand()%14+1; y=rand()%14+1;
Sleep(10);
cout<<x<<' '<<y<<'\n';
while(mp[x][y]||x<1||y<1||x>14||y>14)
{
cout<<"不可以,总司令!";
x=rand()%14+1; y=rand()%14+1;
Sleep(10);
cout<<x<<' '<<y<<'\n';
}
if(g) mp[x][y]=2;
else mp[x][y]=1;
return;
}
else
{
cout<<"2?\n";
int x,y;
cin>>x>>y;
while(mp[x][y]||x<1||y<1||x>14||y>14)
{
cout<<"不可以,总司令!";
cin>>x>>y;
}
if(g) mp[x][y]=2;
else mp[x][y]=1;
return;
}
}
int main()
{
bool y=0;
while(true)
{
print();
ask(y);
y^=1;
if(isvictory())
{
print();
cout<<"总司令,一切都结束了!";
return 0;
}
}
return 0;
}
//●○ ```
#include <bits/stdc++.h>
#include <windows.h>
using namespace std;
const int NR=25;
int mp[NR][NR];
void print()
{
system("cls");
for(int i=0;i<=14;i++)
{
for(int j=0;j<=14;j++)
{
if(i==0) printf("%-2d ",j);
else if(j==0) printf("%-2d",i);
else if(mp[i][j]==0) cout<<"十 ";
else if(mp[i][j]==1) cout<<"○ ";
else cout<<"● ";
}
cout<<'\n';
}
}
bool isvictory()
{
for(int i=1;i<=13;i++)
{
for(int j=1;j<=13;j++)
{
if((j<=9)&&(mp[i][j]==mp[i][j+1])&&(mp[i][j]==mp[i][j+2])&&(mp[i][j]==mp[i][j+3])&&(mp[i][j]==mp[i][j+4])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(mp[i][j]==mp[i+1][j])&&(mp[i][j]==mp[i+2][j])&&(mp[i][j]==mp[i+3][j])&&(mp[i][j]==mp[i+4][j])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(j<=9)&&(mp[i][j]==mp[i+1][j+1])&&(mp[i][j]==mp[i+2][j+2])&&(mp[i][j]==mp[i+3][j+3])&&(mp[i][j]==mp[i+4][j+4])&&(mp[i][j]!=0))
{
return 1;
}
if((i<=9)&&(j>=5)&&(mp[i][j]==mp[i+1][j-1])&&(mp[i][j]==mp[i+2][j-2])&&(mp[i][j]==mp[i+3][j-3])&&(mp[i][j]==mp[i+4][j-4])&&(mp[i][j]!=0))
{
return 1;
}
}
}
return 0;
}
void ask(bool g)
{
srand(time(0));
cout<<"你要下在哪里,";
if(g==0) cout<<"1?\n";
else cout<<"2?\n";
int x,y;
x=rand()%14+1; y=rand()%14+1;
Sleep(10);
cout<<x<<' '<<y<<'\n';
while(mp[x][y]||x<1||y<1||x>14||y>14)
{
cout<<"不可以,总司令!";
x=rand()%14+1; y=rand()%14+1;
Sleep(10);
cout<<x<<' '<<y<<'\n';
}
if(g) mp[x][y]=2;
else mp[x][y]=1;
return;
}
int main()
{
bool y=0;
while(true)
{
print();
ask(y);
y^=1;
if(isvictory())
{
print();
cout<<"总司令,一切都结束了! ";
if(y==0) cout<<"白胜!";
else cout<<"黑胜!";
return 0;
}
}
return 0;
}
//●○机器对决