本文整理汇总了C#中Field.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# Field.Apply方法的具体用法?C# Field.Apply怎么用?C# Field.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field.Apply方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFields
public IEnumerable<Field> GetFields(Field field, Block current)
{
// If not enough space, try these too.
if (field.FirstFilled < 4)
{
foreach (var candidate in GetEndgamePaths(field, current))
{
yield return candidate.Field;
}
}
else
{
foreach (var candidate in GetReachableHoles(field, current))
{
yield return candidate.Field;
}
foreach (var block in current.Variations)
{
int minRow = block.GetMinRow(field);
int maxRow = block.GetMaxRow(field);
foreach (var col in block.GetColumns(field))
{
for (var row = minRow; row <= maxRow; row++)
{
var test = field.Test(block, col, row);
if (test == Field.TestResult.True)
{
var target = new Position(col, row);
var applied = field.Apply(block, target);
yield return applied;
}
if (test != Field.TestResult.Retry)
{
row = short.MaxValue;
}
}
}
}
}
if (field.Skips > 0)
{
yield return field.SkipBlock();
}
}
示例2: TurnRight
private static void TurnRight(string[] exp, Block block, Position position, Field field)
{
var act = new string[5];
act[0] = field.Apply(block, position).ToString();
for (var i = 1; i < 5; i++)
{
position = block.TurnRight(position);
block = block.TurnRight();
var apply = field.Apply(block, position).ToString();
act[i] = apply;
Console.WriteLine(apply.Replace("|", Environment.NewLine));
Console.WriteLine();
}
foreach (var f in act)
{
Console.WriteLine('"' + f + '"' + ',');
}
CollectionAssert.AreEqual(exp, act);
}
示例3: CopyTo
public virtual void CopyTo(Field field)
{
field.Apply(this);
if (this.Validator != null)
{
field.Validator.Fn = this.Validator;
}
}
示例4: GetPaths
public static IEnumerable<MoveCandiate> GetPaths(Field field, Block current, int[] targets, int maxRow)
{
var dones = new bool[current.RotationVariations.Length, field.RowCount + 1, 10];
TempPath first = current.GetFirstTempPath(field.FirstFilled);
dones[0, first.Position.Row + 1, first.Position.Col] = true;
var stack = new Stack<TempPath>();
stack.Push(first);
while (stack.Count != 0)
{
var temp = stack.Pop();
if (temp.Position.Row > maxRow) { continue; }
var test = field.Test(temp.Block, temp.Position);
// No reason the investigate
if (test == Field.TestResult.False) { continue; }
var tr = temp.TurnRight();
if (tr.Position.Col >= 0 && tr.Position.Col <= tr.Block.ColumnMaximum &&
!dones[(int)tr.Block.Rotation, tr.Position.Row + 1, tr.Position.Col])
{
dones[(int)tr.Block.Rotation, tr.Position.Row + 1, tr.Position.Col] = true;
stack.Push(tr);
}
var tl = temp.TurnLeft();
if (tl.Position.Col >= 0 && tl.Position.Col <= tl.Block.ColumnMaximum &&
!dones[(int)tl.Block.Rotation, tl.Position.Row + 1, tl.Position.Col])
{
dones[(int)tl.Block.Rotation, tl.Position.Row + 1, tl.Position.Col] = true;
stack.Push(tl);
}
if (temp.Position.Col < temp.Block.ColumnMaximum && !dones[(int)temp.Block.Rotation, temp.Position.Row + 1, temp.Position.Col + 1])
{
dones[(int)temp.Block.Rotation, temp.Position.Row + 1, temp.Position.Col + 1] = true;
stack.Push(temp.Right());
}
if (temp.Position.Col > 0 && !dones[(int)temp.Block.Rotation, temp.Position.Row + 1, temp.Position.Col - 1])
{
dones[(int)temp.Block.Rotation, temp.Position.Row + 1, temp.Position.Col - 1] = true;
stack.Push(temp.Left());
}
// we have a fit.
if (test == Field.TestResult.True)
{
if (temp.Block.TouchPosition(temp.Position, targets))
{
var unique = temp.Block.Variations.Length == temp.Block.RotationVariations.Length;
// if the block is rotation only, first check if counter part did not arrive already.
if (!unique)
{
var rot_org = (int)temp.Block.Rotation & 1;
var rot_acc = rot_org | 2;
unique =
dones[rot_org, temp.Position.Row + 1, temp.Position.Col] ^
dones[rot_acc, temp.Position.Row + 1, temp.Position.Col];
}
if (unique)
{
var apply = field.Apply(temp.Block, temp.Position);
yield return new MoveCandiate(temp.Path, apply);
}
}
}
else
{
if (!dones[(int)temp.Block.Rotation, temp.Position.Row + 2, temp.Position.Col])
{
dones[(int)temp.Block.Rotation, temp.Position.Row + 2, temp.Position.Col] = true;
stack.Push(temp.Down());
}
}
}
}