Hi friends. I am trying to place a 4x4 matrix(piece) inside a 5X5 (card). This is done however only when all the positions into which the piece is going to be copied are free. Consider the following arrays of chars:
Code:
char CARD[sizeof_card][sizeof_card] = {
{'x', 'x', ' ', 'x','x'},
{' ', ' ', ' ', ' ','x'},
{'x', ' ', ' ', ' ','x'},
{' ', ' ', ' ', ' ','x'},
{'x', ' ', ' ', ' ','x'},
};
char piece[sizeof_piece][sizeof_piece] = {
{' ',' ','g',' '},
{'g','g','g',' '},
{' ','g',' ',' '},
{' ',' ',' ',' '},
};
and the function that returns (int) the number of all possible positions where "piece" can be placed with or without rotation(counter-cw). For example it can be located at 1st position :[0][0][how_often_rotates = 0], 2nd position : [1][1] [how_often_rotates = 0], 3rd position: [1][0][how_often_rotates = 0], 4th position (possible) : [1][0][how_often_rotates = 1]. A struct holds the data and here is how it looks like: (from sample)
14 // number of all possible positions "piece" can be located .
0, 0, 0 // piece rotated 0x counter-cw
1, 1, 0 // piece rotated 0x counter-cw
:
1, 0, 1 // piece rotated 1x
1, 1, 1 // piece rotated 1x
:
Code:
typedef struct tag_possible_xy_rot_positions /* I have problems incrementing total_num_of_possible_positions in struct */
{
int total_num_of_possible_positions;
int **p2p2_positions_rotations;
} POSSIBLE_XY_ROTATE_POSITIONS;
Code:
#include"someheader.h"
#define BLANK 32
//variables
typedef struct info{
int height;
int width;
}INFO;
dim_piece(char (*piece)[4], INFO *p2_piece_coordinates, int sizeof_piece)
{
int i, j;
for(i=0;i<sizeof_piece;i++)
{
for(j=0;j<sizeof_piece;j++)
{
if((int)piece[i][j] != BLANK)
{
if(p2_piece_coordinates->width <= j)
{
p2_piece_coordinates-> width= j + 1;
}
if(p2_piece_coordinates->height <= i)
{
p2_piece_coordinates->height = i + 1;
}
}
}
}
return 0;
}
Code:
/* Return value of where_the_piece_fits(
card, // card[5][5]
piece // piece [4][4]
sizeof_card // 5
sizeof_piece); // 4
*/
Code:
void where_the_piece_fits(char (*card)[5], char (*piece)[4], int sizeof_card, int sizeof_piece)
{
INFO piece_cooardinates = { 0 , 0 };
INFO *p2_piece_coordinates= &piece_coordinates;
// Dim(height, width) of piece
dim_piece(piece, p2_piece_coordinates,sizeof_piece);
}
I'd appreciate if you could help me to get my function : where_the_piece_fits() and the struct tag_possible_xy_rot_positions somehow working. Thank you all in advance.