aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2023-03-30 08:37:17 +0100
committerSimon Tatham <anakin@pobox.com>2023-03-30 08:37:17 +0100
commit73dab39bf5661565f97b2a9571547d5c62f13e39 (patch)
tree70cb21198131cd0fce4961b041ebcc17834495cf
parent796d0f372f12debd45950cd17908ef98e643b13d (diff)
downloadpuzzles-73dab39bf5661565f97b2a9571547d5c62f13e39.zip
puzzles-73dab39bf5661565f97b2a9571547d5c62f13e39.tar.gz
puzzles-73dab39bf5661565f97b2a9571547d5c62f13e39.tar.bz2
puzzles-73dab39bf5661565f97b2a9571547d5c62f13e39.tar.xz
Hats: choose the tiling's starting hat more uniformly.
This fills in the missing piece of commit 6f75879e9fe7cb5, which was trying to make the output patches of tiling as uniformly random as possible across the whole space of possible ones. I fixed every _intermediate_ step in the algorithm, but forgot the starting one!
-rw-r--r--hat.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/hat.c b/hat.c
index 6f0fc96..a269ae7 100644
--- a/hat.c
+++ b/hat.c
@@ -497,6 +497,28 @@ static const size_t n_possible_parents[] = {
lenof(parents_H), lenof(parents_T), lenof(parents_P), lenof(parents_F),
};
+/*
+ * Similarly, we also want to choose our absolute starting hat with
+ * close to uniform probability, which again we do by looking at the
+ * limiting ratio of the metatile types, and this time, scaling by the
+ * number of hats in each metatile.
+ *
+ * We cheatingly use the same MetatilePossibleParent struct, because
+ * it's got all the right fields, even if it has an inappropriate
+ * name.
+ */
+static const MetatilePossibleParent starting_hats[] = {
+ { TT_H, 0, PROB_H },
+ { TT_H, 1, PROB_H },
+ { TT_H, 2, PROB_H },
+ { TT_H, 3, PROB_H },
+ { TT_T, 0, PROB_P },
+ { TT_P, 0, PROB_P },
+ { TT_P, 1, PROB_P },
+ { TT_F, 0, PROB_F },
+ { TT_F, 1, PROB_F },
+};
+
#undef PROB_H
#undef PROB_T
#undef PROB_P
@@ -624,15 +646,17 @@ typedef struct HatCoordContext {
static void init_coords_random(HatCoordContext *ctx, random_state *rs)
{
+ const MetatilePossibleParent *starting_hat = choose_mpp(
+ rs, starting_hats, lenof(starting_hats));
+
ctx->rs = rs;
ctx->prototype = hc_new();
hc_make_space(ctx->prototype, 3);
- ctx->prototype->c[0].type = TT_KITE;
- ctx->prototype->c[1].type = TT_HAT;
- ctx->prototype->c[2].type = random_upto(rs, 4);
+ ctx->prototype->c[2].type = starting_hat->type;
ctx->prototype->c[2].index = -1;
- ctx->prototype->c[1].index = random_upto(
- rs, hats_in_metatile[ctx->prototype->c[2].type]);
+ ctx->prototype->c[1].type = TT_HAT;
+ ctx->prototype->c[1].index = starting_hat->index;
+ ctx->prototype->c[0].type = TT_KITE;
ctx->prototype->c[0].index = random_upto(rs, HAT_KITES);
ctx->prototype->nc = 3;
}