public float this[State s, Action a] { get { if (this.Set.ContainsKey(s)) return this.Set[s][a]; return 0; } set { if (this.Set.ContainsKey(s)) { this.Set[s][a] = value; } else { QSetItem newItem = new QSetItem(); newItem[a] = value; this.Set.Add(s, newItem); } } }
public void Add(State s, QSetItem item) { this.Set.Add(s, item); }
//file format: //1 int (state) //5 floats (5 Q-values for the actions) /// <summary> /// Loads a Q-learning file containing Q-values. /// </summary> /// <param name="filename">The path of the Q-learning file.</param> public void LoadFile(string filename) { FileStream fs = File.Open(filename, FileMode.OpenOrCreate); BinaryReader br = new BinaryReader(fs); while (fs.Position < fs.Length) { State state = new State(br.ReadUInt64()); QSetItem newItem = new QSetItem(); newItem[Action.North] = br.ReadSingle(); newItem[Action.South] = br.ReadSingle(); newItem[Action.East] = br.ReadSingle(); newItem[Action.West] = br.ReadSingle(); newItem[Action.None] = br.ReadSingle(); this.store.Add(state, newItem); } br.Close(); fs.Close(); }