-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
806 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef GUI_INTERFACE_BIGGEST_RECTANGLE_H | ||
#define GUI_INTERFACE_BIGGEST_RECTANGLE_H | ||
|
||
#include <stdlib.h> | ||
|
||
#include <structures/concrete/board.h> | ||
|
||
struct nk_rect_array { | ||
struct nk_rect * elements; | ||
size_t size; | ||
}; | ||
|
||
struct nk_rect_array create_max_overlap_rectangles (board_s board); | ||
void destroy_max_overlap_rectangles(struct nk_rect_array * array); | ||
|
||
#endif //GUI_INTERFACE_BIGGEST_RECTANGLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef GUI_INTERFACE_GRID_H | ||
#define GUI_INTERFACE_GRID_H | ||
|
||
#define NK_INCLUDE_FIXED_TYPES | ||
#define NK_INCLUDE_STANDARD_IO | ||
#define NK_INCLUDE_STANDARD_VARARGS | ||
#define NK_INCLUDE_DEFAULT_ALLOCATOR | ||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT | ||
#define NK_INCLUDE_FONT_BAKING | ||
#define NK_INCLUDE_DEFAULT_FONT | ||
#define NK_KEYSTATE_BASED_INPUT | ||
#include <nuklear.h> | ||
|
||
#include <structures/concrete/board.h> | ||
|
||
void grid(struct nk_context * context, board_s board); | ||
|
||
#endif //GUI_INTERFACE_GRID_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef GUI_INTERFACE_H | ||
#define GUI_INTERFACE_H | ||
|
||
#include <gui/default.h> | ||
|
||
void interface(struct nk_super * super); | ||
|
||
#endif /* GUI_INTERFACE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef GUI_INTERFACE_SOLVER_H | ||
#define GUI_INTERFACE_SOLVER_H | ||
|
||
#include <gui/default.h> | ||
|
||
#include <structures/concrete/state.h> | ||
|
||
typedef enum ds_action { | ||
CREATE_DS, DESTROY_DS, NEXT_VALUE_DS, NEXT_VALUE_TIMED_DS, | ||
PREV_VALUE_DS, RESET_DS, CURRENT_VALUE_DS, PREV_VALUE_TIMED_DS, | ||
START_VALUE_DS, END_VALUE_DS, | ||
} ds_action_e; | ||
|
||
#define IS_PLAY 1 | ||
|
||
typedef enum player_state { | ||
PLAY_FORWARDS_E = 0b00 | IS_PLAY, | ||
PLAY_BACKWARDS_E = 0b10 | IS_PLAY, | ||
|
||
STOP_UNSET_E = 0b00 << 1, | ||
STOP_START_E = 0b01 << 1, | ||
STOP_MIDDLE_E = 0b10 << 1, | ||
STOP_END_E = 0b11 << 1, | ||
} player_state_e; | ||
|
||
typedef enum solver_state { | ||
SOLVE_UNSET_E, SOLVE_RUNNING_E, SOLVE_FINISHED_E, | ||
} solver_state_e; | ||
|
||
typedef struct player { | ||
player_state_e play_state; | ||
solver_state_e solve_state; | ||
} player_s; | ||
|
||
player_s * get_player_singleton(void); | ||
void solve(struct nk_solver * data); | ||
state_array_s state_provider(const ds_action_e action); | ||
|
||
#endif /* GUI_INTERFACE_SOLVER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <gui/interface/biggest_rectangle.h> | ||
|
||
#include <stdbool.h> | ||
|
||
#define NK_INCLUDE_FIXED_TYPES | ||
#define NK_INCLUDE_STANDARD_IO | ||
#define NK_INCLUDE_STANDARD_VARARGS | ||
#define NK_INCLUDE_DEFAULT_ALLOCATOR | ||
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT | ||
#define NK_INCLUDE_FONT_BAKING | ||
#define NK_INCLUDE_DEFAULT_FONT | ||
#define NK_KEYSTATE_BASED_INPUT | ||
#include <nuklear.h> | ||
#include <nuklear_glfw_gl3.h> | ||
|
||
#define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
#define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
|
||
bool _is_inner_rectangle(struct nk_rect inner, struct nk_rect outer); | ||
bool _is_outer_rectangle(struct nk_rect inner, struct nk_rect outer); | ||
bool _replace_max_rectangle(struct nk_rect_array * array, struct nk_rect guess); | ||
|
||
struct nk_rect_array create_max_overlap_rectangles(board_s board) { | ||
ulookup_t row_size = board.game.size[ROW_E], col_size = board.game.size[COLUMN_E]; | ||
size_t * matrix_row = calloc(col_size, sizeof(size_t)); | ||
|
||
struct nk_rect_array array = { | ||
.elements = malloc((((row_size * col_size) / 2) + 1) * sizeof(struct nk_rect)), | ||
.size = 0, | ||
}; | ||
|
||
for (size_t r = 0; r < row_size; r++) { | ||
for (size_t c = 0; c < col_size; c++) { | ||
matrix_row[c] = board.grid[r][c] == -1 ? matrix_row[c] + 1 : 0; | ||
} | ||
|
||
for (size_t c = 0; c < col_size; c++) { | ||
if (matrix_row[c] == 0) continue; | ||
float height = matrix_row[c], width = 0, x = c; | ||
|
||
while (matrix_row[c] != 0 && c < col_size) { | ||
height = MIN(height, matrix_row[c]); | ||
width++; | ||
c++; | ||
} | ||
|
||
struct nk_rect temp = { .x = x, .y = r - (height - 1), .w = width, .h = height, }; | ||
if (!_replace_max_rectangle(&array, temp)) array.elements[array.size++] = temp; | ||
} | ||
|
||
for (size_t c = 0; c < col_size; c++) { | ||
if (matrix_row[c] == 0) continue; | ||
struct nk_rect temp = { .x = c, .y = r - (matrix_row[c] - 1), .w = 1, .h = matrix_row[c], }; | ||
if (!_replace_max_rectangle(&array, temp)) array.elements[array.size++] = temp; | ||
} | ||
} | ||
|
||
return array; | ||
} | ||
|
||
void destroy_max_overlap_rectangles(struct nk_rect_array * array) { | ||
free(array->elements); | ||
array->elements = NULL; | ||
array->size = 0; | ||
} | ||
|
||
bool _is_inner_rectangle(struct nk_rect inner, struct nk_rect outer) { | ||
return | ||
(inner.x >= outer.x) && (inner.y >= outer.y) && | ||
((inner.w + inner.x) <= (outer.w + outer.x)) && | ||
((inner.h + inner.y) <= (outer.h + outer.y)); | ||
} | ||
|
||
bool _is_outer_rectangle(struct nk_rect inner, struct nk_rect outer) { | ||
return _is_inner_rectangle(outer, inner); | ||
} | ||
|
||
bool _replace_max_rectangle(struct nk_rect_array * array, struct nk_rect guess) { | ||
bool replaced = false; | ||
for (size_t s = 0; s < array->size; s++) { | ||
if (_is_inner_rectangle(array->elements[s], guess)) { | ||
array->elements[s] = guess; | ||
replaced = true; | ||
} | ||
if (_is_outer_rectangle(array->elements[s], guess)) replaced = true; | ||
} | ||
|
||
return replaced; | ||
} |
Oops, something went wrong.