/// <summary> /// Get `Mutationfactor` for the state-action /// </summary> /// <param name="s">For the game state</param> /// <param name="a">For the action</param> /// <returns>The mutation factor's value</returns> protected uint getMutationVal(GameState s, Direction a) { if (this.PrevMutationfactor.Key == null) return 0; var key = new SAPair(s, a); if (this.PrevMutationfactor.Key.GetHashCode() == key.GetHashCode()) return this.PrevMutationfactor.Value; return 0; }
/// <summary> /// Calculates the `Q` value /// </summary> /// <param name="s">For the game state</param> /// <param name="a">For the action</param> /// <returns>The `Q` value</returns> protected float getQVal(GameState s, Direction a) { var key = new SAPair(s, a).GetHashCode(); #if __USE_PREPROCESSED_Q__ if (!this._Q.ContainsKey(key)) { float q = 0; var ns = this.getNextState(s, a); if (a == Direction.EAST) { if (ns.IsBallMine) q += 5.0F; else q -= 5.0F; } if (ns.Game_State == GameState.State.OPPONENT_SCORED) q = float.NegativeInfinity; if (ns.Game_State == GameState.State.PLAYER_SCORED) q = float.PositiveInfinity; this.updateQ(s, a, q); } // if making an own-goal if (this.IsInFrontOfGate(s, false) && s.IsBallMine) { if(a == Direction.WEST) this.updateQ(s, a, float.NegativeInfinity); } if (this.IsInFrontOfGate(s, true) && s.IsBallMine) { switch (a) { case Direction.EAST: this.updateQ(s, a, float.PositiveInfinity); break; case Direction.HOLD: this.updateQ(s, a, +100); break; default: this.updateQ(s, a, float.NegativeInfinity); break; } } #endif if (this._Q.ContainsKey(key)) return _Q[key]; return 0; }
/// <summary> /// Updates the `Mutationfactor` table /// </summary> /// <param name="s">The game state</param> /// <param name="a">The action</param> /// <param name="val">The mutation factor's value</param> protected void updateMutaionFactor(GameState s, Direction a) { var key = new SAPair(s, a); uint val = 0; if (this.PrevMutationfactor.Key != null && this.PrevMutationfactor.Key.GetHashCode() == key.GetHashCode()) val = this.PrevMutationfactor.Value + 1; this.PrevMutationfactor = new KeyValuePair<SAPair, uint>(key, val); }
/// <summary> /// Updates the `Q` table /// </summary> /// <param name="s">The game state</param> /// <param name="a">The action</param> /// <param name="val">The value of state-action</param> protected void updateQ(GameState s, Direction a, float val) { var key = new SAPair(s, a).GetHashCode(); if (this._Q.ContainsKey(key)) this._Q[key] = val; else this._Q.Add(key, val); }