From b0a8aaeddfc5feb8a55d16891e199f635291c66a Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Wed, 17 Apr 2024 12:21:25 +0200 Subject: [PATCH] Add movement (with some bugs) TODO: Fix sorting direction. Right now the numbers are sorted max -> min instead of min -> max. TODO: Fix sorting bug. Some numbers are not sorted. --- cmd_optimization.c | 3 ++- sorting.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cmd_optimization.c b/cmd_optimization.c index d0928f5..9fcf876 100644 --- a/cmd_optimization.c +++ b/cmd_optimization.c @@ -6,7 +6,7 @@ /* By: dkaiser b->size + 1) / 2) + { + while (idx--) + run_command(data, RB); + } + else + { + idx = data->b->size - idx; + while (idx--) + run_command(data, RRB); + } +} + +static void move_to_spot(t_psdata *data) { + int pos; + int i; + pos = 0; + while (pos < data->a->size && data->b->stack[0] < data->a->stack[pos]) + pos++; + if (pos < (data->a->size + 1) / 2) + { + i = pos; + while (i--) + run_command(data, RA); + run_command(data, PA); + i = pos; + while (i--) + run_command(data, RRA); + } + else + { + i = data->a->size - pos; + while (i--) + run_command(data, RRA); + run_command(data, PA); + i = data->a->size - pos; + while (i--) + run_command(data, RA); + } } static void scoresort(t_psdata *data) @@ -84,7 +126,8 @@ static void scoresort(t_psdata *data) min_score = i; i++; } - move_to_right_spot(data, min_score); + move_to_top(data, min_score); + move_to_spot(data); free(scores); if (data->b->size > 0) -- 2.47.2