This commit is contained in:
Maix0 2024-02-07 14:46:49 +01:00
parent adb8fc17b7
commit f98cc2c30e
13 changed files with 224 additions and 227 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 20:10:21 by maiboyer #+# #+# */
/* Updated: 2024/01/31 14:10:08 by maiboyer ### ########.fr */
/* Updated: 2024/02/02 22:48:02 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,18 +14,7 @@
#define BEST_MOVE_H
#include "app/state.h"
enum e_stack_selector
{
STACK_A,
STACK_B,
};
enum e_zero_position
{
MIN_ZERO_POS,
MAX_ZERO_POS,
};
#include "me/vec/vec_i64.h"
struct s_functions
{
@ -33,17 +22,20 @@ struct s_functions
void (*reverse)(void *);
};
typedef t_usize (*t_iter_pos_func)(t_vec_i64 *);
typedef struct s_best_move_args
{
enum e_stack_selector main_stack;
enum e_zero_position zero_pos;
void *args;
struct s_functions main;
struct s_functions other;
struct s_functions both;
t_iter_pos_func iter_func;
t_usize index;
t_vec_i64 *from;
t_vec_i64 *to;
void *args;
struct s_functions main;
struct s_functions other;
struct s_functions both;
} t_best_move_args;
void run_func_with_best_rotate_for_item(t_state *state, t_usize index,
t_best_move_args data);
void run_func_with_best_rotate_for_item(t_state *state, t_best_move_args data);
#endif /* BEST_MOVE_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 21:31:42 by maiboyer #+# #+# */
/* Updated: 2024/01/31 14:12:25 by maiboyer ### ########.fr */
/* Updated: 2024/02/02 22:47:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,23 +20,6 @@
#include "me/vec/vec_i64.h"
typedef void (*t_banana_func)(void *);
typedef t_usize (*t_iter_pos_func)(t_vec_i64 *);
enum e_best_move_stack_selector
{
MAIN,
OTHER,
BOTH,
};
typedef struct s_best_move_args_but_better
{
t_best_move_args data;
t_vec_i64 *main_stack;
t_vec_i64 *other_stack;
t_iter_pos_func iter_func;
} t_best_move_args_but_better;
static inline t_banana_func choose_func(struct s_functions *funcs,
t_rotation rotate)

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 19:00:18 by maiboyer #+# #+# */
/* Updated: 2024/01/29 19:27:19 by maiboyer ### ########.fr */
/* Updated: 2024/02/02 22:42:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,30 +22,33 @@ enum e_rotation_direction
};
typedef struct s_rotation
{
t_usize value;
t_usize ring_size;
t_usize value;
t_usize ring_size;
enum e_rotation_direction direction;
} t_rotation;
static inline t_rotation forward(t_usize by, t_usize ring_size)
{
return ((t_rotation){
.value = by % ring_size, .ring_size = ring_size, .direction = FORWARD});
.value = by, .ring_size = ring_size, .direction = FORWARD});
}
static inline t_rotation reverse(t_usize by, t_usize ring_size)
{
return ((t_rotation){
.value = by % ring_size, .ring_size = ring_size, .direction = REVERSE});
.value = by, .ring_size = ring_size, .direction = REVERSE});
}
static inline t_rotation flip(t_rotation rot)
{
enum e_rotation_direction flipped;
flipped = FORWARD;
if (rot.direction == FORWARD)
flipped = REVERSE;
else if (rot.direction == REVERSE)
flipped = FORWARD;
else
return (rot);
return ((t_rotation){.value = rot.ring_size - rot.value,
.ring_size = rot.ring_size,