/*------------------------------------------------*/ /* Copyright(C) T.Nakamura 1999 */ /* E-Mail: nakamura (at) tokyo.email.ne.jp */ /*------------------------------------------------*/ /* pentomino */ /* */ /* usage : pento [ { "6*10" | "10*6" | */ /* "5*12" | "12*5" | */ /* "4*15" | "15*4" | */ /* "3*20" | "20*3" } ] */ /* */ /* default ... "6*10" */ /* */ /*------------------------------------------------*/ #include #include /*------------------------*/ /* define constant */ /*------------------------*/ #define PIECE_NO 12 #define UNUSE 0 #define USE 1 #define INHIBIT -1 #define EMPTY 0 #define MAX_X 32 #define MAX_Y 8 /*------------------------*/ /* external variable */ /*------------------------*/ char board[MAX_X][MAX_Y]; int use_piece[PIECE_NO]; int seq_no; int size_x; int size_y; /*------------------------*/ /* display result */ /*------------------------*/ void display() { #define MAX_COL 85 char lp1[MAX_COL]; char lp2[MAX_COL]; int x,y,i; printf(" seq_no=%d\n",seq_no); for (y=0; y<=size_y; y++) { for(x=0; x0) printf("%s\n",lp1); printf("%s\n",lp2); } printf("\n\n"); } /*------------------------*/ /* check_board */ /*------------------------*/ int check_board(int x,int y) { if (board[x][y+1]!=0 && board[x+1][y]!=0) return 1; if (board[x+2][y]!=0 && board[x+1][y+1]!=0 && board[x][y+1]!=0) return 1; if (board[x+1][y]!=0 && board[x+1][y+1]!=0 && board[x][y+2]!=0 && board[x-1][y+1]!=0) return 1; return 0; } /*------------------------*/ /* put_piece */ /*------------------------*/ void search(int posx,int posy,int put_no) { int i,j; static struct piece_s { int no; struct { int x[4]; int y[4]; } type[8]; } piece[PIECE_NO] = { 8, /*** type L ***/ 0,0,0,1, 1,2,3,3, 0,-1,-2,-3, 1,1,1,1, 1,1,1,1, 0,1,2,3, 0,1,2,3, 1,0,0,0, 0,0,0,-1, 1,2,3,3, 0,1,2,3, 1,1,1,1, 1,0,0,0, 0,1,2,3, 1,2,3,3, 0,0,0,1, 4, /*** type T ***/ 1,2,1,1, 0,0,1,2, 0,1,2,0, 1,1,1,2, 0,-1,0,1, 1,2,2,2, 0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2,2,3, 0,-1,1,2, 1,1,0,0, 1, /*** type X ***/ -1,0,1,0, 1,1,1,2, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 4, /*** type V ***/ 0,0,1,2, 1,2,2,2, 0,0,-1,-2, 1,2,2,2, 0,0,1,2, 1,2,0,0, 1,2,2,2, 0,0,1,2, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 8, /*** type P ***/ 1,1,0,0, 0,1,1,2, 1,0,1,2, 0,1,1,1, -1,0,-1,0, 1,1,2,2, 1,2,1,2, 0,0,1,1, 1,1,0,1, 0,1,1,2, 1,1,0,-1, 0,1,1,1, 0,1,0,1, 1,1,2,2, 0,1,1,2, 1,1,0,0, 4, /*** type Z ***/ 1,1,1,2, 0,1,2,2, 0,-1,-2,-2, 1,1,1,2, 1,0,0,-1, 0,1,2,2, 0,1,2,2, 1,1,1,2, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, }; while(board[posx][posy]!=0) { posx++; if (posx>size_x) { posx = 1; posy++; } } /** check board **/ if (check_board(posx,posy)) return; for (i=0; i