yes
This commit is contained in:
parent
4d7255f105
commit
e0e790c230
14 changed files with 416 additions and 63 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 20:10:21 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 20:28:35 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/01/31 14:10:08 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,28 +15,32 @@
|
|||
|
||||
#include "app/state.h"
|
||||
|
||||
enum e_stack_selector {
|
||||
enum e_stack_selector
|
||||
{
|
||||
STACK_A,
|
||||
STACK_B,
|
||||
};
|
||||
|
||||
enum e_zero_position {
|
||||
enum e_zero_position
|
||||
{
|
||||
MIN_ZERO_POS,
|
||||
MAX_ZERO_POS,
|
||||
};
|
||||
|
||||
struct s_functions {
|
||||
struct s_functions
|
||||
{
|
||||
void (*forward)(void *);
|
||||
void (*reverse)(void *);
|
||||
};
|
||||
|
||||
typedef struct s_best_move_args {
|
||||
typedef struct s_best_move_args
|
||||
{
|
||||
enum e_stack_selector main_stack;
|
||||
enum e_zero_position zero_pos;
|
||||
void *function_arguments;
|
||||
struct s_functions main;
|
||||
struct s_functions other;
|
||||
struct s_functions both;
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/29 21:31:42 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 21:50:15 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/01/31 14:12:25 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -38,31 +38,13 @@ typedef struct s_best_move_args_but_better
|
|||
|
||||
} t_best_move_args_but_better;
|
||||
|
||||
static inline t_banana_func choose_rot(enum e_best_move_stack_selector ty,
|
||||
t_best_move_args_but_better *data,
|
||||
t_rotation *rot)
|
||||
static inline t_banana_func choose_func(struct s_functions *funcs,
|
||||
t_rotation rotate)
|
||||
{
|
||||
if (ty == MAIN)
|
||||
{
|
||||
if (rot->direction == FORWARD)
|
||||
return (data->data.main.forward);
|
||||
else
|
||||
return (data->data.main.reverse);
|
||||
}
|
||||
else if (ty == OTHER)
|
||||
{
|
||||
if (rot->direction == FORWARD)
|
||||
return (data->data.other.forward);
|
||||
else
|
||||
return (data->data.other.reverse);
|
||||
}
|
||||
else if (ty == BOTH)
|
||||
{
|
||||
if (rot->direction == FORWARD)
|
||||
return (data->data.both.forward);
|
||||
else
|
||||
return (data->data.both.reverse);
|
||||
}
|
||||
if (rotate.direction == FORWARD)
|
||||
return (funcs->forward);
|
||||
else if (rotate.direction == REVERSE)
|
||||
return (funcs->reverse);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
22
include/app/find_iter.h
Normal file
22
include/app/find_iter.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* find_iter.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:24:10 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:24:47 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FIND_ITER_H
|
||||
#define FIND_ITER_H
|
||||
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_i64.h"
|
||||
|
||||
t_usize min_iter_zero_pos(t_vec_i64 *vec);
|
||||
t_usize max_iter_zero_pos(t_vec_i64 *vec);
|
||||
|
||||
#endif /* FIND_ITER_H */
|
||||
24
include/app/iter_state.h
Normal file
24
include/app/iter_state.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* iter_state.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/31 14:19:06 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/31 14:19:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ITER_STATE_H
|
||||
#define ITER_STATE_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
typedef struct s_iter_state
|
||||
{
|
||||
t_usize pos;
|
||||
t_i64 elem;
|
||||
} t_iter_state;
|
||||
|
||||
#endif /* ITER_STATE_H */
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/01/11 14:27:25 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/01/29 22:15:52 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/01/31 15:09:44 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,4 +27,43 @@ typedef struct s_state
|
|||
t_state parses_arguments(t_usize count, t_str nums[]);
|
||||
void free_state(t_state state);
|
||||
|
||||
static inline void make_sorted_true_for_elem(t_state *s, t_i64 elem)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < s->sorted.len)
|
||||
{
|
||||
if (s->sorted.buffer[i].value == elem)
|
||||
{
|
||||
s->sorted.buffer[i].active = true;
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void make_sorted_true_from_stack(t_state *s, t_vec_i64 *stack)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < stack->len)
|
||||
{
|
||||
make_sorted_true_for_elem(s, stack->buffer[i++]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void make_sorted_all_false(t_state *s)
|
||||
{
|
||||
t_usize i;
|
||||
|
||||
i = 0;
|
||||
while (i < s->sorted.len)
|
||||
{
|
||||
s->sorted.buffer[i].active = false;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* STATE_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue