Пример #1
0
static void InitStates() {
  int i, t;

  for (i = 0; i < NumStates(); i++) {
    for (t = 0; t < 256; t++) {
      states[i].transitions[t] = kInvalidState;
    }
  }
}
Пример #2
0
/* Adds an edge with a range of bytes. For use in definitions generated by the
 * DFA parser.  */
void AddRange(int state_idx,
              uint8_t byte_begin,
              uint8_t byte_end,
              uint16_t target) {
  int i;

  assert(0 <= state_idx && state_idx < NumStates());
  for (i = byte_begin; i <= byte_end; i++) {
    states[state_idx].transitions[i] = target;
  }
}
Пример #3
0
Tag::Tag(string params_file) :
	BaseTag(params_file) {
	same_loc_obs_ = floor_.NumCells();
	obs_.resize(NumStates());
	for (int rob = 0; rob < floor_.NumCells(); rob++) {
		for (int opp = 0; opp < floor_.NumCells(); opp++) {
			int s = RobOppIndicesToStateIndex(rob, opp);
			obs_[s] = (rob == opp ? same_loc_obs_ : rob);
		}
	}
  robot_pos_unknown_ = false;
}
Пример #4
0
/* The main loop to traverse all possible paths from the begin state, record
 * transition bytes and output the whole instruction as soon as we reach a final
 * state.  If we are in a multibyte field that the decoder should not care
 * about, we generate 0x01, 0x23, 0x45, ... as the field bytes.  */
static void TraverseStates(uint16_t entry, bool in_anyfield) {
  int i;
  uint8_t prev_byte;
  struct state st = states[entry];
  uint16_t st2;

  if (st.is_final) {
    OutputWriteInstruction(&g_output);
    /* Some final states have outgoing transitions, so we have to continue
       iterating through them. */
  }
  if (!in_anyfield) {
    if (st.anyfield_begin) {
      /* We are in the state that starts anyfield. If it is a one-byte field,
         then recursive call is not anyfield.  */
      inst_bytes[inst_len++] = 0x01;
      if (st.anyfield_end) {
        TraverseStates(st.transitions[0], false);
      } else {
        TraverseStates(st.transitions[0], true);
      }
      inst_len--;
    } else {
      /* Traverse all available transitions in the node.  */
      for (i = 0; i < 256; i++) {
        st2 = st.transitions[i];
        if (st2 != kInvalidState) {
          assert(st2 < NumStates());
          inst_bytes[inst_len++] = i;
          TraverseStates(st2, false);
          inst_len--;
        }
      }
    }
  } else {
    /* Continue anyfield traversal.  */
    assert(AllTransitionsEqual(st));
    prev_byte = inst_bytes[inst_len - 1];
    inst_bytes[inst_len++] = prev_byte + 0x22;
    if (st.anyfield_end) {
      TraverseStates(st.transitions[0], false);
    } else {
      TraverseStates(st.transitions[0], true);
    }
    inst_len--;
  }
}
Пример #5
0
Tag::Tag() {
	string map = string("mapSize = 5 10\n") + string("#####...##\n")
		+ string("#####...##\n") + string("#####...##\n")
		+ string("...........\n") + string("...........");
	istringstream iss(map);
	Init(iss);

	same_loc_obs_ = floor_.NumCells();
	obs_.resize(NumStates());
	for (int rob = 0; rob < floor_.NumCells(); rob++) {
		for (int opp = 0; opp < floor_.NumCells(); opp++) {
			int s = RobOppIndicesToStateIndex(rob, opp);
			obs_[s] = (rob == opp ? same_loc_obs_ : rob);
		}
	}
  robot_pos_unknown_ = false;
}