1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
bool diagonal(int (*board)[8], int, int, int);
int _tmain(int argc, _TCHAR* argv[])
{
int i, j, direction;
bool test = true;
char pause;
int chessBoard[8][8];
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
{
chessBoard[i][j] = 0;
cout << chessBoard[i][j] << " ";
}
cout << endl;
}
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
{
direction = 1;
while(direction < 5 && test != false)
{
****************test = diagonal(chessBoard, i, j, direction);*******************
direction++;
}
if(test == true)
{
chessBoard[i][j] = 1;
break;
}
}
}
for(i = 0; i < 8; i++)
{
for(j = 0; j < 8; j++)
cout << chessBoard[i][j] << " ";
cout << endl;
}
cout << "Press any key + Enter to continue..." << endl;
cin >> pause;
return 0;
}
bool diagonal(int (*board)[8], int i, int j, int dir)
{
int l = 0, m = 0, n = 0, o = 0;
bool diagTest = true;
switch(dir)
{
case 1:
while((i-l) >= 0 && (j-l) >= 0)
{
if(board[i-l][j-l] == 0)
diagTest = true;
else
diagTest = false;
}
break;
case 2:
while((i+m) < 8 && (j+m) < 8)
{
if(board[i+m][j+m] == 0)
diagTest = true;
else
diagTest = false;
}
break;
case 3:
while((i+n) < 8 && (j-n) >= 0)
{
if(board[i+n][j-n] == 0)
diagTest = true;
else
diagTest = false;
}
break;
case 4:
while((i-o) >= 0 && (j+o) < 8)
{
if(board[i-o][j+o] == 0)
diagTest = true;
else
diagTest = false;
}
break;
}
return diagTest;
}
|