-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_rotations.c
58 lines (52 loc) · 1.98 KB
/
set_rotations.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_rotations.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpaulo-m <lpaulo-m@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/16 00:17:03 by lpaulo-m #+# #+# */
/* Updated: 2022/08/11 16:17:11 by lpaulo-m ### ########.fr */
/* */
/* ************************************************************************** */
#include <push_swap.h>
static void set_total(t_rotation *r)
{
r->total = r->ra + r->rb + r->rr + r->rra + r->rrb + r->rrr;
}
void set_up_up_rotation(t_rotation *r, int b_index, int a_index)
{
r[UP_UP].rb = b_index;
r[UP_UP].ra = a_index;
if (r[UP_UP].rb > r[UP_UP].ra)
r[UP_UP].rr = r[UP_UP].ra;
else
r[UP_UP].rr = r[UP_UP].rb;
r[UP_UP].ra -= r[UP_UP].rr;
r[UP_UP].rb -= r[UP_UP].rr;
set_total(&r[UP_UP]);
}
void set_down_down_rotation(t_rotation *r, int b_index, int a_index)
{
r[DOWN_DOWN].rra = count_a() - a_index;
r[DOWN_DOWN].rrb = count_b() - b_index;
if (r[DOWN_DOWN].rrb > r[DOWN_DOWN].rra)
r[DOWN_DOWN].rrr = r[DOWN_DOWN].rra;
else
r[DOWN_DOWN].rrr = r[DOWN_DOWN].rrb;
r[DOWN_DOWN].rra -= r[DOWN_DOWN].rrr;
r[DOWN_DOWN].rrb -= r[DOWN_DOWN].rrr;
set_total(&r[DOWN_DOWN]);
}
void set_up_down_rotation(t_rotation *r, int b_index, int a_index)
{
r[UP_DOWN].ra = a_index;
r[UP_DOWN].rrb = count_b() - b_index;
set_total(&r[UP_DOWN]);
}
void set_down_up_rotation(t_rotation *r, int b_index, int a_index)
{
r[DOWN_UP].rra = count_a() - a_index;
r[DOWN_UP].rb = b_index;
set_total(&r[DOWN_UP]);
}