From 8c646de68cfb636a06fc031cda53b89809f486f9 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 7 Jan 2012 21:26:40 +0100 Subject: [PATCH] pattern_eq(): Introduce --- pattern.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pattern.h b/pattern.h index ee3cf49..65fb438 100644 --- a/pattern.h +++ b/pattern.h @@ -140,9 +140,22 @@ int feature_payloads(struct pattern_config *pc, enum feature_id f); char *pattern2str(char *str, struct pattern *p); /* Convert string to pattern, return pointer after the patternspec. */ char *str2pattern(char *str, struct pattern *p); +/* Compare two patterns for equality. Assumes fixed feature order. */ +static bool pattern_eq(struct pattern *p1, struct pattern *p2); /* Initialize p and fill it with features matched by the * given board move. */ void pattern_match(struct pattern_config *pc, pattern_spec ps, struct pattern *p, struct board *b, struct move *m); + +static inline bool +pattern_eq(struct pattern *p1, struct pattern *p2) +{ + if (p1->n != p2->n) return false; + for (int i = 0; i < p1->n; i++) + if (p1->f[i].id != p2->f[i].id || p1->f[i].payload != p2->f[i].payload) + return false; + return true; +} + #endif -- 2.11.4.GIT