http://codepad.org/tQJO9dQX
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#define FOR(i, n) for (int (i) = 0; (i) < (n) ; (i)++)
#define FORBE(i, beg, end) for (int (i) = (beg); (i) < (end) ; (i)++)
#define FORRBE(i, beg, end) for (int (i) = (beg) - 1; (i) >= (end) ; (i)--)
#define CAN_PLACE(c, x, y) !((x) > 12 || (x) < ex[d.r][(c)] || (y) > 20 || \
(y) < ey[d.r][(c)] || *(ULL*)(tbm + (y)) & *(ULL*)dbm[d.r][(c)] << (12 - (x)))
struct DiamondInfo { int r, c, x, y; }d;
typedef unsigned long long ULL;
unsigned short D[7][4] = { {51}, {15, 4369}, {547,23,785,116}, {275,113,802,71},
{54,561}, {99,306}, {39,305,114,562} };
const int S[7] = { 1, 2, 4, 4, 2, 2, 4 };
const char * C = "#ILJSZT";
unsigned short dbm[7][4][4], tbm[24];
char tcm[2][24][16];
const int DIR[5][2] = { {0, 0}, {1, 0}, {-1, 0}, {0, 0}, {0, -1} };
const int ex[7][4] = { {4}, {6,3}, {4,5,4,5}, {4,5,4,5}, {5,4}, {5,4}, {5,4,5,4} };
const int ey[7][4] = { {2}, {1,4}, {3,2,3,2}, {3,2,3,2}, {2,3}, {2,3}, {2,3,2,3} };
void p_tcm(int a, int c, int x, int y) {
FOR(i, 24) FOR(j, 16)
if (i >= y && i < y + 4 && (dbm[d.r][c][i - y] << (12 - x) >> j & 1))
tcm[a][i][15 - j] = C[d.r];
else tcm[a][i][15 - j] = tcm[0][i][15 - j];
}
int main() {
srand((unsigned)time(NULL));
memset(tcm, ' ', sizeof(tcm));
FOR(i, 7) FOR(j, 4) FOR(k, 4) dbm[i][j][3 - k] = D[i][j] >> (4 * k) & 0x000F;
int count, k1, k2;
COORD pos = { 0 };
for (count = 0;; _sleep(1), count++) {
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
FORRBE(i, 24, 4) FORRBE(j, 16, 6) printf(j == 6 ? "%c\n" : "%c", tcm[1][i][j]);
if (_kbhit() && (k1 = _getch()))
if (k1 == 224 && _kbhit() && (k2 = _getch() / 2 - 36) >= 0 && k2 < 5 &&
CAN_PLACE((d.c + !k2) % S[d.r], d.x + DIR[k2][0], d.y + DIR[k2][1]))
p_tcm(1, (d.c += !k2) %= S[d.r], d.x += DIR[k2][0], d.y += DIR[k2][1]);
else if (k1 == 27) break;
if (!(count % 100) && CAN_PLACE(d.c, d.x, d.y - 1))
p_tcm(1, d.c, d.x, d.y -= 1);
if (!count || !CAN_PLACE(d.c, d.x + DIR[4][0], d.y + DIR[4][1])) {
*(ULL *)(tbm + d.y) |= *(ULL*)dbm[d.r][d.c] << (12 - d.x);
p_tcm(0, d.c, d.x, d.y);
FORRBE(i, 24, 4)
if (tbm[i] == 0x03FF)
FORBE(j, i, 24) {
tbm[j] = j == 23 ? 0 : tbm[j + 1];
memcpy(tcm[0][j], tcm[0][j + 1], sizeof(tcm[0][0]));
}
d.r = rand() % 7, d.c = rand() % S[d.r];
d.x = 12 - 4, d.y = 20;
p_tcm(1, d.c, d.x, d.y);
}
}
return 0;
}
#include <Windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#define FOR(i, n) for (int (i) = 0; (i) < (n) ; (i)++)
#define FORBE(i, beg, end) for (int (i) = (beg); (i) < (end) ; (i)++)
#define FORRBE(i, beg, end) for (int (i) = (beg) - 1; (i) >= (end) ; (i)--)
#define CAN_PLACE(c, x, y) !((x) > 12 || (x) < ex[d.r][(c)] || (y) > 20 || \
(y) < ey[d.r][(c)] || *(ULL*)(tbm + (y)) & *(ULL*)dbm[d.r][(c)] << (12 - (x)))
struct DiamondInfo { int r, c, x, y; }d;
typedef unsigned long long ULL;
unsigned short D[7][4] = { {51}, {15, 4369}, {547,23,785,116}, {275,113,802,71},
{54,561}, {99,306}, {39,305,114,562} };
const int S[7] = { 1, 2, 4, 4, 2, 2, 4 };
const char * C = "#ILJSZT";
unsigned short dbm[7][4][4], tbm[24];
char tcm[2][24][16];
const int DIR[5][2] = { {0, 0}, {1, 0}, {-1, 0}, {0, 0}, {0, -1} };
const int ex[7][4] = { {4}, {6,3}, {4,5,4,5}, {4,5,4,5}, {5,4}, {5,4}, {5,4,5,4} };
const int ey[7][4] = { {2}, {1,4}, {3,2,3,2}, {3,2,3,2}, {2,3}, {2,3}, {2,3,2,3} };
void p_tcm(int a, int c, int x, int y) {
FOR(i, 24) FOR(j, 16)
if (i >= y && i < y + 4 && (dbm[d.r][c][i - y] << (12 - x) >> j & 1))
tcm[a][i][15 - j] = C[d.r];
else tcm[a][i][15 - j] = tcm[0][i][15 - j];
}
int main() {
srand((unsigned)time(NULL));
memset(tcm, ' ', sizeof(tcm));
FOR(i, 7) FOR(j, 4) FOR(k, 4) dbm[i][j][3 - k] = D[i][j] >> (4 * k) & 0x000F;
int count, k1, k2;
COORD pos = { 0 };
for (count = 0;; _sleep(1), count++) {
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
FORRBE(i, 24, 4) FORRBE(j, 16, 6) printf(j == 6 ? "%c\n" : "%c", tcm[1][i][j]);
if (_kbhit() && (k1 = _getch()))
if (k1 == 224 && _kbhit() && (k2 = _getch() / 2 - 36) >= 0 && k2 < 5 &&
CAN_PLACE((d.c + !k2) % S[d.r], d.x + DIR[k2][0], d.y + DIR[k2][1]))
p_tcm(1, (d.c += !k2) %= S[d.r], d.x += DIR[k2][0], d.y += DIR[k2][1]);
else if (k1 == 27) break;
if (!(count % 100) && CAN_PLACE(d.c, d.x, d.y - 1))
p_tcm(1, d.c, d.x, d.y -= 1);
if (!count || !CAN_PLACE(d.c, d.x + DIR[4][0], d.y + DIR[4][1])) {
*(ULL *)(tbm + d.y) |= *(ULL*)dbm[d.r][d.c] << (12 - d.x);
p_tcm(0, d.c, d.x, d.y);
FORRBE(i, 24, 4)
if (tbm[i] == 0x03FF)
FORBE(j, i, 24) {
tbm[j] = j == 23 ? 0 : tbm[j + 1];
memcpy(tcm[0][j], tcm[0][j + 1], sizeof(tcm[0][0]));
}
d.r = rand() % 7, d.c = rand() % S[d.r];
d.x = 12 - 4, d.y = 20;
p_tcm(1, d.c, d.x, d.y);
}
}
return 0;
}