public bool AddCommand(string s, int q, MCommand command) { if (!_tacts.ContainsKey(q)) { _tacts.Add(q, new Dictionary <string, MCommand>()); } if (!_tacts[q].ContainsKey(s)) { _tacts[q].Add(s, command); return(true); } return(false); }
void ExecuteCommand(MCommand command) { for (int i = 0; i < _words.Count; i++) { _words[i][_indexes[i]] = command.symbols.ToCharArray()[i]; if (_words[i].Count == 1) { _words[i].Insert(0, ' '); _indexes[i]++; _words[i].Add(' '); } switch (command.direct[i]) { case Direct.R: _indexes[i]--; if (_indexes[i] == 0) { _words[i].Insert(0, ' '); _indexes[i]++; } break; case Direct.L: _indexes[i]++; if (_indexes[i] == _words[i].Count) { _words[i].Add(' '); } break; case Direct.N: break; default: throw new Exception("invalid direct"); } } _q = command.q; if (_q == 0) { return; } List <char> word = new List <char>(); for (int i = 0; i < _words.Count; i++) { word.Add(_words[i][_indexes[i]]); } ExecuteCommand(_tacts[_q][new string(word.ToArray())]); }