update...

This commit is contained in:
Maieul BOYER 2024-01-29 22:45:54 +01:00
parent 63d62aec4d
commit 4d7255f105
No known key found for this signature in database
26 changed files with 518 additions and 641 deletions

45
include/app/best_move.h Normal file
View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* best_move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef BEST_MOVE_H
#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,
};
struct s_functions {
void (*forward)(void *);
void (*reverse)(void *);
};
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;
} t_best_move_args;
void run_func_with_best_rotate_for_item(t_state *state, t_usize index,
t_best_move_args data);
#endif /* BEST_MOVE_H */

View file

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* best_move_inner.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef BEST_MOVE_INNER_H
#define BEST_MOVE_INNER_H
#include "app/best_move.h"
#include "app/rotate.h"
#include "app/state.h"
#include "me/types.h"
#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_rot(enum e_best_move_stack_selector ty,
t_best_move_args_but_better *data,
t_rotation *rot)
{
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);
}
return (NULL);
}
#endif /* BEST_MOVE_INNER_H */

View file

@ -13,7 +13,7 @@
#ifndef COST_H
# define COST_H
# include "app/element.h"
# include "app/state.h"
# include "app/types/type_cost.h"
# include "me/types.h"

View file

@ -13,12 +13,12 @@
#ifndef DUP_STATE_H
# define DUP_STATE_H
# include "app/element.h"
# include "me/types.h"
typedef struct s_dup_state
{
t_element *lhs;
t_i64 *lhs;
t_usize index_to_skip;
bool found_dup;
} t_dup_state;

29
include/app/find_place.h Normal file
View file

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* find_place.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 22:00:27 by maiboyer #+# #+# */
/* Updated: 2024/01/29 22:15:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FIND_PLACE_H
#define FIND_PLACE_H
#include "app/state.h"
#include "me/types.h"
typedef struct s_find_place_iter_state
{
t_usize current_index;
t_usize found_index;
t_i64 to_find_elem;
} t_find_place_iter_state;
t_usize find_place(t_i64 elem, t_state *state);
#endif /* FIND_PLACE_H */

View file

@ -14,9 +14,9 @@
# define LIS_H
# include "me/types.h"
# include "me/vec/vec_element.h"
# include "me/vec/vec_i64.h"
# include "me/vec/vec_i64.h"
t_vec_i64 lis(t_vec_element *elements);
t_vec_i64 lis(t_vec_i64 *elements);
#endif /* LIS_H */

View file

@ -6,18 +6,19 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 16:13:08 by maiboyer #+# #+# */
/* Updated: 2024/01/12 21:27:27 by maiboyer ### ########.fr */
/* Updated: 2024/01/29 19:07:15 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef MOVES_H
# define MOVES_H
# include "app/element.h"
# include "app/state.h"
# include "app/types/type_move.h"
# include "me/types.h"
void do_move(t_move m, t_state *s);
void do_move(t_move m, t_state *s);
t_const_str get_str_for_move(t_move m);
#endif /* MOVES_H */

55
include/app/rotate.h Normal file
View file

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* rotate.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef ROTATE_H
#define ROTATE_H
#include "me/types.h"
enum e_rotation_direction
{
FORWARD,
REVERSE,
};
typedef struct s_rotation
{
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});
}
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});
}
static inline t_rotation flip(t_rotation rot)
{
enum e_rotation_direction flipped;
flipped = FORWARD;
if (rot.direction == FORWARD)
flipped = REVERSE;
return ((t_rotation){.value = rot.ring_size - rot.value,
.ring_size = rot.ring_size,
.direction = flipped});
}
#endif /* ROTATE_H */

View file

@ -6,25 +6,25 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:27:25 by maiboyer #+# #+# */
/* Updated: 2024/01/12 21:16:59 by maiboyer ### ########.fr */
/* Updated: 2024/01/29 22:15:52 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STATE_H
# define STATE_H
#define STATE_H
# include "me/types.h"
# include "me/vec/vec_cost.h"
# include "me/vec/vec_element.h"
#include "me/types.h"
#include "me/vec/vec_i64.h"
#include "me/vec/vec_i64_bool.h"
typedef struct s_state
{
t_vec_element stack_a;
t_vec_element stack_b;
t_vec_cost costs;
} t_state;
t_vec_i64_bool sorted;
t_vec_i64 stack_a;
t_vec_i64 stack_b;
} t_state;
t_state parses_arguments(t_usize count, t_str nums[]);
void free_state(t_state state);
t_state parses_arguments(t_usize count, t_str nums[]);
void free_state(t_state state);
#endif /* STATE_H */

21
include/app/target.h Normal file
View file

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* target.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/29 20:30:43 by maiboyer #+# #+# */
/* Updated: 2024/01/29 20:31:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TARGET_H
#define TARGET_H
#include "app/rotate.h"
#include "me/types.h"
t_rotation target(t_usize from, t_usize to, t_usize ring_size);
#endif /* TARGET_H */

View file

@ -1,25 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* element.h :+: :+: :+: */
/* type_i64_bool.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:28:41 by maiboyer #+# #+# */
/* Updated: 2024/01/11 14:34:27 by maiboyer ### ########.fr */
/* Created: 2024/01/29 19:14:52 by maiboyer #+# #+# */
/* Updated: 2024/01/29 19:15:56 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ELEMENT_H
# define ELEMENT_H
#ifndef TYPE_I64_BOOL_H
#define TYPE_I64_BOOL_H
# include "me/types.h"
#include "me/types.h"
typedef struct s_element
typedef struct s_i64_bool
{
t_i64 value;
} t_element;
t_i64 value;
bool active;
} t_i64_bool;
void free_element(t_element elem);
#endif /* ELEMENT_H */
#endif /* TYPE_I64_BOOL_H */