aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-04-10 21:19:09 +0300
committereug-vs <eugene@eug-vs.xyz>2022-04-10 21:19:09 +0300
commit5f583e476f3f711a581f417319670ee401a716c4 (patch)
tree18343ba76c1526d9c26e24452ccc68cdf53c2a1a
parent6c88febbe0cff8960bc6f2e0bcdfc89777a5f72b (diff)
downloadcarcassonne-engine-c-5f583e476f3f711a581f417319670ee401a716c4.tar.gz
feat: add meeple placement
-rw-r--r--src/board.c3
-rw-r--r--src/board.h1
-rw-r--r--src/main.c27
3 files changed, 23 insertions, 8 deletions
diff --git a/src/board.c b/src/board.c
index cc16e06..0e66f16 100644
--- a/src/board.c
+++ b/src/board.c
@@ -94,7 +94,6 @@ int evaluate_structure(int index, BoardUnit* board) {
char feature = board[index].feature;
int structure_group = board[index].structure_group;
- printf("Evaluating group %i (%c)\n", structure_group, feature);
for (int i = 0; i < BOARD_WIDTH; i++) {
for (int j = 0; j < BOARD_WIDTH; j++) {
@@ -102,7 +101,6 @@ int evaluate_structure(int index, BoardUnit* board) {
if (board[index].feature != EMPTY) { // Empty tiles doesn't count
for (int k = 0; k < 4; k++) {
if (board[index + NEIGHBOR_INCREMENTS[k]].structure_group == structure_group) {
- printf("Found at tile %i\n", i * BOARD_WIDTH + j);
value++;
break;
}
@@ -111,6 +109,5 @@ int evaluate_structure(int index, BoardUnit* board) {
}
}
- printf("Value: %i\n", value);
return value;
}
diff --git a/src/board.h b/src/board.h
index 4785871..a993680 100644
--- a/src/board.h
+++ b/src/board.h
@@ -1,6 +1,7 @@
#define BOARD_WIDTH 9
#define BOARD_ROW_UNITS ((BOARD_WIDTH * 2) + 1)
#define BOARD_UNITS BOARD_ROW_UNITS * BOARD_ROW_UNITS
+#define PLAYERS 2
/* constants */
diff --git a/src/main.c b/src/main.c
index ab5409e..5001ba6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,14 +56,10 @@ int main() {
/* main loop */
char input_key;
- while (1) {
+ for (int move = 0; ; move++) {
/* board */
refresh_structure_groups(board);
draw_board(board, board_win);
- if (wgetch(board_win) == 'q') {
- endwin();
- return 0;
- }
/* tile placement */
tile = tileset[rand() % 5];
@@ -90,11 +86,32 @@ int main() {
else if (input_key == 'j') position += BOARD_WIDTH;
else if (input_key == 'k') position -= BOARD_WIDTH;
else if (input_key == 'r') rotate_tile(&tile, 3);
+ else if (input_key == 'q') {
+ endwin();
+ return 0;
+ }
}
int result = place_tile(tile, translate_coordinate(position), board, 0);
if (result) wprintw(messages_win, "Placed tile %s (%c) at position %i\n", tile.edges, tile.center, position);
else wprintw(messages_win, "Could not place tile %s (%c) at position %i\n", tile.edges, tile.center, position);
+
+
+ /* meeple placement */
+ input_key = wgetch(board_win);
+ int meeple_index = translate_coordinate(position);
+
+ if (input_key == 'l') meeple_index += 1;
+ else if (input_key == 'h') meeple_index -= 1;
+ else if (input_key == 'j') meeple_index += BOARD_ROW_UNITS;
+ else if (input_key == 'k') meeple_index -= BOARD_ROW_UNITS;
+ else if (input_key != 10) meeple_index = -1;
+
+ if (meeple_index >= 0) {
+ board[meeple_index].meeple = move % PLAYERS;
+ wprintw(messages_win, "Placed meeple #%i at index %i\n", move % PLAYERS, meeple_index);
+ }
+
wrefresh(messages_win);
}