1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include <stdio.h>
#define ver 7
#define hor 7
#define taillepiece 3
#include <string.h>
void boardIn();
void boardOut();
struct echiquier
{
char piece[taillepiece];
};
struct echiquier tab[ver][hor];
/////////////////////////////////
main()
{
boardIn();
boardOut();
}
void boardIn()
{
int cptTab01, cptTab02;
// ajout des espaces pour remplir les cases vides du tableau
for(cptTab01=2; cptTab01<6; cptTab01++)
{
for (cptTab02=0; cptTab02<8; cptTab02++)
{
strcpy(tab[cptTab01][cptTab02].piece, " ");
}
}
// pièces noires
strcpy(tab[1][0].piece, "PB1");
strcpy(tab[1][1].piece, "PB2");
strcpy(tab[1][2].piece, "PB3");
strcpy(tab[1][3].piece, "PB4");
strcpy(tab[1][4].piece, "PB5");
strcpy(tab[1][5].piece, "PB6");
strcpy(tab[1][6].piece, "PB7");
strcpy(tab[1][7].piece, "PB8");
strcpy(tab[0][0].piece, "RB1");
strcpy(tab[0][1].piece, "kB1");
strcpy(tab[0][2].piece, "BB1");
strcpy(tab[0][3].piece, "QB ");
strcpy(tab[0][4].piece, "KB ");
strcpy(tab[0][5].piece, "BB2");
strcpy(tab[0][6].piece, "kB2");
strcpy(tab[0][7].piece, "RB2");
// pièces blanches
strcpy(tab[6][0].piece, "PW1");
strcpy(tab[6][1].piece, "PW2");
strcpy(tab[6][2].piece, "PW3");
strcpy(tab[6][3].piece, "PW4");
strcpy(tab[6][4].piece, "PW5");
strcpy(tab[6][5].piece, "PW6");
strcpy(tab[6][6].piece, "PW7");
strcpy(tab[6][7].piece, "PW8");
strcpy(tab[7][0].piece, "RW1");
strcpy(tab[7][1].piece, "kW1");
strcpy(tab[7][2].piece, "BW1");
strcpy(tab[7][3].piece, "QW ");
strcpy(tab[7][4].piece, "KW ");
strcpy(tab[7][5].piece, "BW2");
strcpy(tab[7][6].piece, "kW2");
strcpy(tab[7][7].piece, "RW2");
}
void boardOut() // construction et affichage du plateau (8 valeurs : 0 à 7)
{
int cptTab1;
int cptTab2;
int cptC;
int cpt3 ;
cpt3 = 8;
printf(" A B C D E F G H\n");
for(cptTab1=0 ; cptTab1<8 ; cptTab1++)
{
printf(" --- --- --- --- --- --- --- ---\n");
printf("%d |", cpt3);
cpt3--;
for(cptTab2=0 ; cptTab2<8 ; cptTab2++)
{
printf("%s|", tab[cptTab1][cptTab2]);
}
printf("\n");
}
printf(" --- --- --- --- --- --- --- ---\n");
} |
Partager