summaryrefslogtreecommitdiff
path: root/digital/io-hub/src/robospierre/element.h
diff options
context:
space:
mode:
authorJérôme Jutteau2011-05-28 14:27:14 +0200
committerJérôme Jutteau2011-05-28 16:35:04 +0200
commitd2e4e1f473154775de48d19a31a97e9604e30905 (patch)
tree64f8be8dbcbc163a3519f1fd9b075a7bb88e41ae /digital/io-hub/src/robospierre/element.h
parent579d7d9ad8caf4299c5c672b724d056d9e9d9797 (diff)
digital/io-hub: add element score computation
Diffstat (limited to 'digital/io-hub/src/robospierre/element.h')
-rw-r--r--digital/io-hub/src/robospierre/element.h127
1 files changed, 121 insertions, 6 deletions
diff --git a/digital/io-hub/src/robospierre/element.h b/digital/io-hub/src/robospierre/element.h
index aa7b5b4e..95cf2b2c 100644
--- a/digital/io-hub/src/robospierre/element.h
+++ b/digital/io-hub/src/robospierre/element.h
@@ -3,7 +3,7 @@
/* element.h */
/* robospierre - Eurobot 2011 AI. {{{
*
- * Copyright (C) 2011 Nicolas Schodet
+ * Copyright (C) 2011 Nicolas Schodet, Jérôme Jutteau
*
* APBTeam:
* Web: http://apbteam.org/
@@ -24,17 +24,25 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* }}} */
+#include "defs.h"
+/** None. */
+#define ELEMENT_NONE 1
/** A pawn, not a head. */
-#define ELEMENT_PAWN 1
+#define ELEMENT_PAWN 2
/** Queen pawn, used for statistic update of table data. */
-#define ELEMENT_QUEEN 2
+#define ELEMENT_QUEEN 4
/** King pawn, used for statistic update of table data. */
-#define ELEMENT_KING 4
+#define ELEMENT_KING 8
/** Any head, queen or king. */
-#define ELEMENT_HEAD 6
+#define ELEMENT_HEAD (ELEMENT_QUEEN |ELEMENT_KING)
/** Any element, pawn, queen, or king. */
-#define ELEMENT_ANY 7
+#define ELEMENT_ANY (ELEMENT_HEAD |ELEMENT_PAWN)
+/** Tower types. */
+#define ELEMENT_TOWER_1_QUEEN 8
+#define ELEMENT_TOWER_2_QUEEN 16
+#define ELEMENT_TOWER_1_KING 32
+#define ELEMENT_TOWER_2_KING 64
/** Return non zero if element is a head, not a pawn. */
#define ELEMENT_IS_HEAD(e) ((e) && !((e) & ELEMENT_PAWN))
@@ -42,4 +50,111 @@
/** Return non zero if element may be a head. */
#define ELEMENT_CAN_BE_HEAD(e) ((e) & ELEMENT_HEAD)
+#define ELEMENT_PAWN_SCORE 10
+#define ELEMENT_ANY_SCORE 15
+#define ELEMENT_QUEEN_SCORE 20
+#define ELEMENT_KING_SCORE 30
+
+/** Emplacement attributes bits. */
+#define ELEMENT_BONUS 1
+/**
+ * Two meanings:
+ * - When it is on an intersection or in the green zone, this mean that it is positioned on the
+ * left size of the table.
+ * - When it is located on an color, this corresponds to the red color.
+ */
+#define ELEMENT_LEFT 2
+/**
+ * Two meanings:
+ * - When it is on an intersection or in the green zone, this mean that it is positioned on the
+ * left right of the table.
+ * - When it is located on an color, this corresponds to the blue color.
+ */
+#define ELEMENT_RIGHT 4
+#define ELEMENT_SAFE 8
+#define ELEMENT_GREEN 16
+#define ELEMENT_INTERSEC 64
+/** Center of a square or central element. */
+#define ELEMENT_CENTER 128
+
+struct element_t
+{
+ /** May have several types if unknown (pawn, king, queen). */
+ uint8_t type;
+ /** Element position. */
+ vect_t pos;
+ /** Emplacement attributes. */
+ uint8_t attr;
+};
+typedef struct element_t element_t;
+
+/* Elements range, see element table content. */
+#define ELEMENT_INTERSEC_START 0
+#define ELEMENT_INTERSEC_END 19
+#define ELEMENT_CENTRAL_PAWN 20
+#define ELEMENT_GREEN_START 21
+#define ELEMENT_GREEN_END 30
+#define ELEMENT_UNLOAD_START 31
+#define ELEMENT_UNLOAD_END 62
+#define ELEMENT_UNLOAD_SAFE_START 63
+#define ELEMENT_UNLOAD_SAFE_END 66
+
+/** Elements on table. */
+extern struct element_t element_table[];
+
+/** Initialize elements. */
+void
+element_init (void);
+
+/** Gives the score of an element considering it as an unload zone. */
+int32_t
+element_unload_score (position_t robot_pos, uint8_t element_id);
+
+/** Gives best unload. */
+uint8_t
+element_unload_best (position_t robot_pos);
+
+/** Gives score of an element. */
+int32_t
+element_score (position_t robot_pos, uint8_t element_id);
+
+/** Return a probability of an element to be here.
+ * This depends of the remaining time.
+ * Returns a probability from 0 (element may really not be here)
+ * to maximal value (element may be here).
+ */
+uint32_t
+element_proba (uint8_t element_id);
+
+/** Return the best element to pick. */
+uint8_t
+element_best (position_t robot_pos);
+
+/** Function to call when we see an element is not here. */
+void
+element_not_here (uint8_t element_id);
+
+/** Call this function when an element is taken. */
+void
+element_taken (uint8_t element_id, uint8_t element_type);
+
+/** Call this function when the robot put down an element. */
+void
+element_down (uint8_t element_id, uint8_t element_type);
+
+/** Gives the nearest element from a position. */
+uint8_t
+element_give_position (position_t pos);
+
+/** Give the opposed element. */
+uint8_t
+element_opposed (uint8_t element_id);
+
+/** Return 1 if the element is in our side, 0 otherwise. */
+int
+element_our_side (uint8_t element_id);
+
+inline void
+element_intersec_symetric (uint8_t element_id, uint8_t element_type);
+
#endif /* element_h */