Skip to content
Extraits de code Groupes Projets
Valider 81d6a9d2 rédigé par Loïc DUBARD's avatar Loïc DUBARD :speech_balloon:
Parcourir les fichiers

reecriture de la structure de pile

parent cfba99cd
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
a.out
obj/*
test.c
stackchess
*.o
*.aux
*.log
*.out
*.toc
*.gz
Fichier ajouté
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Fichier ajouté
\documentclass[french]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[french]{babel}
\selectlanguage{french}
\usepackage{amsmath}
\usepackage{float}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{xcolor}
\usepackage{graphicx}
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
\author{Loïc DUBARD}
\title{Projet de programmation Impérative :\\ Stackchess}
\begin{document}
\maketitle
\tableofcontents
\clearpage
\section*{Introduction}
\section{Démarche générale}
\subsection{Présentation des structures de données principales utilisées ainsi que les différentes opérations implémentées sur ces structures}
\subsubsection*{Pile}
\end{document}
\ No newline at end of file
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
Aucun aperçu pour ce type de fichier
......@@ -16,7 +16,7 @@ void affiche_pile_a_cote(pile **tableau,char *sel,int x,int y,int N, int ligne,i
{
int k;
if (ligne == N-1) printf(" %s:",sel);
noeud* tmp=tableau[x][y].sommet;
pile tmp=tableau[x][y];
for (k=0 ; k<nb ; k++){
if (ligne==N-nb+k){
if (ligne != N-1) printf(" ");
......@@ -58,14 +58,14 @@ void affichetableau_pile_cote(pile **tableau, int N,char *sel)
if ((i+j)%2 == 1){
if (est_vide(tableau[i][j]))
printf(NOIR " " RESET);
else if (tableau[i][j].sommet->chaine[1] == 'N')
else if (tableau[i][j]->chaine[1] == 'N')
printf(PNOIRE NOIR "%c " RESET, *sommet(tableau[i][j]));
else
printf(PBLANCHE NOIR"%c " RESET, *sommet(tableau[i][j]));
} else {
if (est_vide(tableau[i][j]))
printf(BLANC " " RESET);
else if (tableau[i][j].sommet->chaine[1] == 'N')
else if (tableau[i][j]->chaine[1] == 'N')
printf(PNOIRE BLANC"%c " RESET, *sommet(tableau[i][j]));
else
printf(PBLANCHE BLANC"%c " RESET, *sommet(tableau[i][j]));
......
......@@ -48,7 +48,7 @@ void case_destination(pile **tableau,int N,int i_src,int j_src, int *i_dest,int
if (dest[1] != '\0'){
determiner_indices(dest,N,i_dest,j_dest);
if (*i_dest>=0 && *i_dest<N && *j_dest>=0 && *j_dest<N && nb>nb_de_pion(tableau[*i_dest][*j_dest],"BN"[(*tour+1)%2])){
noeud* tmp=tableau[i_src][j_src].sommet;
pile tmp=tableau[i_src][j_src];
int valide,i;
for (i=0 ; i<nb ; i++){
......
......@@ -13,39 +13,39 @@ pile **initialisation(int N)
for (i=0 ; i<N ; i++){
tableau[i] =(pile*)malloc(N*sizeof(pile));
for (j=0 ; j<N ; j++)
tableau[i][j].sommet = NULL;
tableau[i][j] = NULL;
}
return tableau;
}
int est_vide(pile p)
{
return p.sommet == NULL;
return p == NULL;
}
char *sommet(pile p)
{
if (!est_vide(p)) return p.sommet->chaine;
if (!est_vide(p)) return p->chaine;
else return "\0";
}
void empiler(pile *p, char *elt)
{
noeud* nouveau;
nouveau = (noeud*) malloc(sizeof(noeud));
pile nouveau;
nouveau = (pile) malloc(sizeof(struct _noeud));
nouveau->chaine = elt;
nouveau->next = p->sommet;
p->sommet = nouveau;
nouveau->next = *p;
*p = nouveau;
}
char *depiler(pile *p)
{
if (! est_vide(*p)){
char *elt;
elt = p->sommet->chaine;
noeud* tmp = p->sommet;
p->sommet = p->sommet->next;
elt = (*p)->chaine;
pile tmp = *p;
*p = (*p)->next;
free(tmp);
return elt;
}
......@@ -54,7 +54,7 @@ char *depiler(pile *p)
void reset(pile *p)
{
while (p->sommet)
while (! est_vide(*p))
/*termine lorsque p n'a plus de sommet à dépiler (car p est de longueur finie)*/
depiler(p);
}
......@@ -99,11 +99,10 @@ void debut_partie(pile **tableau, int N)
int longueur_pile(pile p)
{
int i=0;
noeud* tmp=p.sommet;
while (tmp != NULL){
while (p != NULL){
/*termine quand on arrive au bout de la pile qui est de longueur finie*/
i++;
tmp=tmp->next;
p=p->next;
}
return i;
}
......@@ -118,11 +117,10 @@ void determiner_indices(char *sel,int N,int *i,int *j)
int nb_de_pion(pile p,char couleur)
{
int i=0;
noeud* tmp=p.sommet;
while (tmp != NULL){
while (p != NULL){
/*termine car la pile est de longueur finie*/
if (tmp->chaine[1]==couleur) i++;
tmp=tmp->next;
if (p->chaine[1]==couleur) i++;
p=p->next;
}
return i;
}
......@@ -131,8 +129,8 @@ int nb_de_cavaliers(pile p,char couleur,int nb)
{
int i,k=0;
for (i=0 ; i<nb ; i++){
if (p.sommet->chaine[0] == 'C' && p.sommet->chaine[1]==couleur) k++;
p.sommet=p.sommet->next;
if (p->chaine[0] == 'C' && p->chaine[1]==couleur) k++;
p=p->next;
}
return k;
}
......@@ -158,12 +156,12 @@ int partie_finie(pile ** tableau,int N,int tour)
printf("On a un cas d'égalité !");
return 1;
}
noeud* tmp;
pile tmp;
if (k+l==4){
/*le cas il reste à chacun un fou et une tour*/
for (i=0 ; i<N ; i++){
for (j=0 ; j<N ; j++){
tmp=tableau[i][j].sommet;
tmp=tableau[i][j];
while (tmp != NULL){
if (tmp->chaine[0]=='T'){
if (tmp->chaine[1]=='B') toursb+=1;
......
......@@ -7,15 +7,10 @@
#include<string.h>
/*tableau.h*/
typedef struct _noeud noeud;
typedef struct _noeud * pile;
struct _noeud{
char *chaine;
noeud* next;
};
typedef struct _pile pile;
struct _pile{
noeud* sommet;
pile next;
};
/*
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter