本文整理汇总了C#中HashSet.Average方法的典型用法代码示例。如果您正苦于以下问题:C# HashSet.Average方法的具体用法?C# HashSet.Average怎么用?C# HashSet.Average使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashSet
的用法示例。
在下文中一共展示了HashSet.Average方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var collection = new HashSet<double> { 5.2, 8, -3.14, 0, 55 };
Console.WriteLine(collection.Sum());
Console.WriteLine(collection.Product());
Console.WriteLine(collection.Min());
Console.WriteLine(collection.Max());
Console.WriteLine(collection.Average());
}
示例2: GetDefensiveThreatFromPlanets
public float GetDefensiveThreatFromPlanets(List<Planet> planets)
{
if (this.DefenseDict.Count == 0)
return 0;
HashSet<SystemCommander> scoms = new HashSet<SystemCommander>();
foreach(Planet planet in planets)
{
SystemCommander temp =null;
if(this.DefenseDict.TryGetValue(planet.system,out temp))
{
scoms.Add(temp);
}
}
return scoms.Average(defense => defense.RankImportance);
}
示例3: Collapse
//.........这里部分代码省略.........
// var nodeInputs =
// outputs.Where(output => output.Item3.Item2 == outerNode)
// .Select(
// output =>
// new
// {
// InnerNodeInputSender = output.Item1,
// OuterNodeInPortData = output.Item3.Item1
// })
// .ToList();
// nodeInputs.ForEach(_ => node.AddInput());
// node.RegisterAllPorts();
// return
// new
// {
// OuterNode = outerNode,
// InnerNode = node,
// Outputs =
// inputs.Where(
// input => input.Item3.Item2 == outerNode)
// .Select(input => input.Item3.Item1),
// Inputs = nodeInputs,
// OuterNodePortDataList = inPortsConnected
// };
// }).ToList();
#endregion
#region UI Positioning Calculations
double avgX = selectedNodeSet.Average(node => node.X);
double avgY = selectedNodeSet.Average(node => node.Y);
double leftMost = selectedNodeSet.Min(node => node.X);
double topMost = selectedNodeSet.Min(node => node.Y);
double rightMost = selectedNodeSet.Max(node => node.X + node.Width);
double leftShift = leftMost - 250;
#endregion
#region Handle full selected connectors
// Step 2: Determine all the connectors whose start/end owners are
// both in the selection set, and then move them from the current
// workspace into the new workspace.
var fullySelectedConns = new HashSet<ConnectorModel>(
currentWorkspace.Connectors.Where(
conn =>
{
bool startSelected = selectedNodeSet.Contains(conn.Start.Owner);
bool endSelected = selectedNodeSet.Contains(conn.End.Owner);
return startSelected && endSelected;
}));
foreach (var connector in fullySelectedConns)
{
undoRecorder.RecordDeletionForUndo(connector);
connector.Delete();
}
#endregion
示例4: Weights
static Weights()
{
try
{
Items = new HashSet<Item>
{
new Item(
"killable", "AA Killable", 20, false,
t => t.Health < ObjectManager.Player.GetAutoAttackDamage(t, true) ? 10 : 0),
new Item(
"attack-damage", "Attack Damage", 10, false, delegate(Obj_AI_Hero t)
{
var ad = t.FlatPhysicalDamageMod;
ad += ad / 100 * (t.Crit * 100) * (t.HasItem(ItemData.Infinity_Edge.Id) ? 2.5f : 2f);
var averageArmor = GameObjects.AllyHeroes.Average(a => a.Armor) *
t.PercentArmorPenetrationMod - t.FlatArmorPenetrationMod;
return (ad * (100 / (100 + (averageArmor > 0 ? averageArmor : 0)))) * t.AttackSpeedMod;
}),
new Item(
"ability-power", "Ability Power", 10, false, delegate(Obj_AI_Hero t)
{
var averageMr = GameObjects.AllyHeroes.Average(a => a.SpellBlock) *
t.PercentMagicPenetrationMod - t.FlatMagicPenetrationMod;
return t.FlatMagicDamageMod * (100 / (100 + (averageMr > 0 ? averageMr : 0)));
}),
new Item(
"low-resists", "[i] Resists", 6, true,
t =>
ObjectManager.Player.FlatPhysicalDamageMod >= ObjectManager.Player.FlatMagicDamageMod
? t.Armor
: t.SpellBlock),
new Item("low-health", "[i] Health", 8, true, t => t.Health),
new Item("short-distance", "[i] Distance", 7, true, t => t.Distance(ObjectManager.Player)),
new Item(
"team-focus", "Team Focus", 3, false,
t =>
Aggro.Items.Where(a => a.Value.Target.Hero.NetworkId == t.NetworkId)
.Select(a => a.Value.Value)
.DefaultIfEmpty(0)
.Sum()),
new Item(
"focus-me", "Focus Me", 3, false, delegate(Obj_AI_Hero t)
{
var entry = Aggro.GetSenderTargetEntry(t, ObjectManager.Player);
return entry != null ? entry.Value + 1f : 0;
}),
new Item(
"hard-cc", "Hard CCed", 5, false, delegate(Obj_AI_Hero t)
{
var buffs =
t.Buffs.Where(
x =>
x.Type == BuffType.Charm || x.Type == BuffType.Knockback ||
x.Type == BuffType.Suppression || x.Type == BuffType.Fear ||
x.Type == BuffType.Taunt || x.Type == BuffType.Stun).ToList();
return buffs.Any() ? buffs.Max(x => x.EndTime) + 1f : 0f;
}),
new Item(
"soft-cc", "Soft CCed", 5, false, delegate(Obj_AI_Hero t)
{
var buffs =
t.Buffs.Where(
x =>
x.Type == BuffType.Slow || x.Type == BuffType.Silence ||
x.Type == BuffType.Snare || x.Type == BuffType.Polymorph).ToList();
return buffs.Any() ? buffs.Max(x => x.EndTime) + 1f : 0f;
}) /*,
new Item(
"gold", "Gold", 7, false,
t =>
(t.MinionsKilled + t.NeutralMinionsKilled) * 22.35f + t.ChampionsKilled * 300f +
t.Assists * 95f)*/ //Bug: Bugsplatting currently
};
Average = (float) Items.Average(w => w.Weight);
MaxRange = 2000f;
}
catch (Exception ex)
{
Global.Logger.AddItem(new LogItem(ex));
}
}
示例5: Collapse
//.........这里部分代码省略.........
var nodeInputs =
outputs.Where(output => output.Item3.Item2 == outerNode)
.Select(
output =>
new
{
InnerNodeInputSender = output.Item1,
OuterNodeInPortData = output.Item3.Item1
})
.ToList();
nodeInputs.ForEach(_ => node.AddInput());
node.RegisterAllPorts();
return
new
{
OuterNode = outerNode,
InnerNode = node,
Outputs =
inputs.Where(
input => input.Item3.Item2 == outerNode)
.Select(input => input.Item3.Item1),
Inputs = nodeInputs,
OuterNodePortDataList = inPortsConnected
};
}).ToList();
#endregion
#region UI Positioning Calculations
double avgX = selectedNodeSet.Average(node => node.X);
double avgY = selectedNodeSet.Average(node => node.Y);
double leftMost = selectedNodeSet.Min(node => node.X);
double topMost = selectedNodeSet.Min(node => node.Y);
double rightMost = selectedNodeSet.Max(node => node.X + node.Width);
#endregion
#region Handle full selected connectors
// Step 2: Determine all the connectors whose start/end owners are
// both in the selection set, and then move them from the current
// workspace into the new workspace.
var fullySelectedConns =
new HashSet<ConnectorModel>(
currentWorkspace.Connectors.Where(
conn =>
{
bool startSelected = selectedNodeSet.Contains(conn.Start.Owner);
bool endSelected = selectedNodeSet.Contains(conn.End.Owner);
return startSelected && endSelected;
}));
foreach (var ele in fullySelectedConns)
{
undoRecorder.RecordDeletionForUndo(ele);
currentWorkspace.Connectors.Remove(ele);
}
#endregion
示例6: Collapse
//.........这里部分代码省略.........
selectedNodeSet.Contains(
outerNode.Inputs[x].Item2))
.ToList();
var nodeInputs = outputs
.Where(output => output.Item3.Item2 == outerNode)
.Select(
output =>
new
{
InnerNodeInputSender = output.Item1,
OuterNodeInPortData = output.Item3.Item1
}).ToList();
nodeInputs.ForEach(_ => node.AddInput());
node.RegisterAllPorts();
return new
{
OuterNode = outerNode,
InnerNode = node,
Outputs = inputs.Where(input => input.Item3.Item2 == outerNode)
.Select(input => input.Item3.Item1),
Inputs = nodeInputs,
OuterNodePortDataList = inPortsConnected
};
}).ToList();
#endregion
#region UI Positioning Calculations
double avgX = selectedNodeSet.Average(node => node.X);
double avgY = selectedNodeSet.Average(node => node.Y);
double leftMost = selectedNodeSet.Min(node => node.X);
double topMost = selectedNodeSet.Min(node => node.Y);
double rightMost = selectedNodeSet.Max(node => node.X + node.Width);
#endregion
#region Move selection to new workspace
var connectors = new HashSet<ConnectorModel>(currentWorkspace.Connectors.Where(
conn => selectedNodeSet.Contains(conn.Start.Owner)
&& selectedNodeSet.Contains(conn.End.Owner)));
//Step 2: move all nodes to new workspace
// remove from old
foreach (var ele in selectedNodeSet)
{
ele.SaveResult = false;
currentWorkspace.Nodes.Remove(ele);
ele.WorkSpace = newNodeWorkspace;
}
foreach (var ele in connectors)
{
currentWorkspace.Connectors.Remove(ele);
}
// add to new
newNodeWorkspace.Nodes.AddRange(selectedNodeSet);
newNodeWorkspace.Connectors.AddRange(connectors);
double leftShift = leftMost - 250;
示例7: Collapse
//.........这里部分代码省略.........
.ToList();
var nodeInputs = outputs
.Where(output => output.Item3.Item2 == outerNode)
.Select(
output =>
new
{
InnerNodeInputSender = output.Item1,
OuterNodeInPortData = output.Item3.Item1
}).ToList();
nodeInputs.ForEach(_ => node.AddInput());
node.NodeUI.RegisterAllPorts();
dynSettings.Bench.WorkBench.UpdateLayout();
return new
{
OuterNode = outerNode,
InnerNode = node,
Outputs = inputs.Where(input => input.Item3.Item2 == outerNode)
.Select(input => input.Item3.Item1),
Inputs = nodeInputs,
OuterNodePortDataList = inPortsConnected
};
}).ToList();
#endregion
#region UI Positioning Calculations
double avgX = selectedNodeSet.Average(node => Canvas.GetLeft(node.NodeUI));
double avgY = selectedNodeSet.Average(node => Canvas.GetTop(node.NodeUI));
double leftMost = selectedNodeSet.Min(node => Canvas.GetLeft(node.NodeUI)) + 24;
double topMost = selectedNodeSet.Min(node => Canvas.GetTop(node.NodeUI));
double rightMost = selectedNodeSet.Max(node => Canvas.GetLeft(node.NodeUI) + node.NodeUI.Width);
#endregion
#region Move selection to new workspace
var connectors = new HashSet<dynConnector>(
currentWorkspace.Connectors.Where(
conn => selectedNodeSet.Contains(conn.Start.Owner.NodeLogic)
&& selectedNodeSet.Contains(conn.End.Owner.NodeLogic)));
//Step 2: move all nodes to new workspace
// remove from old
currentWorkspace.Nodes.RemoveAll(selectedNodeSet.Contains);
currentWorkspace.Connectors.RemoveAll(connectors.Contains);
// add to new
newNodeWorkspace.Nodes.AddRange(selectedNodeSet);
newNodeWorkspace.Connectors.AddRange(connectors);
double leftShift = leftMost - 250;
foreach (dynNodeUI node in newNodeWorkspace.Nodes.Select(x => x.NodeUI))
{
Canvas.SetLeft(node, Canvas.GetLeft(node) - leftShift);
Canvas.SetTop(node, Canvas.GetTop(node) - topMost + 120);
}
#endregion
示例8: NodeFromSelection
internal void NodeFromSelection(IEnumerable<dynNode> selectedNodes)
{
var selectedNodeSet = new HashSet<dynNode>(selectedNodes);
#region Prompt
//First, prompt the user to enter a name
string newNodeName, newNodeCategory;
string error = "";
do
{
var dialog = new FunctionNamePrompt(Bench.addMenuCategoryDict.Keys, error);
if (dialog.ShowDialog() != true)
{
return;
}
newNodeName = dialog.Text;
newNodeCategory = dialog.Category;
if (FunctionDict.ContainsKey(newNodeName))
{
error = "A function with this name already exists.";
}
else if (newNodeCategory.Equals(""))
{
error = "Please enter a valid category.";
}
else
{
error = "";
}
}
while (!error.Equals(""));
var newNodeWorkspace = NewFunction(newNodeName, newNodeCategory, false);
#endregion
CurrentSpace.DisableReporting();
#region UI Positioning Calculations
var avgX = selectedNodeSet.Average(node => Canvas.GetLeft(node.NodeUI));
var avgY = selectedNodeSet.Average(node => Canvas.GetTop(node.NodeUI));
var leftMost = selectedNodeSet.Min(node => Canvas.GetLeft(node.NodeUI));
var topMost = selectedNodeSet.Min(node => Canvas.GetTop(node.NodeUI));
var rightMost = selectedNodeSet.Max(node => Canvas.GetLeft(node.NodeUI) + node.NodeUI.Width);
#endregion
#region Determine Inputs and Outputs
//Step 1: determine which nodes will be inputs to the new node
var inputs = new HashSet<Tuple<dynNode, int, Tuple<int, dynNode>>>(
selectedNodeSet.SelectMany(
node => Enumerable.Range(0, node.InPortData.Count).Where(node.HasInput).Select(
data => Tuple.Create(node, data, node.Inputs[data])).Where(
input => !selectedNodeSet.Contains(input.Item3.Item2))));
var outputs = new HashSet<Tuple<dynNode, int, Tuple<int, dynNode>>>(
selectedNodeSet.SelectMany(
node => Enumerable.Range(0, node.OutPortData.Count).Where(node.HasOutput).SelectMany(
data => node.Outputs[data]
.Where(output => !selectedNodeSet.Contains(output.Item2))
.Select(output => Tuple.Create(node, data, output)))));
#endregion
#region Detect 1-node holes (higher-order function extraction)
var curriedNodeArgs =
new HashSet<dynNode>(
inputs
.Select(x => x.Item3.Item2)
.Intersect(outputs.Select(x => x.Item3.Item2)))
.Select(
outerNode =>
{
var node = new dynApply1();
var nodeUI = node.NodeUI;
NodeNameAttribute elNameAttrib = node.GetType().GetCustomAttributes(typeof(NodeNameAttribute), true)[0] as NodeNameAttribute;
if (elNameAttrib != null)
{
nodeUI.NickName = elNameAttrib.Name;
}
nodeUI.GUID = Guid.NewGuid();
//store the element in the elements list
newNodeWorkspace.Nodes.Add(node);
node.WorkSpace = newNodeWorkspace;
node.DisableReporting();
Bench.WorkBench.Children.Add(nodeUI);
//Place it in an appropriate spot
Canvas.SetLeft(nodeUI, Canvas.GetLeft(outerNode.NodeUI));
Canvas.SetTop(nodeUI, Canvas.GetTop(outerNode.NodeUI));
//Fetch all input ports
// in order
//.........这里部分代码省略.........