Курсовая работа: Программа "Морской бой"
}
// –
int AI: Generation (Flot *CPU, int col_ship, int col_deck)
{
int x1, y1, k, i, j;
bool vertical = false, regen;
do {
randomize();
x1 = rand()% 10;
y1 = rand()% 10;
regen = false;
for (k = 0; k < col_deck; k++)
for (i = 0; i < col_ship; i++)
for (j = 0; j < CPU -> ship[i].col_deck; j++)
{
if(regen) break;
if(! vertical)
{
if((CPU -> ship[i].desp_of_part[j].x == x1 + k &&
CPU -> ship[i].desp_of_part[j].y == y1) || (x1 + k >= 10))
{
vertical = true;
regen = true;
continue;
}
if((CPU -> ship[i].desp_of_part[j].x – 1 == x1 + k ||
CPU -> ship[i].desp_of_part[j].x + 1 == x1 + k) &&
(CPU -> ship[i].desp_of_part[j].y – 1 == y1 ||
CPU -> ship[i].desp_of_part[j].y + 1 == y1))