Files
college-C/Projects/LifeGame/checkthis.c
2022-02-25 15:33:16 +02:00

38 lines
1.1 KiB
C

void AddOneToNeighbors(int * ptr_mat, int * ptr_loc, unsigned int row_size, unsigned int col_size)
{
int * ptr_last = ptr_mat + (row_size * col_size);
int * ptr_temp = ptr_loc - col_size - ONE;
for (unsigned short count = ZERO; count < THREE; count++)
{
if (ptr_temp >= ptr_mat &&
((int)ptr_temp / sizeof(int)) / row_size == ((((int)ptr_loc / sizeof(int)) / row_size) - ONE))
{
(*(ptr_temp))++;
}
ptr_temp++;
}
ptr_temp = ptr_loc - ONE;
for (unsigned short count = ZERO; count < TWO; count++)
{
if (ptr_temp >= ptr_mat &&
ptr_temp < ptr_last &&
((int)ptr_temp / sizeof(int)) / row_size == ((((int)ptr_loc / sizeof(int)) / row_size)))
{
(*(ptr_temp))++;
}
ptr_temp += TWO;
}
ptr_temp = ptr_loc + col_size - ONE;
for (unsigned short count = ZERO; count < THREE; count++)
{
if (ptr_temp < ptr_last &&
((int)ptr_temp / sizeof(int)) / row_size == ((((int)ptr_loc / sizeof(int)) / row_size) + ONE))
{
(*(ptr_temp))++;
}
ptr_temp++;
}
}