Пример #1
0
        internal static bool Swap(this Stone[,] field, int2 lPos, int2 rPos)
        {
            if (field == null)
            {
                return(false);
            }
            if (!field.InRange(lPos) || !field.InRange(rPos))
            {
                return(false);
            }

            var ls = field.Get(lPos);
            var rs = field.Get(rPos);

            if (ls != null)
            {
                ls.position = rPos;
            }
            if (rs != null)
            {
                rs.position = lPos;
            }

            field.Set(rPos, ls);
            field.Set(lPos, rs);

            return(true);
        }
Пример #2
0
            public bool HasCombo(int2 pos, Stone[,] field)
            {
                var mp  = pos + _movePos;
                var op1 = pos + _otherPos1;
                var op2 = pos + _otherPos2;

                if (!field.InRange(pos))
                {
                    return(false);
                }
                if (!field.InRange(mp))
                {
                    return(false);
                }
                if (!field.InRange(op1))
                {
                    return(false);
                }
                if (!field.InRange(op2))
                {
                    return(false);
                }

                var color = field.Get(pos).color;

                if (color == field.Get(mp).color)
                {
                    return(false);
                }
                if (color != field.Get(op1).color)
                {
                    return(false);
                }
                if (color != field.Get(op2).color)
                {
                    return(false);
                }

                return(true);
            }
Пример #3
0
        private static IEnumerable <Stone> GetAllWithColor(Stone[,] field, Color color,
                                                           int2 startPos, int2 offset)
        {
            for (var pos = startPos; field.InRange(pos); pos += offset)
            {
                var stone = field.Get(pos);

                if (stone == null)
                {
                    yield break;
                }
                if (stone.color != color)
                {
                    yield break;
                }

                yield return(stone);
            }
        }