本文整理汇总了C#中Sequence.Convert方法的典型用法代码示例。如果您正苦于以下问题:C# Sequence.Convert方法的具体用法?C# Sequence.Convert怎么用?C# Sequence.Convert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sequence
的用法示例。
在下文中一共展示了Sequence.Convert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChooseAction
/// <summary>
/// Choose the next action from the given set of actions in the given state.
/// </summary>
internal Action ChooseAction(Sequence<Action> actions, IState state)
{
switch (policy)
{
case RewardPolicy.MaximumReward:
{
return GetActionsWithMaximumReward(actions, state).Choose();
}
default:
{
Converter<Action, int> weightOfAction =
delegate(Action a) { return GetWeight(state, a); };
Sequence<int> weights = actions.Convert<int>(weightOfAction);
//choose an action with probability proportional to its weight
int sum = weights.Tail.Reduce<int>(delegate(int x, int y) { return x + y; }, weights.Head);
int z = HashAlgorithms.GlobalChoiceController.Next(sum);
int tot = weights[0];
int i = 0;
while (z >= tot)
tot += weights[++i];
return actions[i];
}
}
}