/// <summary> /// load file to memory /// </summary> /// <param name="fileDir"></param> public void load(string fileDir) { file.fileLoad(fileDir); int prevstate = -1; //set states for (int i = 0; i < file.commands.Count; ++i) { string tmp = file.commands[i]; int t = Convert.ToInt32(splite(tmp)[2]); if (Convert.ToInt32(splite(tmp)[0]) != prevstate) { states.Add(new State(Convert.ToInt32(splite(tmp)[0]), false)); } prevstate = Convert.ToInt32(splite(tmp)[0]); } //set final state out.. states.Add(new State(prevstate + 1, true)); //add transitions for (int i = 0; i < states.Count; ++i) { for (int j = 0; j < file.commands.Count; ++j) { string command = file.commands[j]; if (states[i].id == Convert.ToInt32(splite(command)[0])) { char read = char.Parse(splite(command)[1]); char write = char.Parse(splite(command)[3]); State.dir dir = moveDirection(splite(command)[4]); int index = Convert.ToInt32(splite(command)[2]); for (int x = 0; x < states.Count; ++x) { if (index == states[x].id) { index = x; break; } } State next = states[index]; states[i].addTransition(read, write, dir, next); } } } }
int moveDirection(State.dir str, int index) { if (str == State.dir.L) { index--; } if (str == State.dir.R) { index++; } if (str == State.dir.S) { } return(index); }