/// <summary> /// /// Updates the MovePicker's selection weights based on the results of a previous decision /// /// </summary> /// <param name="decision"></param> /// <param name="result"></param> public void Feedback(Decision decision, ResultType result) { int depth = decision.SelectionMethod.Depth; AnalysisMode mode = decision.SelectionMethod.Mode; int firstIndex = GetIndex(mode); MoveHistory assumedHistory = decision.AssumedHistory; Selector <MoveType> selectionTree = FindSelector(depth, mode, assumedHistory); switch (result) { case ResultType.Win: if (rewardWin) { selectionTree.Reward(decision.PickedMove); depthSelector.Reward(depth); if (depth > 1) { modeSelector.Reward(mode); } } else if (punishWin) { selectionTree.Punish(decision.PickedMove); depthSelector.Punish(depth); if (depth > 1) { modeSelector.Punish(mode); } } break; case ResultType.Loss: if (rewardLoss) { selectionTree.Reward(decision.PickedMove); depthSelector.Reward(depth); if (depth > 1) { modeSelector.Reward(mode); } } else if (punishLoss) { selectionTree.Punish(decision.PickedMove); depthSelector.Punish(depth); if (depth > 1) { modeSelector.Punish(mode); } } break; case ResultType.Draw: if (rewardDraw) { selectionTree.Reward(decision.PickedMove); depthSelector.Reward(depth); if (depth > 1) { modeSelector.Reward(mode); } } else if (punishDraw) { selectionTree.Punish(decision.PickedMove); depthSelector.Punish(depth); if (depth > 1) { modeSelector.Punish(mode); } } break; default: break; } }
/// <summary> /// /// Finds the selector associated with a set of decision factors /// /// </summary> /// <param name="depth">The number of previous rounds being analyzed</param> /// <param name="mode">The type of analysis being used to analyze previous rounds</param> /// <param name="assumedHistory">The collection of rounds available to be analyzed</param> /// <returns>The Selector associated with the input decision factors</returns> Selector <MoveType> FindSelector(int depth, AnalysisMode mode, MoveHistory assumedHistory) { int firstIndex = GetIndex(mode); // Find correct SelectionTree Selector <MoveType> selector = null; int secondIndex = -1; int thirdIndex = -1; int fourthIndex = -1; if (depth == 0) { selector = zeroMoveTree; } else { switch (mode) { case AnalysisMode.PlayerAbsolute: secondIndex = GetIndex(assumedHistory.Rounds[0].PlayerAbsolute); if (depth > 1) { thirdIndex = GetIndex(assumedHistory.Rounds[1].PlayerAbsolute); } if (depth > 2) { fourthIndex = GetIndex(assumedHistory.Rounds[2].PlayerAbsolute); } break; case AnalysisMode.PlayerRelative: secondIndex = GetIndex(assumedHistory.Rounds[0].PlayerRelative); if (depth > 1) { thirdIndex = GetIndex(assumedHistory.Rounds[1].PlayerRelative); } if (depth > 2) { fourthIndex = GetIndex(assumedHistory.Rounds[2].PlayerRelative); } break; case AnalysisMode.OpponentAbsolute: secondIndex = GetIndex(assumedHistory.Rounds[0].OpponentAbsolute); if (depth > 1) { thirdIndex = GetIndex(assumedHistory.Rounds[1].OpponentAbsolute); } if (depth > 2) { fourthIndex = GetIndex(assumedHistory.Rounds[2].OpponentAbsolute); } break; case AnalysisMode.OpponentRelative: secondIndex = GetIndex(assumedHistory.Rounds[0].OpponentRelative); if (depth > 1) { thirdIndex = GetIndex(assumedHistory.Rounds[1].OpponentRelative); } if (depth > 2) { fourthIndex = GetIndex(assumedHistory.Rounds[2].OpponentRelative); } break; case AnalysisMode.Result: secondIndex = GetIndex(assumedHistory.Rounds[0].Result); if (depth > 1) { thirdIndex = GetIndex(assumedHistory.Rounds[1].Result); } if (depth > 2) { fourthIndex = GetIndex(assumedHistory.Rounds[2].Result); } break; default: throw new InvalidOperationException("FindSelector couldn't resolve AnalysisMode enumeration."); } if (depth == 1) { selector = oneMoveTree[firstIndex, secondIndex]; } else if (depth == 2) { selector = twoMoveTree[firstIndex, secondIndex, thirdIndex]; } else if (depth == 3) { selector = threeMoveTree[firstIndex, secondIndex, thirdIndex, fourthIndex]; } } return(selector); }
public MoveHistory(MoveHistory source) { maxLength = source.maxLength; Rounds = new List <Round>(source.Rounds); }