void copy_window_size(int *nlines, int *cols) { if (nlines) *nlines = get_li(); if (cols) *cols = get_co(); }
/* * term_space_erase: this can be used if term_CE_clear_to_eol() returns 1. * This will erase from x to the end of the screen uses space. Actually, it * doesn't reposition the cursor at all, so the cursor must be in the correct * spot at the beginning and you must move it back afterwards */ void term_space_erase(int x) { int i, cnt; cnt = get_co() - x; for (i = 0; i < cnt; i++) fputc(' ', term_fp); }
// Set the Board, Pawns, and determine if a winner is available. int main() { int board[9][8] = {0}, turn = 2, pawn[2] = {12}; set_defaults(board); while (Winner(pawn[1], pawn[2])) { print_board(board); get_co(board, turn, pawn); if (turn == 2) turn = 1; else turn = 2; } scanf("asd"); }
static char input_check_resized(void) { ScreenInputData *inputdata = screen_get_inputdata(get_current_screen()); int new_li = get_li(); int new_co = get_co(); if (inputdata->old_li == new_li && inputdata->old_co == new_co) return 0; /* resized? Keep it simple and reset everything */ inputdata->cursor_x = 0; inputdata->cursor_y = new_li - 1; inputdata->old_li = new_li; inputdata->old_co = new_co; inputdata->zone = new_co; if (inputdata->zone > WIDTH) inputdata->zone -= WIDTH; return 1; }
// Checkers Output function for creating a new state void get_co(int board[9][8], int turn, int pawn[2]) { int x[4]; getxyaz: if(turn == 1) printf("x's turn.\n"); else printf("o's turn.\n"); printf("Write XYAZ: \n"); scanf("%d %d %d %d", &x[1], &x[2], &x[3], &x[4]); if (board[x[1]][x[2]] == turn || board[x[1]][x[2]] == turn + 2) { if (turn == 1) { if (x[3] == x[1] + 1 && x[4] == x[2] + 1 || x[4] == x[2] - 1) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; int x2, y2; if (x[1] > x[3]) x2 = x[1] - 1; else x2 = x[3] - 1; if (x[2] > x[4]) y2 = x[2] - 1; else y2 = x[4] - 1; board[x2][y2] = 0; pawn[turn + 1]--; Is_King (x[3],x[4], board, turn); if (NextChainValid (board, x)) get_co (board, turn, pawn); } else { printf("Invalid move.\n"); goto getxyaz; } } else if (turn == 2) { if (x[3] == x[1] - 1 && x[4] == x[2] + 1 || x[4] == x[2] - 1) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; Is_King (x[3], x[4], board, turn); } else if (x[3] == x[1] - 2 && x[4] == x[2] + 2 || x[4] == x[2] - 2) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; int x2, y2; if (x[1] > x[3]) x2 = x[1] - 1; else x2 = x[3] - 1; if (x[2] > x[4]) y2 = x[2] - 1; else y2 = x[4] - 1; board[x2][y2] = 0; pawn[turn - 1]--; Is_King (x[3], x[4], board, turn); if (NextChainValid (board, x)) get_co (board, turn, pawn); } else { printf("Invalid move.\n"); goto getxyaz; } } else if (turn == 3) { if (x[3] == x[1] - 1 || x[3] == x[1] + 1 && x[4] == x[2] + 1 || x[4] == x[2] - 1) { board[x[1]][x[4]] = turn; Is_King (x[3], x[4], board, turn); } else if (x[3] == x[1] + 2 || x[3] == x[1] - 2 && x[4] == x[2] + 2|| x[4] == x[2] - 2) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; int x2, y2; if (x[1] > x[3]) x2 = x[1] - 1; else x2 = x[3] - 1; if (x[2] > x[4]) y2 = x[2] - 1; else y2 = x[4] - 1; board[x2][y2] = 0; pawn [turn - 1]--; Is_King (x[3], x[4], board, turn); if (NextChainValid (board, x)) get_co (board, turn, pawn); } else { printf("Invalid move.\n"); goto getxyaz; } } else if (turn == 4) { if (x[3] == x[1] - 1 && x[4] == x[2] + 1 || x[4] == x[2] - 1) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; Is_King (x[3], x[4], board, turn); } else if (x[3] == x[1] + 2 && x[4] == x[2] + 2 || x[4] == x[2] - 2) { board[x[1]][x[2]] = 0; board[x[3]][x[4]] = turn; int x2, y2; if (x[1] > x[3]) x2 = x[1] - 1; else x2 = x[3] - 1; if (x[2] > x[4]) y2 = x[2] - 1; else y2 = x[4] - 1; board[x2][y2] = 0; pawn[turn - 3]--; Is_King (x[3], x[4], board, turn); if (NextChainValid(board, x)) get_co (board, turn, pawn); } else { printf("Invalid move.\n"); goto getxyaz; } } } }