public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type.IsSlicer());

            var mustSeek = tile.Type == EngineGlyphType.SlicerEnd && tile.TimesAccessed == 0;

            if (state.GetAndFlushInverting() && tile.TimesAccessed == 0)
            {
                mustSeek = true;
            }

            tile.TimesAccessed++;

            if (mustSeek)
            {
                while (!state.Position.IsBeginning)
                {
                    state.Position.MoveBackward();
                    if (state[state.Position].Type == EngineGlyphType.SlicerStart)
                    {
                        break;
                    }
                }
            }
            else
            {
                state.Position.MoveForward();
            }
        }
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
//            Contract.Assert(tile.Type == EngineGlyphType.Nothing);

            tile.TimesAccessed++;
            state.Position.MoveForward();
        }
Beispiel #3
0
        public void ParseTile(EngineTile tile)
        {
            Contract.Assert(_tileParsers.ContainsKey(tile.Type), $"Failed to find parser for {tile.Type}");
            var callback = _tileParsers[tile.Type];

            callback.Invoke(_state, tile);
        }
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type.IsNumeral());

            state.CurrentNumberGroup += StateParserUtils.GetNumeralValue(tile, state.GetAndFlushInverting());
            tile.TimesAccessed++;
            state.Position.MoveForward();
        }
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type == EngineGlyphType.ModifierInvert);

            tile.TimesAccessed++;
            state.Position.MoveForward();
            state.ToggleInverting();
        }
Beispiel #6
0
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type == EngineGlyphType.OperationMultiplier);

            StateParserUtils.PerformOperation(state);
            state.LastOperator = state.GetAndFlushInverting() ? EngineOperatorType.Division : EngineOperatorType.Multiplication;
            tile.TimesAccessed++;
            state.Position.MoveForward();
        }
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type.IsAction());

            StateParserUtils.PerformOperation(state);

            AddAction(state, GetActionType(tile, state.GetAndFlushInverting()));
            tile.TimesAccessed++;
            state.Position.MoveForward();
        }
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type.IsBomb());

            if (!state.GetAndFlushInverting())
            {
                state.Explode(1);
            }

            tile.TimesAccessed++;
            state.Position.MoveForward();
        }
Beispiel #9
0
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type == EngineGlyphType.ModifierIgnore);

            tile.TimesAccessed++;
            state.Position.MoveForward();
            if (!state.GetAndFlushInverting())
            {
                StateParserUtils.SkipEmptyTiles(state);
                state.Position.MoveForward();
            }
        }
Beispiel #10
0
        private EngineTile[,] CloneTiles(EngineTile[,] original)
        {
            var newTiles = new EngineTile[original.GetLength(0), original.GetLength(1)];

            for (var x = 0; x < original.GetLength(0); x++)
            {
                for (var y = 0; y < original.GetLength(1); y++)
                {
                    newTiles[x, y] = original[x, y].Clone();
                }
            }

            return(newTiles);
        }
        public void Explode(int range)
        {
            for (var x = Position.Position.X - range; x < Position.Position.X + range; x++)
            {
                for (var y = Position.Position.Y - range; y < Position.Position.Y + range; y++)
                {
                    if (!IsValidPosition(x, y))
                    {
                        continue;
                    }

                    Tiles[x, y] = new EngineTile(EngineGlyphType.Nothing);
                }
            }
        }
Beispiel #12
0
        public static void ParseTile(EngineParserState state, EngineTile tile)
        {
            Contract.Assert(tile.Type.IsCameleon());

            var baseDirection = tile.Type.GetDirection();
            var target        = FindTarget(state, state.GetAndFlushInverting() ? baseDirection.Opposite : baseDirection, 0);

            if (target == null)
            {
                state.Position.MoveForward();
            }
            else
            {
                target = new EngineTile(target.Type)
                {
                    TimesAccessed = tile.TimesAccessed
                };
                state.EngineParser.ParseTile(target);
            }
            tile.TimesAccessed++;
        }
        private static EngineActionType GetActionType(EngineTile tile, bool isInverted)
        {
            switch (tile.Type)
            {
            case EngineGlyphType.ActionMoveN:
            case EngineGlyphType.ActionMoveNE:
            case EngineGlyphType.ActionMoveE:
            case EngineGlyphType.ActionMoveSE:
            case EngineGlyphType.ActionMoveS:
            case EngineGlyphType.ActionMoveSW:
            case EngineGlyphType.ActionMoveW:
            case EngineGlyphType.ActionMoveNW:
                return(EngineActionType.MoveN + (tile.Type.GetDirection().Id + (isInverted ? 4 : 0)) % 8);

            case EngineGlyphType.ActionSpecial:
                return(EngineActionType.Special);

            default:
                throw new ArgumentException($"Can't be called with {tile.Type}");
            }
        }
        public static int GetNumeralValue(EngineTile tile, bool isInverting)
        {
            var multiplier = isInverting ? -1 : 1;

            switch (tile.Type)
            {
            case EngineGlyphType.NumeralOne:
                return(1 * multiplier);

            case EngineGlyphType.NumeralTwo:
                return(2 * multiplier);

            case EngineGlyphType.NumeralFour:
                return(4 * multiplier);

            case EngineGlyphType.NumeralEight:
                return(8 * multiplier);

            default:
                throw new ArgumentException($"Invalid tile type, Numeral expeced {tile.Type} given", nameof(tile));
            }
        }