mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
Patch from James H to make new-Loopy port more easily.
[originally from svn r8174]
This commit is contained in:
33
grid.c
33
grid.c
@ -50,7 +50,7 @@ void grid_free(grid *g)
|
|||||||
|
|
||||||
/* Used by the other grid generators. Create a brand new grid with nothing
|
/* Used by the other grid generators. Create a brand new grid with nothing
|
||||||
* initialised (all lists are NULL) */
|
* initialised (all lists are NULL) */
|
||||||
static grid *grid_new()
|
static grid *grid_new(void)
|
||||||
{
|
{
|
||||||
grid *g = snew(grid);
|
grid *g = snew(grid);
|
||||||
g->faces = NULL;
|
g->faces = NULL;
|
||||||
@ -76,11 +76,11 @@ static grid *grid_new()
|
|||||||
*
|
*
|
||||||
* Combining gives: distance = determinant / line-length(a,b)
|
* Combining gives: distance = determinant / line-length(a,b)
|
||||||
*/
|
*/
|
||||||
static double point_line_distance(int px, int py,
|
static double point_line_distance(long px, long py,
|
||||||
int ax, int ay,
|
long ax, long ay,
|
||||||
int bx, int by)
|
long bx, long by)
|
||||||
{
|
{
|
||||||
int det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
|
long det = ax*by - bx*ay + bx*py - px*by + px*ay - ax*py;
|
||||||
double len;
|
double len;
|
||||||
det = max(det, -det);
|
det = max(det, -det);
|
||||||
len = sqrt(SQ(ax - bx) + SQ(ay - by));
|
len = sqrt(SQ(ax - bx) + SQ(ay - by));
|
||||||
@ -125,7 +125,7 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* Target to beat */
|
/* Target to beat */
|
||||||
int dist = SQ(cur->x - x) + SQ(cur->y - y);
|
long dist = SQ((long)cur->x - (long)x) + SQ((long)cur->y - (long)y);
|
||||||
/* Look for nearer dot - if found, store in 'new'. */
|
/* Look for nearer dot - if found, store in 'new'. */
|
||||||
grid_dot *new = cur;
|
grid_dot *new = cur;
|
||||||
int i;
|
int i;
|
||||||
@ -137,10 +137,10 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
|
|||||||
int j;
|
int j;
|
||||||
if (!f) continue;
|
if (!f) continue;
|
||||||
for (j = 0; j < f->order; j++) {
|
for (j = 0; j < f->order; j++) {
|
||||||
int new_dist;
|
long new_dist;
|
||||||
grid_dot *d = f->dots[j];
|
grid_dot *d = f->dots[j];
|
||||||
if (d == cur) continue;
|
if (d == cur) continue;
|
||||||
new_dist = SQ(d->x - x) + SQ(d->y - y);
|
new_dist = SQ((long)d->x - (long)x) + SQ((long)d->y - (long)y);
|
||||||
if (new_dist < dist) {
|
if (new_dist < dist) {
|
||||||
new = d;
|
new = d;
|
||||||
break; /* found closer dot */
|
break; /* found closer dot */
|
||||||
@ -157,23 +157,22 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
|
|||||||
cur = new;
|
cur = new;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 'cur' is nearest dot, so find which of the dot's edges is closest. */
|
/* 'cur' is nearest dot, so find which of the dot's edges is closest. */
|
||||||
best_edge = NULL;
|
best_edge = NULL;
|
||||||
|
|
||||||
for (i = 0; i < cur->order; i++) {
|
for (i = 0; i < cur->order; i++) {
|
||||||
grid_edge *e = cur->edges[i];
|
grid_edge *e = cur->edges[i];
|
||||||
int e2; /* squared length of edge */
|
long e2; /* squared length of edge */
|
||||||
int a2, b2; /* squared lengths of other sides */
|
long a2, b2; /* squared lengths of other sides */
|
||||||
double dist;
|
double dist;
|
||||||
|
|
||||||
/* See if edge e is eligible - the triangle must have acute angles
|
/* See if edge e is eligible - the triangle must have acute angles
|
||||||
* at the edge's dots.
|
* at the edge's dots.
|
||||||
* Pythagoras formula h^2 = a^2 + b^2 detects right-angles,
|
* Pythagoras formula h^2 = a^2 + b^2 detects right-angles,
|
||||||
* so detect acute angles by testing for h^2 < a^2 + b^2 */
|
* so detect acute angles by testing for h^2 < a^2 + b^2 */
|
||||||
e2 = SQ(e->dot1->x - e->dot2->x) + SQ(e->dot1->y - e->dot2->y);
|
e2 = SQ((long)e->dot1->x - (long)e->dot2->x) + SQ((long)e->dot1->y - (long)e->dot2->y);
|
||||||
a2 = SQ(e->dot1->x - x) + SQ(e->dot1->y - y);
|
a2 = SQ((long)e->dot1->x - (long)x) + SQ((long)e->dot1->y - (long)y);
|
||||||
b2 = SQ(e->dot2->x - x) + SQ(e->dot2->y - y);
|
b2 = SQ((long)e->dot2->x - (long)x) + SQ((long)e->dot2->y - (long)y);
|
||||||
if (a2 >= e2 + b2) continue;
|
if (a2 >= e2 + b2) continue;
|
||||||
if (b2 >= e2 + a2) continue;
|
if (b2 >= e2 + a2) continue;
|
||||||
|
|
||||||
@ -187,9 +186,9 @@ grid_edge *grid_nearest_edge(grid *g, int x, int y)
|
|||||||
* Alternatively, we could check that the angle at the point is obtuse.
|
* Alternatively, we could check that the angle at the point is obtuse.
|
||||||
* That would amount to testing a circular region with the edge as
|
* That would amount to testing a circular region with the edge as
|
||||||
* diameter. */
|
* diameter. */
|
||||||
dist = point_line_distance(x, y,
|
dist = point_line_distance((long)x, (long)y,
|
||||||
e->dot1->x, e->dot1->y,
|
(long)e->dot1->x, (long)e->dot1->y,
|
||||||
e->dot2->x, e->dot2->y);
|
(long)e->dot2->x, (long)e->dot2->y);
|
||||||
/* Is dist more than half edge length ? */
|
/* Is dist more than half edge length ? */
|
||||||
if (4 * SQ(dist) > e2)
|
if (4 * SQ(dist) > e2)
|
||||||
continue;
|
continue;
|
||||||
|
31
loopy.c
31
loopy.c
@ -236,7 +236,7 @@ static void check_caches(const solver_state* sstate);
|
|||||||
static char const *const gridnames[] = { GRIDLIST(GRID_NAME) };
|
static char const *const gridnames[] = { GRIDLIST(GRID_NAME) };
|
||||||
#define GRID_CONFIGS GRIDLIST(GRID_CONFIG)
|
#define GRID_CONFIGS GRIDLIST(GRID_CONFIG)
|
||||||
static grid * (*(grid_fns[]))(int w, int h) = { GRIDLIST(GRID_FN) };
|
static grid * (*(grid_fns[]))(int w, int h) = { GRIDLIST(GRID_FN) };
|
||||||
static const int NUM_GRID_TYPES = sizeof(grid_fns) / sizeof(grid_fns[0]);
|
#define NUM_GRID_TYPES (sizeof(grid_fns) / sizeof(grid_fns[0]))
|
||||||
|
|
||||||
/* Generates a (dynamically allocated) new grid, according to the
|
/* Generates a (dynamically allocated) new grid, according to the
|
||||||
* type and size requested in params. Does nothing if the grid is already
|
* type and size requested in params. Does nothing if the grid is already
|
||||||
@ -464,6 +464,18 @@ static game_params *dup_params(game_params *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const game_params presets[] = {
|
static const game_params presets[] = {
|
||||||
|
#ifdef SMALL_SCREEN
|
||||||
|
{ 7, 7, DIFF_EASY, 0, NULL },
|
||||||
|
{ 7, 7, DIFF_NORMAL, 0, NULL },
|
||||||
|
{ 7, 7, DIFF_HARD, 0, NULL },
|
||||||
|
{ 7, 7, DIFF_HARD, 1, NULL },
|
||||||
|
{ 7, 7, DIFF_HARD, 2, NULL },
|
||||||
|
{ 5, 5, DIFF_HARD, 3, NULL },
|
||||||
|
{ 7, 7, DIFF_HARD, 4, NULL },
|
||||||
|
{ 5, 4, DIFF_HARD, 5, NULL },
|
||||||
|
{ 5, 5, DIFF_HARD, 6, NULL },
|
||||||
|
{ 5, 5, DIFF_HARD, 7, NULL },
|
||||||
|
#else
|
||||||
{ 7, 7, DIFF_EASY, 0, NULL },
|
{ 7, 7, DIFF_EASY, 0, NULL },
|
||||||
{ 10, 10, DIFF_EASY, 0, NULL },
|
{ 10, 10, DIFF_EASY, 0, NULL },
|
||||||
{ 7, 7, DIFF_NORMAL, 0, NULL },
|
{ 7, 7, DIFF_NORMAL, 0, NULL },
|
||||||
@ -477,6 +489,7 @@ static const game_params presets[] = {
|
|||||||
{ 5, 4, DIFF_HARD, 5, NULL },
|
{ 5, 4, DIFF_HARD, 5, NULL },
|
||||||
{ 7, 7, DIFF_HARD, 6, NULL },
|
{ 7, 7, DIFF_HARD, 6, NULL },
|
||||||
{ 5, 5, DIFF_HARD, 7, NULL },
|
{ 5, 5, DIFF_HARD, 7, NULL },
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
static int game_fetch_preset(int i, char **name, game_params **params)
|
static int game_fetch_preset(int i, char **name, game_params **params)
|
||||||
@ -3291,14 +3304,14 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
|
|||||||
|
|
||||||
dx = (dx * ds->tilesize) / thickness;
|
dx = (dx * ds->tilesize) / thickness;
|
||||||
dy = (dy * ds->tilesize) / thickness;
|
dy = (dy * ds->tilesize) / thickness;
|
||||||
points[0] = x1 + dy;
|
points[0] = x1 + (int)dy;
|
||||||
points[1] = y1 - dx;
|
points[1] = y1 - (int)dx;
|
||||||
points[2] = x1 - dy;
|
points[2] = x1 - (int)dy;
|
||||||
points[3] = y1 + dx;
|
points[3] = y1 + (int)dx;
|
||||||
points[4] = x2 - dy;
|
points[4] = x2 - (int)dy;
|
||||||
points[5] = y2 + dx;
|
points[5] = y2 + (int)dx;
|
||||||
points[6] = x2 + dy;
|
points[6] = x2 + (int)dy;
|
||||||
points[7] = y2 - dx;
|
points[7] = y2 - (int)dx;
|
||||||
draw_polygon(dr, points, 4, ink, ink);
|
draw_polygon(dr, points, 4, ink, ink);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user