#include #include #include typedef enum Vakje{ LEEG=0, WPION,WTOREN,WPAARD,WLOPER,WKONING,WKONGIN, ZPION,ZTOREN,ZPAARD,ZLOPER,ZKONING,ZKONGIN }Vakje; char characters[][5] = {".", "♟","♜","♞","♝","♛","♚", "🨣","🨠","🨢","🨡","🨟","🨞"}; Vakje Bord[] = { ZTOREN ,ZPAARD ,ZLOPER ,ZKONING,ZKONGIN,ZLOPER ,ZPAARD ,ZTOREN, ZPION ,ZPION ,ZPION ,ZPION ,ZPION ,ZPION ,ZPION ,ZPION, LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG, LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG, LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG, LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG ,LEEG, WPION ,WPION ,WPION ,WPION ,WPION ,WPION ,WPION ,WPION, WTOREN ,WPAARD ,WLOPER ,WKONING,WKONGIN,WLOPER ,WPAARD ,WTOREN }; #define ABS(z) z>0 ? z : -z void printBoard(){ printf(" "); for(int j=0; j<8; j++){ printf("%c ",'a'+j); } printf("\n"); for(int i=0; i<8; i++){ printf("%d ", i+1); for(int j=0; j<8; j++){ printf("%s ",characters[Bord[i*8+j]]); } printf("\n"); } } bool validBishopMovevment(int i1,int j1,int i2,int j2){ if( ABS(i1-i2) == ABS(j1-j2) && (i1!=i2 || j1!=j2) ){ int signJ = (j1 < j2)*2-1; int signI = (i1 < i2)*2-1; bool alEmpty=true; int n = ABS(i1-i2); for(int offset =1; offset WKONGIN || !beurt&& Bord[i1+j1*8]WKONGIN ){ printf("%s is not the right colour\n", strTo); continue; } int direction = 1-beurt*2; //Check, given the piece if the movement is valid switch(Bord[i1+j1*8]){ case(WPION): case(ZPION): if( j2-j1==direction && i1==i2 && Bord[i2+j2*8] == LEEG) break; if( j2-j1==direction && (i1-i2 == -1 || i1-i2 == 1) && Bord[i2+j2*8] != LEEG) break; printf("It is illegal to move a pion that way\n"); continue; case(WTOREN): case(ZTOREN): if(!validTowerMovement(i1,j1,i2,j2)){ printf("It is illegal to move a tower that way\n"); continue; } case(WPAARD): case(ZPAARD): if(ABS(i1-i2)==2 && ABS(j1-j2) ==1 || ABS(i1-i2)==1 && ABS(j1-j2) ==2){ break; } printf("It is illegal to move a horse that way\n"); continue; case(WKONING): case(ZKONING): if(ABS(i1-i2)<=1 && ABS(j1-j2)<=1 && (i1!=i2 || j1!=j2)){ break; } printf("It is illegal to move a king that way\n"); continue; case(WKONGIN): case(ZKONGIN): } //make move Bord[i2+j2*8] = Bord[i1+j1*8]; Bord[i1+j1*8]=LEEG; beurt = !beurt; } }