Exemple #1
0
int pat(Echiquier *E){
	int non_pat=1;
	int i,j;
	Position Pini;
	int available_move[LARGEUR][LARGEUR];
	int *ptr_available_move;
	ptr_available_move = (int *)available_move;
	if(!hunt_chess(E)){
		non_pat=0;
		for(i=0;i<LARGEUR;i++){
			for(j=0;j<LARGEUR;j++){
				enum joueur piece_color = convert_piececolor_to_joueur(E->t[i][j].c);
				if(piece_color==E->joueur){
					Pini = g(j,i);
					avail_moves[E->t[i][j].t](&Pini,E, ptr_available_move);
					if(!test_echec(ptr_available_move,E,i,j)){
						non_pat=1;
					}
				}
			}
		}
	}

	return !non_pat;
}
Exemple #2
0
int mat(Echiquier *E){
	int i,j,k,l;
	int r=1;
	int available_move[LARGEUR][LARGEUR];
	memset(*available_move, 0, sizeof(available_move));
	int *ptr_available_move;
	ptr_available_move = (int *)available_move;
	Position Pini, Pfin;
	Echiquier E_mat_test;

	if(!hunt_chess(E)){
		return 0;
	}
	enum joueur player = E->joueur;
	enum piececolor color;
	if(player == JOUEUR_NOIR){
		color = black;
	}
	else{
		color = white;
	}
	for(i=0;i<LARGEUR;i++){
		for(j=0;j<LARGEUR;j++){
			if(check_pieces_position(i, j, color, E)){
				Pini = g(j,i);
				avail_moves[E->t[i][j].t](&Pini,E, ptr_available_move);
				for(k=0;k<LARGEUR;k++){
					for(l=0;l<LARGEUR;l++){
						if(available_move[k][l]){
							Pfin = g(l,k);				
							E_mat_test = simulate_move(&Pini, &Pfin, E);
							if(!hunt_chess(&E_mat_test)){
								return 0;
							}
						}
					}
				}
				memset(*available_move, 0, sizeof(available_move));
			}
		}
	}
	return r;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    Echiquier B = E;
    double end_game;
    do{//loop to start a new game
    do{//loop to change player until mat

		term_clear(); // un peu mieux ;)

        print_game(&B);
        if(hunt_chess(&B)){
        printf("Vous etes en echec !\n");
        }
        move_piece(&B);
       /* printf("\n----------blacks_positions------------\n");
        print_binary_chess_table(B.blacks_position);
        printf("\n---------whites_position----------\n");
        print_binary_chess_table(B.whites_position);
        printf("\n");
        printf("a6 : %d, %d, (%d,%d), %d\n", B.t[2][0].t, B.t[2][0].c,B.t[2][0].p.posx,B.t[2][0].p.posy,B.t[2][0].m);
        getchar();*/
       //print_game(&B);

    }while(!mat(&B));
    char *player;
    switch (B.joueur){
        case JOUEUR_BLANC : player = "blanc";
        break;
        case JOUEUR_NOIR : player = "noir";
    }
	term_clear();

    print_game(&B);
    printf("\nJoueur %s, vous etes echec et mat !\n",player);
    getchar();
    B = E;
    do{
        printf("Souhaitez-vous refaire une partie ?\n1. Oui\n2. Non\n\n");
        scanf("%lf",&end_game);
        if(end_game != 1 && end_game != 2){
            printf("taper 1 ou 2.\n");
        }
    }while(end_game != 1 && end_game != 2);
    }while(end_game==1);
    return 0;
}
Exemple #4
0
int no_chess_castle(Position *Pini,Echiquier *E){
    Echiquier E_test = *E;
    int i,j,r = 0;
    i = Pini->posy;
    j = Pini->posx;
    if(E_test.joueur== JOUEUR_BLANC){
        E_test.white_king[i][j-3]=1;
        E_test.white_king[i][j-2]=1;
        E_test.white_king[i][j-1]=1;
    }
    else {
        E_test.black_king[i][j-3]=1;
        E_test.black_king[i][j-2]=1;
        E_test.black_king[i][j-1]=1;
    }
    if(hunt_chess(&E_test)){r = 1;}

    return r;
}
Exemple #5
0
int test_echec(int *available_move,Echiquier *E,int i,int j){
	int k,l;
	int counter_nb_chess=1;
	Echiquier E_test = *E;
	int all_move_make_chess;
	for(k=0;k<LARGEUR;k++){
		for(l=0;l<LARGEUR;l++){
			if(available_move[k*LARGEUR + l]){
				get_chess_after_move(i,j,k,l,E,&E_test);
				if(hunt_chess(&E_test)){
					counter_nb_chess=counter_nb_chess && 1;		
				}
				else{
					counter_nb_chess=0;
				}
			}
		}
	}
	all_move_make_chess=counter_nb_chess;
	return all_move_make_chess;
}