아직은 미완성
~cpp
#include<iostream>
#include<ctime>
using namespace std;
void eraser(int row, int col);
int board[8][8];
int count = 0;
int main()
{
for(int i = 0; i<8;i++)
{
for(int j = 0; j<8; j++)
{
board[i][j] = 1;
}
}
srand(time(0));
int row = rand() % 7 + 0;
srand(time(0));
int col = rand() % 7 + 0;
do{
eraser(row, col);
if((row+1)<8 &&(col+2)<8)
{
row = row+1;
col = col+2;
eraser(row, col);
//board[row][col]=2;
}
if((row-2)>=0&&(col-1)>=0)
{
row = row-2;
col = col-1;
eraser(row, col);
board[row][col]=2;
}
if((row-2)>=0 &&(col+1)<8)
{
row = row-2;
col = col+1;
eraser(row, col);
board[row][col]=2;
}
if((row-1)>=0 &&(col+2)<8)
{
row = row-1;
col = col+2;
eraser(row, col);
board[row][col]=2;
}
if((row+2)<8 && (col+1)<8)
{
row = row+2;
col = col+1;
eraser(row, col);
board[row][col]=2;
}
if((row-1)>=0 && (col-2)>=0)
{
row = row-1;
col = col-2;
eraser(row, col);
board[row][col]=2;
}
if((row+1)<8 && (col-2)>=0)
{
row = row+1;
col = col-2;
eraser(row, col);
board[row][col]=2;
}
if((row+2)<8 && (col-1)>=0)
{
row = row+2;
col = col-1;
eraser(row, col);
board[row][col]=2;
}
}while(count < 8);
for(int k = 0; k<8;k++)
{
for(int l = 0; l<8; l++)
{
cout << board[k][l];
}
cout << endl;
}
return 0;
}
void eraser(int row, int col)
{
if(board[row][col]==1)
{
cout << row <<","<< col <<endl;
for(int m = 1; row+m< 8;m++)
{
board[row+m][col] = 0;
}
for(int n = 1; row-n >=0;n++)
{
board[row-n][col] = 0;
}
for(int o = 1; col+o< 8;o++)
{
board[row][col+o] = 0;
}
for(int p = 1; col-p>=0;p++)
{
board[row][col-p] = 0;
}
for(int q = 1; row+q<8 && col-q>=0;q++)
{
board[row+q][col-q] = 0;
}
for(int r = 1; row+r<8 && col+r<8 ;r++)
{
board[row+r][col+r] = 0;
}
for(int s = 1; row-s>=0 && col-s>=0;s++)
{
board[row-s][col-s] = 0;
}
for(int t = 1; row-t>=0 && col+t<8;t++)
{
board[row-t][col+t] = 0;
}
count++;
}
}