Jeu puissance 4 coder en C qui plante des le lancement o_O help^^
ElendilAranwe
Messages postés10Date d'inscriptionmercredi 30 décembre 2009StatutMembreDernière intervention27 avril 2010
-
30 déc. 2009 à 21:20
ElendilAranwe
Messages postés10Date d'inscriptionmercredi 30 décembre 2009StatutMembreDernière intervention27 avril 2010
-
31 déc. 2009 à 11:55
Bonjour comme dis dans le titre, j'ai crée le puissance 4 et coder celui-ci en C++ et il plante dès le démarrage ce qui est très frustrant vous pouvez l'imaginer^^, des heures passer a le coder et as la fin un superbe résultat:
Thread stopped
C:\Users\RaNdoM_PoWneD\Desktop\puissance4 non fonctionnel\progi.exe:
Fault: access violation at 0x14442e:
read of addess 0xeefface
Si vous pourriez m'aider je vous en serait très reconnaissant^^' j'ai chercher pas mal de temps d'ou viens le problème mais sans resultats :'(.
Je suis débutant, je programme depuis le debut de l'année scolaire BTS IRIS 1ere année.
merci
PS: si vous voyez des normes pas respecter ou quoi se serait sympa de me les notifier, c'est grace aux remarques constructives qu'on avance!!
enfin je crois :D
/*******************************************************************************
********************************************************************************
*************************** PUISSANCE 4 ****************************************
********************************************************************************
*******************************************************************************/
/* Consignes pré-processeurs */
#include <stdio.h>
#include <stdlib.h>
#include
/* Prototype des fonctions */
void initialisertabJeu( char tabJeu[8][8] );
void demandeJetonetverif( int* jetonJoueur , char tabJeu[8][8] );
int verificationPlacement( int jetonJoueur , char tabJeu[8][8] );
void placerJetonJoueur( int jetonJoueur , char tabJeu[8][8] );
int verificationVictoire( char tabJeu[8][8] );
void affichertabJeu( char tabJeu[8][8] );
void creationJetonetverif( int* jetonIA , char tabJeu[8][8] );
void placerJetonIA( int jetonIA , char tabJeu[8][8] );
/************************** programme principal *******************************/
void main( )
{
char tabJeu[8][8];
int jetonJoueur = 0;
int jetonIA = 0;
int verif = 0;
int victoire = 0;
initialisertabJeu( tabJeu );
printf( "initialisertabJeu OK " );
system("pause");
affichertabJeu( tabJeu );
printf( "affichertabJeu OK " );
system("pause");
/*************** Joueur ***************/
while( victoire != 1 )
{
demandeJetonetverif( &jetonJoueur , tabJeu );
placerJetonJoueur( jetonJoueur , tabJeu );
affichertabJeu( tabJeu );
verif = verificationVictoire( tabJeu );
if( verif == 0 )
{
printf( " VICTOIRE DE L'IA \r\n\r\n " );
victoire = 1;
}
else
if( verif == 1 )
{
printf( " VICTOIRE /clap /clap ^^ \r\n\r\n" );
victoire = 1;
}
/******************** IA **************************/
if( victoire != 1 )
{
creationJetonetverif( &jetonIA , tabJeu );
placerJetonIA( jetonIA , tabJeu );
verif = verificationVictoire( tabJeu );
if( verif == 0 )
{
printf( " VICTOIRE DE L'IA \r\n\r\n " );
victoire = 1;
}
else
if( verif == 1 )
{
printf( " VICTOIRE /clap /clap ^^ \r\n\r\n" );
victoire = 1;
}
}
}
}
/*************************** FIN MAIN *****************************************/
// initialise la table de jeu avec le caractère '.'
void initialisertabJeu( char tabJeu[8][8] )
{
int indice;
int indice2;
for( indice = 0 ; indice != 8 ; indice++ )
{
for( indice2 = 0 ; indice2 != 8 ; indice++ )
{
tabJeu[ indice ][ indice2 ] = '.';
}
}
}
// affiche la table de jeu sur la fenêtre console
void affichertabJeu( char tabJeu[8][8] )
{
int indice;
int indice2;
printf("01234567\r\n");
for( indice = 0 ; indice != 8 ; indice++ )
{
for( indice2 = 0 ; indice2 != 8 ; indice++ )
{
printf( "%c", tabJeu[ indice2 ][ indice ] );
}
printf("\r\n");
}
}
// demande ou le joueur vut mettre son jeton et vérifie si cela est posible
void demandeJetonetverif( int* jetonJoueur , char tabJeu[8][8] )
{
int verif = NULL ;
printf( "veuillez indiquer une ligne entre 0 et 7 pour y faire glisser un jeton : ");
scanf( "%d" , jetonJoueur );
printf( "\r\n\r\n");
verif = verificationPlacement( *jetonJoueur , tabJeu );
while( verif == -1 )
{
verif = 0;
printf( "erreur veuillez entrer un autre numéro de ligne ou signaler un bug: ");
scanf( "%d" , jetonJoueur );
printf( "\r\n\r\n");
verif = verificationPlacement( *jetonJoueur , tabJeu );
}
}
//verifie si positionner le jeton du joueur est poissible
int verificationPlacement( int jetonJoueur , char tabJeu[8][8] )
{
if( ( tabJeu[ jetonJoueur ][ 0 ] ) != '.' )
{
return -1;
}
if( ( jetonJoueur < 0 ) || ( jetonJoueur > 7 ) )
{
return -1;
}
return 1;
}
// place le jeton du joueur
void placerJetonJoueur( int jetonJoueur , char tabJeu[8][8] )
{
int placement;
int indice;
for( indice = 8 ; indice < 0 ; indice-- )
{
if ( ( tabJeu[ jetonJoueur ][ indice-1 ] ) == '.' )
{
placement = ( indice - 1 ) ;
indice = 1 ;
}
}
tabJeu[ jetonJoueur ][ placement ] = 'O' ;
}
int verificationVictoire( char tabJeu[8][8] )
{
int indice;
int indice2;
int indice3;
int verif;
verif = 0;
// vérifie s'il y a quatres jetons positionner d'affilé en horizontal
for( indice3 = 0 ; indice3 != 5 ; indice3++ )
{
for( indice = 0 ; indice != 4 ; indice++ )
{
for( indice2 = 0 ; indice2 != 8 ; indice2++ )
{
verif = tabJeu[ indice + indice3 ][ indice2 ] + verif;
}
}
if ( verif == ( 'O' + 'O' + 'O' + 'O' ) )
{
return 1; // victoire du joueur
}
if ( verif == ( 'X' + 'X' + 'X' +'X' ) )
{
return 0; // victoire de l'IA
}
verif = 0;
}
// vérifie s'il y a quatres jetons positionner d'affilé en vertical
for( indice3 = 0 ; indice3 != 5 ; indice3++ )
{
for( indice = 0 ; indice != 4 ; indice++ )
{
for( indice2 = 0 ; indice2 != 8 ; indice2++ )
{
verif = tabJeu[ indice2 ][ indice + indice3 ] + verif;
}
}
if ( verif == ( 'O' + 'O' + 'O' + 'O' ) )
{
return 1; // victoire du joueur
}
if ( verif == ( 'X' + 'X' + 'X' +'X' ) )
{
return 0; // victoire de l'IA
}
verif = 0;
}
/* vérifie s'il y a quatres jetons positionner d'affilé en diagonal -
-
-
- */
for( indice = 0 ; indice != 4 ; indice++ )
{
for( indice2 = 0 ; indice2 != 4 ; indice2++ )
{
for( indice3 = 0 ; indice3 != 4 ; indice3++ )
{
verif = tabJeu[ indice + indice3 ][ indice2 + indice3 ] + verif ;
}
if ( verif == ( 'O' + 'O' + 'O' + 'O' ) )
{
return 1; // victoire du joueur
}
if ( verif == ( 'X' + 'X' + 'X' +'X' ) )
{
return 0; // victoire de l'IA
}
verif = 0;
}
}
/* vérifie s'il y a quatres jetons positionner d'affilé en diagonal -
-
-
- */
for( indice = 3 ; indice != 8 ; indice++ )
{
for( indice2 = 0 ; indice2 != 4 ; indice2++ )
{
for( indice3 = 0 ; indice3 != 4 ; indice3++ )
{
verif = tabJeu[ indice - indice3 ][ indice2 + indice3 ] + verif ;
}
if ( verif == ( 'O' + 'O' + 'O' + 'O' ) )
{
return 1; // victoire du joueur
}
if ( verif == ( 'X' + 'X' + 'X' +'X' ) )
{
return 0; // victoire de l'IA
}
verif = 0;
}
}
return -1; // pas de victoire
}
// crée le jeton de l'IA et vérifie s'il est possible de le positionner
void creationJetonetverif( int* jetonIA , char tabJeu[8][8] )
{
int verif = NULL ;
printf( "L'IA Réfléchis.... ");
printf( "\r\n\r\n");
*jetonIA = random( 8 );
verif = verificationPlacement( *jetonIA , tabJeu );
while( verif == -1 )
{
verif = 0;
*jetonIA = random( 8 );
verif = verificationPlacement( *jetonIA , tabJeu );
}
}
// place le jeton de l'IA
void placerJetonIA( int jetonIA , char tabJeu[8][8] )
{
int placement;
int indice;
for( indice = 8 ; indice < 0 ; indice-- )
{
if ( ( tabJeu[ jetonIA ][ indice-1 ] ) == '.' ) // si il n'y as pas de jeton à l'emplacement indiqué sauvegarder l'emplacement
{
placement = ( indice - 1 ) ;
indice = 1 ;
}
}
tabJeu[ jetonIA][ placement ] = 'X' ; // met un jeton à l'emplacement sauvegarder précedemment
}