Yep.
False positive, I guess. I scanned it with Avira before uploading, as I do with all executables. If you have a MinGW+SDL dev environment, I can give you the source if you'd like to compile it yourself.
#include <SDL.h>
#include <cstdlib>
#include <time.h>
#ifdef DEBUG
#include <iostream>
#endif
#include "defs.h"
#include "boolgrid.h"
unsigned int GetRandomNumber(int nLow, int nHigh)
{
return (rand() % (nHigh - nLow + 1)) + nLow;
}
void SetPixel ( SDL_Surface* pSurface , int x , int y , SDL_Color color )
{
//convert color
Uint32 col = SDL_MapRGB ( pSurface->format , color.r , color.g , color.b ) ;
//determine position
char* pPosition = ( char* ) pSurface->pixels ;
//offset by y
pPosition += ( pSurface->pitch * y ) ;
//offset by x
pPosition += ( pSurface->format->BytesPerPixel * x ) ;
//copy pixel data
memcpy ( pPosition , &col , pSurface->format->BytesPerPixel ) ;
}
int main ( int argc, char** argv )
{
srand(time(NULL));
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ){printf( "Unable to init SDL: %s\n", SDL_GetError() );return 1;}
#ifndef DEBUG
freopen( "CON", "w", stdout );
freopen( "CON", "w", stderr );
#endif
atexit(SDL_Quit);
SDL_ShowCursor(0);
SDL_Surface* screen = SDL_SetVideoMode(0, 0, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
if ( !screen ){printf("Unable to init video: %s\n", SDL_GetError());return 1;}
const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
boolgrid gridold (vidinfo->current_w,vidinfo->current_h);
boolgrid gridnew (vidinfo->current_w,vidinfo->current_h);
// for (int x = 0; x < vidinfo->current_w; x++)
// {
// for (int y = 0; y < vidinfo->current_h; y++)
// {
// gridold.set(x,y,(GetRandomNumber(0, 1) == 1));
// }
// }
gridold.set(400,400,true);
gridold.set(401,400,true);
gridold.set(402,400,true);
gridold.set(400,401,true);
gridold.set(401,401,true);
gridold.set(500,500,true);
gridold.set(501,502,true);
gridold.set(502,503,true);
SDL_Color on = {50,50,38,IGNORE_VALUE};
SDL_Color off = {0,0,0,IGNORE_VALUE};
//
// program main loop
bool done = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;
// check for keypresses
case SDL_KEYDOWN:
done = true;
break;
case SDL_MOUSEBUTTONDOWN:
done = true;
break;
// case SDL_MOUSEMOTION:
// done = true;
// break;
} // end switch
} // end of message processing
//
for (int x = 0; x < vidinfo->current_w; x++)
{
for (int y = 0; y < vidinfo->current_h; y++)
{
int n = 0; // neighbours
if (gridold.get(x-1, y-1)) n++; // top left
if (gridold.get(x, y-1)) n++; // top middle
if (gridold.get(x+1, y-1)) n++; // top right
if (gridold.get(x-1, y)) n++; // left
if (gridold.get(x+1, y)) n++; // right
if (gridold.get(x-1, y+1)) n++; // bottom left
if (gridold.get(x, y+1)) n++; // bottom middle
if (gridold.get(x+1, y+1)) n++; // bottom right
if ((gridold.get(x, y))) // current cell is 'on'
{
SetPixel(screen, x, y, on);
//if (n < 2) gridnew.set(x, y, false); // die. :(
//if (n > 3) gridnew.set(x, y, false); // die. :(
gridnew.set(x, y, false); // die if on (seeds)
// otherwise (2 or 3), survive. :)
}
else // current cell is 'off'
{
SetPixel(screen, x, y, off);
//if (n == 3) gridnew.set(x, y, true); // IT'S ALIVE!!!
if (n == 2) gridnew.set(x, y, true); // IT'S ALIVE!!!
}
//if ((GetRandomNumber(0, 500) == 10)) gridnew.set(x, y, (GetRandomNumber(0, 1) == 1)); // IT'S
//
}
}
//
if ((GetRandomNumber(0, 10) == 1))
{
int f = GetRandomNumber(0, vidinfo->current_h - 20);
for (int x = 0; x < vidinfo->current_w; x++)
{
for (int y = f; y < f+20; y++)
{
gridnew.set(x, y, false); // IT'S ALIVE!!!
}
}
}
//
gridnew.copy(&gridold);
//
// DRAWING STARTS HERE
// clear screen
//SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
// DRAWING ENDS HERE
// finally, update the screen :)
SDL_Flip(screen);
} // end main loop
// all is well ;)
printf("Exited cleanly\n");
return 0;
}
#include "boolgrid.h"
#ifdef DEBUG
#include <iostream>
#endif
bool ** _data;
int _w, _h;
boolgrid::boolgrid(int w, int h)
{
_data = new bool * [w];
for (int i = 0; i < w; i++) _data[i] = new bool [h];
_w = w;
_h = h;
for (int i = 0; i < w; i++) // wipe to false
{
for (int j = 0; j < h; j++)
{
_data[i][j] = false;
}
}
}
boolgrid::~boolgrid()
{
for (int i = 0; i < _w; i++)
delete[] _data[i];
delete[] _data;
_data = 0;
}
bool boolgrid::get(int x, int y, bool wrapping)
{
if (!wrapping)
{
return _data[x][y];
}
else
{
int tx = x, ty = y;
if (x > ( _w - 1 )) tx = x - _w;
else if (x < 0) tx = _w + x;
if (y > ( _h - 1 )) ty = y - _h;
else if (y < 0) ty = _h + y;
return _data[tx][ty];
}
}
void boolgrid::set(int x, int y, bool value)
{
_data[x][y] = value;
}
int boolgrid::width()
{
return _w;
}
int boolgrid::height()
{
return _h;
}
void boolgrid::copy(boolgrid * target)
{
if ((_w == target->width()) && (_h == target->height()))
{
for (int i = 0; i < _w; i++) // wipe to false
{
for (int j = 0; j < _h; j++)
{
target->set(i,j,_data[i][j]);
}
}
}
else
{
// welp, grids are different sizes!
//std::cout << "error, grids are different sizes in boolgrid::copy!" << std::endl;
}
}