Code:
#include<iostream>
#include<ctime>
using namespace std;
int bsize(char board[][16], int tile);
int config(char board[][16], int tile);
bool attack(char board[][16], int tile);
void print(char board[][16], int tile);
int main() //need function to test for attacking queen, and to print
{ //out config
srand(time(0));
bsize();
config(char board[][16], int tile);
print(char board[][16], int tile);
return 0;
}
int bsize()
{
int tile;
char board[][16];
cout<<"Please input a number. This number will\nrepersent the number of rows and columns.\nEx. inputting 3 means three rows AND three columns.";
cin>>tile;
return (board[][16], tile);
}
int config(char board[][16], int tile)
{
int queen, random, row=1, column=1;
do
{
do
{
random=rand()%tile+1;
board[row][random]='Q';
row++;
}while(row<=tile);
do
{
random=rand()%tile+1;
board[random][column]='Q';
column++;
}while(column<=tile);
}while(attack()=0);
return (board[][16], tile);
}
bool attack(char board[][16], int tile)
{
int a=(-1), b=(-1), c=(-1), d=0, e=0, f=0, g=0, h=0, i=0, j=0;
bool attack;
do
{
if(board[i+a][j+b] && board[i+c][j+d])
{
attack=1;
}
e++;
f++;
if(e<=3)d++;
if(e<=6 && e>=4)
{
c++;
if(f==3)
{
d=(-1);
h++;
}
}
if(e<=9 && e>=7)
{
b++;
if(h==3)
{
c=(-1);
g++;
}
}
if(e<=12 && e>=10)
{
a++;
}
}while(attack==0);
return attack;
}
void print(char board[][16], int tile)
{
int alpha=0, omega=0, count=0, line=0;
do
{
cout<<board[alpha][omega];
line++;
if(line==tile)cout<<endl;
alpha++;
if(alpha==tile)
{
omega++;
alpha=0;
}
}while(omega<tile);
}