+ uint8_t flags;
+ int8_t lcob_near, rcob_near;
+ uint8_t lcob, rcob;
+ uint8_t lidx, ridx;
+
+ /* read sensors from ballboard */
+ IRQ_LOCK(flags);
+ lcob = ballboard.lcob;
+ ballboard.lcob = I2C_COB_NONE;
+ rcob = ballboard.rcob;
+ ballboard.rcob = I2C_COB_NONE;
+ IRQ_UNLOCK(flags);
+
+/* if (lcob != I2C_COB_NONE) */
+/* DEBUG(E_USER_STRAT, "XXX lcob %s", */
+/* lcob == I2C_COB_WHITE ? "white" : "black"); */
+/* if (rcob != I2C_COB_NONE) */
+/* DEBUG(E_USER_STRAT, "XXX rcob %s", */
+/* rcob == I2C_COB_WHITE ? "white" : "black"); */
+ /* XXX take opponent position into account */
+
+#ifdef HOST_VERSION
+ if (time_get_s() == 15)
+ cobboard.cob_count = 5;
+ if (time_get_s() == 16)
+ cobboard.cob_count = 0;
+#endif
+
+ /* detect cob on left side */
+ lcob_near = corn_is_near(&lidx, I2C_LEFT_SIDE);
+ if (lcob_near && lcob != I2C_COB_NONE) {
+ if (strat_db.corn_table[lidx]->corn.color == I2C_COB_UNKNOWN)
+ DEBUG(E_USER_STRAT, "lcob %s %d",
+ lcob == I2C_COB_WHITE ? "white" : "black", lidx);
+ corn_set_color(strat_db.corn_table[lidx], lcob);
+ }
+
+ /* detect cob on right side */
+ rcob_near = corn_is_near(&ridx, I2C_RIGHT_SIDE);
+ if (rcob_near && rcob != I2C_COB_NONE) {
+ if (strat_db.corn_table[ridx]->corn.color == I2C_COB_UNKNOWN)
+ DEBUG(E_USER_STRAT, "rcob %s %d",
+ rcob == I2C_COB_WHITE ? "white" : "black", ridx);
+ corn_set_color(strat_db.corn_table[ridx], rcob);
+ }
+
+ /* control the cobboard mode for left spickle */
+ if (lcob_near && strat_db.corn_table[lidx]->present) {
+ if (get_cob_count() >= 5 || want_pack || strat_lpack60) {
+ /* nothing */
+ }
+ else {
+ /* deploy spickle and harvest white ones */
+ if (strat_db.corn_table[lidx]->corn.color == I2C_COB_WHITE) {
+ i2c_cobboard_autoharvest_nomove(I2C_LEFT_SIDE);
+ if (cobboard.status == I2C_COBBOARD_STATUS_LBUSY)
+ strat_db.corn_table[lidx]->present = 0;
+ }
+ else
+ i2c_cobboard_deploy_nomove(I2C_LEFT_SIDE);
+ }
+ }
+ else {
+ /* no cob near us, we can pack or deploy freely */
+ if (get_cob_count() >= 5 || want_pack || strat_lpack60)
+ i2c_cobboard_pack(I2C_LEFT_SIDE);
+ else
+ i2c_cobboard_deploy(I2C_LEFT_SIDE);
+ }
+
+ /* control the cobboard mode for right spickle */
+ if (rcob_near && strat_db.corn_table[ridx]->present) {
+ if (get_cob_count() >= 5 || want_pack || strat_rpack60) {
+ /* nothing */
+ }
+ else {
+ /* deploy spickle and harvest white ones */
+ if (strat_db.corn_table[ridx]->corn.color == I2C_COB_WHITE) {
+ i2c_cobboard_autoharvest_nomove(I2C_RIGHT_SIDE);
+ if (cobboard.status == I2C_COBBOARD_STATUS_RBUSY)
+ strat_db.corn_table[ridx]->present = 0;
+ }