-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_swap_make_moves.c
110 lines (102 loc) · 2.3 KB
/
push_swap_make_moves.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* push_swap_make_moves.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: imoro-sa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/26 10:26:09 by imoro-sa #+# #+# */
/* Updated: 2023/04/26 10:26:10 by imoro-sa ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
t_movs move_values(t_cost move)
{
t_movs times;
times.a = 0;
times.b = 0;
times.ab = 0;
if (((move.a < 0 && move.b < 0) && (move.a > move.b))
|| ((move.a > 0 && move.b > 0) && (move.a < move.b)))
{
times.ab = move.a;
times.b = move.b - move.a;
}
else if (((move.a < 0 && move.b < 0) && (move.a < move.b))
|| ((move.a > 0 && move.b > 0) && (move.a > move.b)))
{
times.ab = move.b;
times.a = move.a - move.b;
}
else
{
times.a = move.a;
times.b = move.b;
}
return (times);
}
void make_move_stack_a(int times, t_stack stack)
{
if (times > 0)
{
while (times > 0)
{
rotate(stack);
times--;
}
}
if (times < 0)
{
while (times < 0)
{
rev_rotate(stack);
times++;
}
}
}
void make_move_stack_b(int times, t_stack stack)
{
if (times > 0)
{
while (times > 0)
{
rotate(stack);
times--;
}
}
if (times < 0)
{
while (times < 0)
{
rev_rotate(stack);
times++;
}
}
}
void make_move_stack_ab(int times, t_stack stack_a, t_stack stack_b)
{
if (times > 0)
{
while (times > 0)
{
rotate_ab(stack_a, stack_b);
times--;
}
}
if (times < 0)
{
while (times < 0)
{
rev_rotate_ab(stack_a, stack_b);
times++;
}
}
}
void make_moves(t_stack stack_a, t_stack stack_b, t_cost move)
{
t_movs times;
times = move_values(move);
make_move_stack_a(times.a, stack_a);
make_move_stack_b(times.b, stack_b);
make_move_stack_ab(times.ab, stack_a, stack_b);
}