30分少々でざらっと書いたので、機能的にはなーーーーーんにも出来ません。 ただ眺めるだけです。
#include
#define CELLSIZE 5
#define FSIZE_X (640 / CELLSIZE)
#define FSIZE_Y (480 / CELLSIZE)
typedef char FIELDBUF[FSIZE_X][FSIZE_Y];
typedef struct FIELD{
FIELDBUF buf1;
FIELDBUF buf2;
FIELDBUF *front;
FIELDBUF *back;
}FIELD;
static void initialize(FIELD *field);
static void life(FIELD *field);
static void draw(FIELD *field, int xp, int yp);
///////////////////////////////////////////////////////////////////////////////////////////////////
//エントリーポイント //
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)/////////
{
FIELD field;
ChangeWindowMode(TRUE);
if(DxLib_Init() == -1 || SetDrawScreen(DX_SCREEN_BACK)) return -1;
initialize(&field);
while(!ProcessMessage() && !ClearDrawScreen() && !CheckHitKey(KEY_INPUT_ESCAPE)){
draw(&field, 0, 0);
life(&field);
ScreenFlip();
}
DxLib_End();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//初期化 //
void initialize(FIELD *field)//////////////////////////////////////////////////////////////////////
{
int x, y;
for(x = 0; x buf1[x][y] = GetRand(1);
}
}
field->front = &field->buf1;
field->back = &field->buf2;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//生成・淘汰 //
void life(FIELD *field)////////////////////////////////////////////////////////////////////////////
{
int x, y;
for(x = 0; x front)[x][y];
//周囲の生きているセルを数える
for(xo = x - 1; xo front)[xo back)[x][y] = (*field->front)[x][y];
else if(count == 3) (*field->back)[x][y] = 1;
else if(count > 3) (*field->back)[x][y] = 0;
else (*field->back)[x][y] = 0;
}
}
*(LONG_PTR*)&field->front ^= *(LONG_PTR*)&field->back ^= *(LONG_PTR*)&field->front ^= *(LONG_PTR*)&field->back;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//フィールドの描画 //
void draw(FIELD *field, int xp, int yp)////////////////////////////////////////////////////////////
{
int i, x, y;
//セルの描画
for(x = 0; x front)[x][y]) continue;
DrawBox(xp + x * CELLSIZE, yp + y * CELLSIZE, xp + (x + 1) * CELLSIZE, yp + (y + 1) * CELLSIZE, GetColor(0, 255, 0), TRUE);
}
}
//フレームの描画
for(i = 0; i < FSIZE_X + 1; i++) DrawLine(xp + i * CELLSIZE, yp, xp + i * CELLSIZE, xp + FSIZE_Y * CELLSIZE, GetColor(65, 65, 65));
for(i = 0; i < FSIZE_Y + 1; i++) DrawLine(xp, yp + i * CELLSIZE, xp + FSIZE_X * CELLSIZE, yp + i * CELLSIZE, GetColor(65, 65, 65));
}
ブロマイドを入手する日も近そうです。
#追記
ふと思ったけれど、AOJとか問題解く度に答えを貼り付けてたら、ポイントすごい事になるんじゃないかな?
とかとか、思ってみる。