/************************************************************************/
/* ペントミノ その6 */
/* */
/* 10×6の盤面に詰め込む */
/* */
/* usage: pentomino */
/************************************************************************/
#include <stdio.h>
#define TRUE 1
#define FALSE 0
#define CN 5 /* セル数 */
#define PN 12 /* ピース数 */
#define WIDTH 10 /* 盤面の幅 */
#define HEIGHT 6 /* 盤面の高さ */
#define BLANK '.' /* ブランク */
char board[WIDTH][HEIGHT]; /* 盤面 */
typedef struct {
int x;
int y;
} Pos;
typedef struct {
char name; /* 名称 */
Pos form[CN]; /* 配置 */
} PieceForm;
void pieceset( int x, int y, PieceForm *pf );
void pieceunset( int x, int y, PieceForm *pf );
void initboard( void );
void printboard( void );
int main(int argc, char **argv);
/*----------------------------------------------------------------------*/
/* 指定位置(x,y)の指定のピース(含む方向)をセットする */
/*----------------------------------------------------------------------*/
void pieceset( int x, int y, PieceForm *pf )
{
int i;
int u, v;
for( i=0; i<CN; ++i ) {
u = x + pf->form[i].x;
v = y + pf->form[i].y;
board[u][v] = pf->name;
}
}
/*----------------------------------------------------------------------*/
/* 指定位置(x,y)の指定のピース(含む方向)を取り除く */
/*----------------------------------------------------------------------*/
void pieceunset( int x, int y, PieceForm *pf )
{
int i;
int u, v;
for( i=0; i<CN; ++i ) {
u = x + pf->form[i].x;
v = y + pf->form[i].y;
board[u][v] = BLANK;
}
}
/*----------------------------------------------------------------------*/
/* 盤面の初期化 */
/*----------------------------------------------------------------------*/
void initboard( void )
{
int x, y;
for( x=0; x<WIDTH; ++x ) {
for( y=0; y<HEIGHT; ++y ) {
board[x][y] = BLANK;
}
}
}
/*----------------------------------------------------------------------*/
/* 盤面のプリント */
/*----------------------------------------------------------------------*/
void printboard( void )
{
int x, y;
for( y=0; y<HEIGHT; ++y ) {
for( x=0; x<WIDTH; ++x ) {
printf( " %c", board[x][y] );
}
printf( "\n" );
}
printf( "\n" );
}
/*----------------------------------------------------------------------*/
/* main */
/*----------------------------------------------------------------------*/
int main(int argc, char **argv)
{
PieceForm pf0 = { 'F', {{ 0, 0},{ 0, 1},{ 1, 1},{ 1, 2},{ 2, 1}} };
PieceForm pf1 = { 'F', {{ 0, 0},{ 1, 0},{ 1, 1},{ 1, 2},{ 2, 1}} };
PieceForm px = { 'X', {{ 0, 0},{ 1,-1},{ 1, 0},{ 1, 1},{ 2, 0}} };
initboard();
pieceset( 1, 2, &pf0 );
printboard();
pieceunset( 1, 2, &pf0 );
pieceset( 1, 2, &pf1 );
printboard();
pieceunset( 1, 2, &pf1 );
pieceset( 6, 4, &px );
printboard();
}
/************************************************************************/
/* End of Pentomino */
/************************************************************************/