* =====================================================================================
*/
-#include <ncurses.h>
+#include <string.h>
#include "ui.h"
mvprintw(y+14, x, "5| | | | | | | | |");
mvprintw(y+15, x, " | | | | | | | | |");
mvprintw(y+16, x, " +----+----+----+----+----+----+----+----+");
- mvprintw(y+17, x, "7| | | | | | | | |");
+ mvprintw(y+17, x, "6| | | | | | | | |");
mvprintw(y+18, x, " | | | | | | | | |");
mvprintw(y+19, x, " +----+----+----+----+----+----+----+----+");
- mvprintw(y+20, x, "8| | | | | | | | |");
+ mvprintw(y+20, x, "7| | | | | | | | |");
mvprintw(y+21, x, " | | | | | | | | |");
- mvprintw(y+22, x, " -----+----+----+----+----+----+----+-----");
+ mvprintw(y+22, x, " +----+----+----+----+----+----+----+----+");
+ mvprintw(y+23, x, "8| | | | | | | | |");
+ mvprintw(y+24, x, " | | | | | | | | |");
+ mvprintw(y+25, x, " -----+----+----+----+----+----+----+-----");
}
-static void print_o(int y, int x, int type) {
+static void print_o(int y, int x, unsigned int type) {
+ if (type == black) {
+ init_color(COLOR_CYAN, 0, 0, 0); /* redefine to a dark black color */
+ init_pair(2, COLOR_WHITE, COLOR_CYAN);
+ attron(COLOR_PAIR(2));
+ } else {
+ init_pair(3, COLOR_BLACK, COLOR_WHITE);
+ attron(COLOR_PAIR(3));
+ }
mvprintw(y, x, "/\\");
mvprintw(y+1, x, "\\/");
+ /* reset to default */
+ init_pair(1, COLOR_WHITE, COLOR_BLACK);
+ attron(COLOR_PAIR(1));
}
/* will be used for pawn placement hints */
-static void print_x(int y, int x, int type) {
+static void print_x(int y, int x, unsigned int type) {
+ if (type == hint_allowed) {
+ init_pair(4, COLOR_GREEN, COLOR_BLACK);
+ attron(COLOR_PAIR(4));
+ } else {
+ init_pair(5, COLOR_RED, COLOR_BLACK);
+ attron(COLOR_PAIR(5));
+ }
mvprintw(y, x, "\\/");
mvprintw(y+1, x,"/\\");
+ /* reset to default */
+ init_pair(1, COLOR_WHITE, COLOR_BLACK);
+ attron(COLOR_PAIR(1));
}
/* y = 1: y -> 0 x = 1: 1 -> 1
* y > 1: y -> y + 3 x > 1: x -> x + 5 */
static int remap_y(int y) {
-
+
if (y == 1) {
- return 0;
- } else if (y > 1) {
- return (remap_y(y -1) + 3);
+ return 2;
+ } else if (y > 1 && y < board_size + 1) {
+ return (remap_y(y - 1) + 3);
}
+ return -1;
}
static int remap_x(int x) {
if (x == 1) {
- return x;
- } else if (x > 1) {
+ return 3;
+ } else if (x > 1 && x < board_size + 1) {
return (remap_x(x - 1) + 5);
}
+ return -1;
}
-void print_pawns(int pawn_array[board_size][board_size]) {
- for (int i = 0; i < board_size; i++) {
- for (int j = 0; j < board_size; j++) {
- //mvprintw(i, j, "pawn[%d][%d] = %d\n", i, j, pawn_array[i][j]);
+void print_pawns(int base_y, int base_x, unsigned int pawn_array[board_size][board_size]) {
+ for (unsigned int i = 0; i < board_size; i++) {
+ for (unsigned int j = 0; j < board_size; j++) {
+ if (pawn_array[i][j] != empty) {
+ print_o(base_y + remap_y(i), base_x + remap_x(j), pawn_array[i][j]);
+ }
}
}
}
+
+int map_col_letter_to_int(char c) {
+
+ if (c == 'a' || c == 'A') {
+ return 1;
+ } else if (c == 'b' || c == 'B') {
+ return 2;
+ } else if (c == 'c' || c == 'C') {
+ return 3;
+ } else if (c == 'd' || c == 'D') {
+ return 4;
+ } else if (c == 'e' || c == 'E') {
+ return 5;
+ } else if (c == 'f' || c == 'F') {
+ return 6;
+ } else if (c == 'g' || c == 'G') {
+ return 7;
+ } else if (c == 'h' || c == 'H') {
+ return 8;
+ }
+ return -1;
+}
+
+int prompt_values(WINDOW* windows, int base_y, int base_x, const char* msg, int* y, char* x) {
+ mvwprintw(windows, base_y, base_x, "%s\n", msg);
+ int retVal = mvwscanw(windows, base_y + 1, base_x, "%d%c", y, x);
+ return (retVal == 1) ? 0 : 1;
+}