From 2e5c189444a82df0d9127c94322ec4e3b159dcce Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 25 Apr 2017 18:38:00 +0200 Subject: [PATCH] Fix to the const definition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- lib/constants.c | 22 ++++++++++++++++++++++ lib/constants.h | 8 +++++--- lib/othello.h | 6 ++++++ lib/ui.c | 32 ++++++++++++++++++++------------ lib/ui.h | 3 +++ src/main.c | 3 ++- 6 files changed, 58 insertions(+), 16 deletions(-) create mode 100644 lib/constants.c diff --git a/lib/constants.c b/lib/constants.c new file mode 100644 index 0000000..7559432 --- /dev/null +++ b/lib/constants.c @@ -0,0 +1,22 @@ +/* + * ===================================================================================== + * + * Filename: constants.h + * + * Description: Header for constant values + * + * Version: 1.0 + * Created: 24/04/2017 21:06:32 + * Revision: none + * Compiler: gcc + * + * Author: Jerome Benoit (fraggle), jerome.benoit@piment-noir.org + * Organization: Piment Noir + * + * ===================================================================================== + */ + +/* exported const definitions */ +const int empty = 0; +const int white = 1; +const int black = 2; diff --git a/lib/constants.h b/lib/constants.h index 74ea1d8..902489d 100644 --- a/lib/constants.h +++ b/lib/constants.h @@ -19,9 +19,11 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -const int empty = 0; -const int white = 1; -const int black = 2; +#define board_size 8 + +extern const int empty; +extern const int white; +extern const int black; #endif /* CONSTANTS_H */ diff --git a/lib/othello.h b/lib/othello.h index e590b02..7123697 100644 --- a/lib/othello.h +++ b/lib/othello.h @@ -19,4 +19,10 @@ #ifndef OTHELLO_H #define OTHELLO_H +#include "constants.h" + +int pawn[board_size][board_size] = { + {0, 0} +}; + #endif /* OTHELLO_H */ diff --git a/lib/ui.c b/lib/ui.c index c5f83b7..c786772 100644 --- a/lib/ui.c +++ b/lib/ui.c @@ -51,35 +51,43 @@ void print_board(int y, int x) { mvprintw(y+22, x, " -----+----+----+----+----+----+----+-----"); } -static void print_x(int y, int x, int type) { - - mvprintw(y, x, "\\/"); - mvprintw(y+1, x,"/\\"); -} - static void print_o(int y, int x, int type) { mvprintw(y, x, "/\\"); mvprintw(y+1, x, "\\/"); } -/* y = 1: y -> 0 x = 1: 1 -> 1 - * y > 2: y -> y + 3 2 -> +6 */ +/* will be used for pawn placement hints */ +static void print_x(int y, int x, int type) { + + mvprintw(y, x, "\\/"); + mvprintw(y+1, x,"/\\"); +} +/* 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 y + 3; + return (remap_y(y -1) + 3); } } static int remap_x(int x) { if (x == 1) { - return 1; - } else if (x > 2) { - return x + 5; + return x; + } else if (x > 1) { + return (remap_x(x - 1) + 5); + } +} + +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]); + } } } diff --git a/lib/ui.h b/lib/ui.h index 2915078..ad32628 100644 --- a/lib/ui.h +++ b/lib/ui.h @@ -19,8 +19,11 @@ #ifndef UI_H #define UI_H +#include "constants.h" + /* ncurses printing */ void print_board(int y, int x); +void print_pawns(int pawn_array[board_size][board_size]); /* non ncurses printing */ diff --git a/src/main.c b/src/main.c index ead55ef..7a327be 100644 --- a/src/main.c +++ b/src/main.c @@ -4,6 +4,7 @@ #include #include "ui.h" +#include "othello.h" int main() { int row = 0, col = 0; @@ -23,7 +24,7 @@ int main() { /* center the board */ int center_board_y = row/2 - 23/2; - int center_board_x = col/2 - 40/2; + int center_board_x = col/2 - 41/2; do { print_board(center_board_y, center_board_x); -- 2.34.1