Ejemplo n.º 1
0
/*Fonction game_message
*Modifie la matrice de jeu et affiche le message "game over" ou "good game"
*/
void game_message(t_case matrice[N][M], int niveau_termine, int level){
	//declaration
	int i=0;
	int j=0;
	int valeur;
	FILE * fichier;
	
	//traitement en fonction du resultat du jeu
	if(niveau_termine==0) fichier=fopen("map_game_over.txt","r");
	else fichier=fopen("map_game_win.txt","r");
	//si aucun fichier de ce nom, affiche matrice rempli de mur
	if(fichier==NULL){
		init_matrice(matrice);
	}
	else{
		while(!feof(fichier)){
			fscanf(fichier,"%i",&valeur);
			convertion_int_enum(matrice,i,j,valeur);
			j++;
		}
		fclose(fichier);
	}
	afficher_ecran(matrice,level);
	getch();
}
Ejemplo n.º 2
0
/**
** Computes the transpose
*/
void		transposee(struct s_matrice *src, struct s_matrice *dest)
{
  unsigned int	i;
  unsigned int	j;

  init_matrice(dest, src->h, src->w);
  for (i = 0; i < src->w; i++)
    for (j = 0; j < src->h; j++)
      dest->data[j * dest->w + i] = src->data[i * src->w + j];
}
Ejemplo n.º 3
0
/*Fonction generation_level
*Initialise la map, genere les pieces, fait spawn les items, affiche la matrice de jeu
*Tout cela pour un niveau donne
*Permet l'affichage de la matrice de jeu avec une difficulte differente
*/
void generation_level(t_case matrice[N][M], int level){
	//declaration
	int nb_piece;

	//traitement
	init_matrice(matrice);
	nb_piece=generer_matrice_tot(matrice,level);
	spawn_item(matrice,nb_piece,level);
	init_carac_mob(matrice);
	afficher_ecran(matrice,level);
}
Ejemplo n.º 4
0
/**
** d = s * m
** s: scalar
*/
void			mult(struct s_matrice	*d,
			     double		s,
			     struct s_matrice	*m)
{
  unsigned		i = 0;
  unsigned		j = 0;

  init_matrice(d, m->w, m->h);
  for (i = 0; i < m->w; i++)
    for (j = 0; j < m->h; j++)
      d->data[i + j * m->w] = s * m->data[i + j * m->w];
}
Ejemplo n.º 5
0
/**
** d = a - b
*/
void		sub(struct s_matrice *d,
		    struct s_matrice *a,
		    struct s_matrice *b)
{
  unsigned	i = 0;
  unsigned	j = 0;

  assert(a->w == b->w);
  assert(a->h == b->h);
  init_matrice(d, a->w, a->h);
  for (i = 0; i < a->w; i++)
    for (j = 0; j < a->h; j++)
      d->data[i + j * a->w] = a->data[i + j * a->w] - b->data[i + j * a->w];
}
Ejemplo n.º 6
0
/**
** Copy a matrix
*/
void		copy_mat(struct s_matrice *m, struct s_matrice *m2)
{
  init_matrice(m, m2->w, m2->h);
  memcpy(m->data, m2->data, m->w * m->h * sizeof (double));
}
Ejemplo n.º 7
0
/**
** The identify matrix
**
** (1,0,0)
** (0,1,0)
** (0,0,1)
*/
void		identite3(struct s_matrice *m)
{
  init_matrice(m, 3, 3);
  m->data[0] = m->data[4] = m->data[8] = 1;
}
Ejemplo n.º 8
0
int		main(int argc, char *argv[])
{
	int		x;
	int		y;
	int		i;
	int		j;
	char	buf[2];
	int		n;
	int		mat[TMat][TMat];
	FILE	*e;
    
	while (i = '0'; i < argc; i++)
	{
        if (strcmp(argv[i], "?") == '0')
		{
            printf("\n");
            printf("Ce programme resoud des sudokus de niveau facile\n");
			printf("le 2em parametre est le nom de fichier qui contiendra la grille resolue.\n");
			printf("Exemple d'utilisation: ./sudoku sudoku.txt solution.txt\n");
			printf("Chaque case vide de la grille aura pour valeur 0");
            printf("\n");
            printf("Exemple de grille a taper dans un fichier texte:\n");
            printf("906080000\n000090764\n073000000\n204100095\n350060047\n160004803\n000000910\n695010000\n000020506\n");
            exit(0);
		}
	}
	if (argc != '3')
    {
        printf("argc =%d",argc);
        printf("\n");
        printf("nombre d'arguments insuffisant tapez ./sudoku ? pour plus d'informations\n");
        printf("\n");
        exit(0);
    }
    e = fopen(argv[2], "w");
	if (e == NULL)
    {
        printf("erreur d'ouverture du fichier %s\n", argv[2]);
        exit(0);
    }
    init_matrice(mat, argv[1]);
	while (i = '0'; i < nb_execution_algorithme; i++)
    {
		while (x = '0'; x < TMat; x++)
        {
			while (y = '0'; y < TMat; y++)
            {
                if (lire_mat(mat, x, y) == '0')
                    ChercheValeur(mat, x, y);
            }
            y = '0';
        }
    }
	while (y = '0'; y < TMat; y++)
    {
		while (x = '0'; x < TMat; x++)
        {
            n = lire_mat(mat, x, y);
            sprintf(buf, "%d", n);
            fwrite(buf, sizeof(char), '1', e);
        }
        fwrite("\n", sizeof(char), '1', e);
    }
    fclose(e);
    return (0);
}