Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define QUEENMOVE(NEWCELL) if (!j) NEWCELL = 0; \
- else if (!NEWCELL) NEWCELL = 4; \
- else if (NEWCELL == 3) NEWCELL = 5;\
- else if (NEWCELL == 1) j = 0;
- int main() {
- // Correct Move.
- // after reading the statement: WTF!!!
- int k, q, n; // king, queen, new_queen.
- int i, j;
- while(scanf("%d%d%d", &k, &q, &n) != EOF) {
- int k_col = k%8, k_row = k/8;
- int q_col = q%8, q_row = q/8;
- int n_col = n%8, n_row = n/8;
- if (k == q)
- // given state is illegal.
- printf("Illegal state\n");
- else {
- unsigned char board[8][8] = {0};
- board[k_row][k_col] = 1;
- board[q_row][q_col] = 2;
- // places where king can move to:
- if (k_col != 0) board[k_row][k_col-1] = 3;
- if (k_col != 7) board[k_row][k_col+1] = 3;
- if (k_row != 0) board[k_row-1][k_col] = 3;
- if (k_row != 7) board[k_row+1][k_col] = 3;
- // places where queen is allowed move to:
- for (i = q_col+1, j = 1; i <= 7; i++) QUEENMOVE(board[q_row][i]);
- for (i = q_col-1, j = 1; i >= 0; i--) QUEENMOVE(board[q_row][i]);
- for (i = q_row+1, j = 1; i <= 7; i++) QUEENMOVE(board[i][q_col]);
- for (i = q_row-1, j = 1; i >= 0; i--) QUEENMOVE(board[i][q_col]);
- if (board[n_row][n_col] == 0 || board[n_row][n_col] == 1 || board[n_row][n_col] == 2 || board[n_row][n_col] == 3)
- printf("Illegal move\n");
- else if (board[n_row][n_col] == 5)
- // the move is legal, but not allowed (Graph 2).
- printf("Move not allowed\n");
- else {
- int counter = 0;
- if (k_col != 0 && !(k_col-1 == n_col || k_row == n_row)) counter++;
- if (k_col != 7 && !(k_col+1 == n_col || k_row == n_row)) counter++;
- if (k_row != 0 && !(k_row-1 == n_row || k_col == n_col)) counter++;
- if (k_row != 7 && !(k_row+1 == n_row || k_col == n_col)) counter++;
- if (counter)
- printf("Continue\n");
- else
- printf("Stop\n");
- }
- //DEBUG:
- // for (i = 0; i < 8; i++)
- // for (j = 0; j < 8; j++)
- // printf("%d%s", board[i][j], j == 7 ? "\n":" ");
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement