private static bool IsAllowSpetMiddlePattern(IList <Item> items, Item i, IList <Item> buffer, Axis axis, params Vector2[] offsets) { return(Tuple.Create(buffer, i) .MatchTo <Tuple <IList <Item>, Item>, Tuple <IList <Item>, Item> >() .Where(_ => _.Item1.Count > 0 && Abs(_.Item1[_.Item1.Count - 1].position[(int)axis] - _.Item2.position[(int)axis]) > 0.01f) .Return(_ => { // next row||col _.Item1.Clear(); return _; }) .Else(_ => _) .Result() .MatchTo <Tuple <IList <Item>, Item>, bool>() .Where(_ => _.Item1.Count == 0 || (_.Item1.Count == 1 && !SpriteEquals(_.Item1[0], _.Item2))) .Return(_ => UpdateBuffer(_.Item2, _.Item1)) .Where(_ => (_.Item1.Count == 1 && SpriteEquals(_.Item1[0], _.Item2)) || (_.Item1.Count == 2 && !SpriteEquals(_.Item1[0], _.Item2))) .Return(_ => UpdateBuffer(_.Item2, _.Item1, 0)) .Where(_ => _.Item1.Count == 2 && SpriteEquals(_.Item1[0], _.Item2)) .Return(_ => { UpdateBuffer(_.Item2, _.Item1, 0); return _.Item1[1].interactive && IsStepAllowed(items, _.Item1[1].sprite, _.Item1[0], offsets); }) .Else(_ => false) .Result()); }
private static bool CheckBoardGeneration(IList <Item> items, LevelBlueprint config) { return // Search if match3 line exist (!SearchItemInChaine(items, 3, Axis.X, Axis.X, Axis.Y).SelectMany(ls => ls.Slinq()) .Concat(SearchItemInChaine(items, 2, Axis.Y, Axis.Y, Axis.X).SelectMany(ls => ls.Slinq())) .Select(InitItem, config) .Aggregate(false, (b, item) => true) && // Search if steps avaliable !SearchItemInChaine(items, 2, Axis.X, Axis.X, Axis.Y) .Where((ls, _items) => IsStepAllowed(_items, ls[0].sprite, ls[0].position + Vector2.down, Vector2.right, Vector2.down, Vector2.left) || IsStepAllowed(_items, ls[ls.Count - 1].sprite, ls[ls.Count - 1].position + Vector2.up, Vector2.left, Vector2.up, Vector2.right), items) .SelectMany(ls => ls.Slinq()) .Concat(SearchItemInChaine(items, 2, Axis.Y, Axis.Y, Axis.X) .Where((ls, _items) => IsStepAllowed(_items, ls[0].sprite, ls[0].position + Vector2.left, Vector2.left, Vector2.up, Vector2.down) || IsStepAllowed(_items, ls[ls.Count - 1].sprite, ls[ls.Count - 1].position + Vector2.right, Vector2.right, Vector2.up, Vector2.down), items) .SelectMany(ls => ls.Slinq())) .Concat(items .Slinq() .OrderBy((i1, i2) => OrderBy(i1, i2, Axis.Y, Axis.X)) .Where( (i, t) => IsAllowSpetMiddlePattern(t.Item1, i, t.Item2, Axis.Y, Vector2.up, Vector2.down), Tuple.Create(items, new List <Item>()))) .Concat(items.Slinq().OrderBy((i1, i2) => OrderBy(i1, i2, Axis.X, Axis.Y)) .Where( (i, t) => IsAllowSpetMiddlePattern(t.Item1, i, t.Item2, Axis.X, Vector2.left, Vector2.right), Tuple.Create(items, new List <Item>()))) .Any() .ToSome() .Where(v => !v) .ForEach((v, _items) => _items .SlinqWithIndex() .Where(t => t.Item2 % 3 == 0) .Select(t => t.Item1) .ForEach((i, c) => InitItem(i, c), config) , items) .ValueOr(false)); }
private static bool IsStepAllowed(IList <Item> items, Sprite sprite, Item item, params Vector2[] offsets) { return(offsets .Slinq() .Where((o, allow) => allow, item.interactive) .Select((offset, position) => position + offset, item.position) .SelectMany(p => items.Slinq().Where(i => p.Equals(i.position))) .Any((i, t) => !t.Item1.Equals(i.position) && t.Item2.Equals(i.sprite), Tuple.Create(item.position, sprite))); }
public void AddPredicateAndAction(DelegateFunc <Option <T>, bool> predicate, Action <Option <T> > action) { _predicatesAndActions.Add(Tuple.Create(predicate, Either <Action <T>, Action <Option <T> > > .Right(action))); }