This commit is contained in:
Maix0 2024-01-13 18:50:17 +01:00
parent 54a5b658d4
commit 33db892d3b
11 changed files with 233 additions and 38 deletions

32
include/app/cost.h Normal file
View file

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cost.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 21:13:51 by maiboyer #+# #+# */
/* Updated: 2024/01/12 23:37:23 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COST_H
#define COST_H
#include "app/element.h"
#include "app/state.h"
#include "app/types/type_cost.h"
#include "me/types.h"
t_cost alloc_cost(t_state *s);
void free_cost(t_cost self);
void calculate_cost(t_state *s);
void cost_for_index(t_state *s, t_usize index);
typedef struct s_cost_iter_state
{
t_cost *current_minimum;
t_usize max_index;
} t_cost_iter_state;
#endif /* COST_H */

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 16:13:08 by maiboyer #+# #+# */
/* Updated: 2024/01/11 16:18:49 by maiboyer ### ########.fr */
/* Updated: 2024/01/12 21:27:27 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,22 +15,9 @@
#include "app/element.h"
#include "app/state.h"
#include "me/types.h"
#include "app/types/type_move.h"
typedef enum e_move
{
SWAP_A = 1 << 0,
SWAP_B = 1 << 1,
SWAP_BOTH = SWAP_A | SWAP_B,
PUSH_A = 1 << 2,
PUSH_B = 1 << 3,
ROTATE_A = 1 << 4,
ROTATE_B = 1 << 5,
ROTATE_BOTH = ROTATE_A | ROTATE_B,
REVERSE_ROTATE_A = 1 << 6,
REVERSE_ROTATE_B = 1 << 7,
REVERSE_ROTATE_BOTH = REVERSE_ROTATE_A | REVERSE_ROTATE_B,
} t_move;
#include "me/types.h"
void do_move(t_move m, t_state *s);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/11 14:27:25 by maiboyer #+# #+# */
/* Updated: 2024/01/11 14:36:28 by maiboyer ### ########.fr */
/* Updated: 2024/01/12 21:16:59 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,11 +15,13 @@
#include "me/types.h"
#include "me/vec/vec_element.h"
#include "me/vec/vec_cost.h"
typedef struct s_state
{
t_vec_element stack_a;
t_vec_element stack_b;
t_vec_cost costs;
} t_state;
t_state parses_arguments(t_usize count, t_str nums[]);

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_cost.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 21:20:00 by maiboyer #+# #+# */
/* Updated: 2024/01/12 23:16:24 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPE_COST_H
#define TYPE_COST_H
#include "me/types.h"
#include "me/vec/vec_moves.h"
typedef struct s_cost
{
t_usize index;
t_vec_moves moves;
bool active;
} t_cost;
#endif /* TYPE_COST_H */

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* type_move.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/12 21:26:56 by maiboyer #+# #+# */
/* Updated: 2024/01/12 21:27:08 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef TYPE_MOVE_H
#define TYPE_MOVE_H
typedef enum e_move
{
SWAP_A = 1 << 0,
SWAP_B = 1 << 1,
SWAP_BOTH = SWAP_A | SWAP_B,
PUSH_A = 1 << 2,
PUSH_B = 1 << 3,
ROTATE_A = 1 << 4,
ROTATE_B = 1 << 5,
ROTATE_BOTH = ROTATE_A | ROTATE_B,
REVERSE_ROTATE_A = 1 << 6,
REVERSE_ROTATE_B = 1 << 7,
REVERSE_ROTATE_BOTH = REVERSE_ROTATE_A | REVERSE_ROTATE_B,
} t_move;
#endif /* TYPE_MOVE_H */