aboutsummaryrefslogtreecommitdiff
path: root/src/steps.c
blob: cdba7632779046cea453cb6a64044e85bd480cde (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#define STEPS_C

#include "steps.h"

/* TODO: change all checkers to use coordinates! */

bool
check_centers(Cube *cube)
{
	int i;

	for (i = 0; i < 6; i++)
		if (cube->xp[i] != i)
			return false;

	return true;
}

bool
check_coud_HTM(Cube *cube)
{
	int i;

	for (i = 0; i < 8; i++)
		if (cube->co[i] != 0)
			return false;

	return true;
}

bool
check_coud_URF(Cube *cube)
{
	Cube c2, c3;

	copy_cube(cube, &c2);
	copy_cube(cube, &c3);

	apply_move(z, &c2);
	apply_move(x, &c3);

	return check_coud_HTM(cube) ||
	       check_coud_HTM(&c2)  ||
	       check_coud_HTM(&c3);
}

bool
check_cp_HTM(Cube *cube)
{
	int i;

	for (i = 0; i < 8; i++)
		if (cube->cp[i] != i)
			return false;

	return true;
}

bool
check_corners_HTM(Cube *cube)
{
	return check_coud_HTM(cube) && check_cp_HTM(cube);
}

bool
check_corners_URF(Cube *cube)
{
	Cube c;
	Trans i;

	for (i = 0; i < NROTATIONS; i++) {
		copy_cube(cube, &c);
		apply_alg(rotation_alg(i), &c);
		if (check_corners_HTM(&c))
			return true;
	}

	return false;
}

bool
check_cornershtr(Cube *cube)
{
	/* TODO (use coord) */
	return true;
}

bool
check_eofb(Cube *cube)
{
	/* TODO (use coord) */
	return true;
}

bool
check_drud(Cube *cube)
{
	/* TODO (use coord) */
	return true;
}

bool
check_htr(Cube *cube)
{
	/* TODO (check_drud(cube) and coord_htr_drud == 0) */
	return true;
}

Alg *
validate_singlecw_ending(Alg *alg)
{
	int i;
	bool nor, inv;
	Alg *ret;
	Move l2 = NULLMOVE, l1 = NULLMOVE, l2i = NULLMOVE, l1i = NULLMOVE;

	for (i = 0; i < alg->len; i++) {
		if (alg->inv[i]) {
			l2i = l1i;
			l1i = alg->move[i];
		} else {
			l2 = l1;
			l1 = alg->move[i];
		}
	}

	nor = l1 ==base_move(l1)  && (!commute(l1, l2) ||l2 ==base_move(l2));
	inv = l1i==base_move(l1i) && (!commute(l1i,l2i)||l2i==base_move(l2i));

	if (nor && inv) {
		ret = new_alg("");
		copy_alg(alg, ret);
	} else {
		ret = NULL;
	}

	return ret;
}

/* Public functions **********************************************************/

/*
void
compute_ind(Step *s, Cube *cube, Movable *ind)
{
	int i;
	Cube mvd;
	Trans t, tt;

	for (i = 0; i < s->n_coord; i++) {
		t = s->coord_trans[i];
		copy_cube(cube, &mvd);
		apply_trans(t, &mvd);

		ind[i].val = index_coord(s->coord[i], &mvd, &tt);
		ind[i].t = transform_trans(tt, t);
	}
}
*/

void
prepare_cs(ChoiceStep *cs, SolveOptions *opts)
{
	int i, j;
	Step *s;

	for (i = 0; cs->step[i] != NULL; i++) {
		s = cs->step[i];
		for (j = 0; j < s->n_coord; j++) {
			s->pd[j] = malloc(sizeof(PruneData));
			s->pd[j]->moveset = s->moveset;
			s->pd[j]->coord   = s->coord[j];
			s->pd[j]->compact = s->pd_compact[j];
			s->pd[j] = genptable(s->pd[j], opts->nthreads);
		}
	}
}

Generated with cgit - Back to sebastiano.tronto.net