示例#1
4
//check
void check(){
	int t1=0,t2=0,i,j,x1,y1,z1=0,z2=0;
	checkm arr[30];
		for(i=0;i<=7;i++){
			for(j=0;j<=7;j++){
				if(board[i][j]==-5){
					y1=i;
					x1=j;
					break;
				}
			}
		}
		for(j=0;j<=7;j++){
			for(i=0;i<=7;i++){
				if (t1==1){
				}
				if(board[j][i]>=9 && board[j][i]<=16){
					flipturn();
					t1 = pawn(j,i,y1,x1);flipturn();
		//add position of pawn to a list
					if(t1==1){
						arr[z1].y=j;arr[z1].x=i;arr[z1].piece=board[j][i];z1++;
					}
				}
				else if(board[j][i]==2 || board[j][i]==7){
					t1 = horse(j,i,y1,x1);
					if(t1==1){
					arr[z1].y=j;arr[z1].x=i;arr[z1].piece=board[j][i];z1++;
					}
				}
				else if(board[j][i]==4){
					t1 = queen(j,i,y1,x1);
					if(t1==1){
					arr[z1].y=j;arr[z1].x=i;arr[z1].piece=board[j][i];z1++;
					}
				}
				else if(board[j][i]==1 || board[j][i]==8){
					t1 = rook(j,i,y1,x1);
					if(t1==1){
						arr[z1].y=j;arr[z1].x=i;arr[z1].piece=board[j][i];z1++;
					}
				}
				else if(board[j][i]==3 || board[j][i]==6){
					t1 = bishop(j,i,y1,x1);
					if(t1==1){
						arr[z1].y=j;arr[z1].x=i;arr[z1].piece=board[j][i];z1++;
					}
				}
			 }
		}
		if(z1!=0){
			mvwprintw(chessboard,1,25,"Player 1 in CHECK");wrefresh(chessboard);
			if(turn!=0)
				checkmate(y1,x1,&arr,z1);
			else{
				mvwprintw(chessboard,2,30,"                   ");wrefresh(chessboard);
			}
		}
		z2=0;
		for(i=0;i<=7;i++){	
			for(j=0;j<=7;j++){
				if(board[i][j]==5){
					y1=i;
					x1=j;
					break;
				}
			}
		}	
		for(j=0;j<=7;j++){
			for(i=0;i<=7;i++){
				if (t2==1){	
				}
				if(board[j][i]>=(-9) && board[j][i]<=(-16)){
					flipturn();
					t2 = pawn(j,i,y1,x1);flipturn();
					if(t2==1){
							arr[z2].y=j;arr[z2].x=i;arr[z2].piece=board[j][i];z2++;
					}
				}
				else if(board[j][i]==(-2) || board[j][i]==(-7)){
					t2= horse(j,i,y1,x1);
					if(t2==1){
						arr[z2].y=j;arr[z2].x=i;arr[z2].piece=board[j][i];z2++;
					}
				}
				else if(board[j][i]==(-4)){
					t2 = queen(j,i,y1,x1);
					if(t2==1){
						arr[z2].y=j;arr[z2].x=i;arr[z2].piece=board[j][i];z2++;
					}
				}
				else if(board[j][i]==(-1) || board[j][i]==(-8)){
					t2 = rook(j,i,y1,x1);
					if(t2==1){
						arr[z2].y=j;arr[z2].x=i;arr[z2].piece=board[j][i];z2++;
					}
				}
				else if(board[j][i]==(-3) || board[j][i]==(-6)){
					t2 = bishop(j,i,y1,x1);
					if(t2==1){
						arr[z2].y=j;arr[z2].x=i;arr[z2].piece=board[j][i];z2++;
					}
				} 
			}
		}
		wrefresh(chessboard);
		if(z2!=0){	
			mvwprintw(chessboard,1,25,"Player 2 in CHECK");wrefresh(chessboard);
			if(turn==0)
				checkmate(y1,x1,&arr,z2);
			else{
				mvwprintw(chessboard,2,30,"                   ");wrefresh(chessboard);
			}
		}
		if(z1==0&&z2==0) 
			mvwprintw(chessboard,2,25,"                 ");wrefresh(chessboard);
}
示例#2
0
文件: chess.c 项目: pkova/noobchess
    void pturn() {

        while (true) {


            if (checkmate() == 1) {
                printf("Checkmate!");
                break;
            }


            if (checkcheck(-1, -1))
                printf("Check!\n");

            char *boardchk[8][8];

            memcpy(boardchk, board, sizeof(board));
            
            boardprint();
            char move[10];
            printf("Please type a move in standard chess notation: ");
            scanf("%s", move);
            turn(move);

            if (checkcheck(-1, -1)) {
                memcpy(board, boardchk, sizeof(board));
                printf("Can not move into check!\n");
            }


            if (memcmp(board, boardchk, sizeof(board)) != 0)
                (wturn == 1) ? (wturn = 0) : (wturn = 1);


        }
    }