示例#1
0
        public GameDataInterop.GameState.BoardMoveSequence Debug_GenRandomMoveSequence(int nNumMoves)
        {
            VLRTech.Util.Checks.Runtime.AssertThrow(nNumMoves >= 0);

            Random oRandomGenerator = new Random();

            GameDataInterop.GameState.BoardMoveSequence oBoardMoveSequence = new GameDataInterop.GameState.BoardMoveSequence();
            GameDataInterop.CellIndex oStartCellIndex = new GameDataInterop.CellIndex {
                m_nColumn = oRandomGenerator.Next(0, m_GameLevelState.m_BoardState.GetNumColumns()), m_nRow = oRandomGenerator.Next(0, m_GameLevelState.m_BoardState.GetNumRows())
            };

            oBoardMoveSequence.m_StartCellIndex = oStartCellIndex;

            Array oSwapDirectionArray = Enum.GetValues(typeof(GameDataInterop.GameState.EDirection));

            for (int i = 0; i < nNumMoves; i++)
            {
                GameDataInterop.BoardElement oBoardElement_Start = m_GameLevelState.m_BoardState.GetBoardElementByCellIndex(oStartCellIndex);
                VLRTech.Util.Checks.Runtime.AssertThrow(oBoardElement_Start.IsValidNonTransientToken());

                GameDataInterop.GameState.EDirection eSwapDirection = GameDataInterop.GameState.EDirection.Unknown;
                while (true)
                {
                    // Note: Using '1' as lower bound, to skip 'Unknown' enum value
                    GameDataInterop.GameState.EDirection eSwapDirection_Potential = (GameDataInterop.GameState.EDirection)oSwapDirectionArray.GetValue(oRandomGenerator.Next(1, oSwapDirectionArray.GetLength(0)));
                    GameDataInterop.BoardElement         oBoardElement_SwapTarget = m_GameLevelState.m_BoardState.GetBoardElementByCellIndex(oBoardElement_Start.m_CellIndex.GetNeighboringCellIndex(eSwapDirection_Potential));
                    if (oBoardElement_SwapTarget.IsOutOfBounds())
                    {
                        continue;
                    }

                    // Found a valid swap
                    eSwapDirection = eSwapDirection_Potential;
                    break;
                }

                GameDataInterop.GameState.BoardMoveStep oMoveStep = new GameDataInterop.GameState.BoardMoveStep
                {
                    m_StartCellIndex = oStartCellIndex,
                    m_eDirection     = eSwapDirection,
                };
                oBoardMoveSequence.m_oMoveStepList.Add(oMoveStep);

                // Update start cell index to new move target
                oStartCellIndex = m_GameLevelState.m_BoardState.GetBoardElementByCellIndex(oBoardElement_Start.m_CellIndex.GetNeighboringCellIndex(eSwapDirection)).m_CellIndex;
            }

            return(oBoardMoveSequence);
        }
示例#2
0
        public GameDataInterop.GameState.BoardMoveResult ExecuteBoardMoveSequence_Complete(GameDataInterop.BoardState oBoardState, GameDataInterop.GameState.BoardMoveSequence oBoardMoveSequence)
        {
            GameDataInterop.GameState.BoardMoveResult oBoardMoveResult = new GameDataInterop.GameState.BoardMoveResult();

            // TODO: Copy board state, so we can leave unmodified in the event of an error while processing the move

            // Execute the move sequence
            // Check correctness of move sequence as we go

            GameDataInterop.CellIndex oCurrentCellIndex = oBoardMoveSequence.m_StartCellIndex;

            foreach (var oMoveStep in oBoardMoveSequence.m_oMoveStepList)
            {
                VLRTech.Util.Checks.Runtime.AssertThrow(oCurrentCellIndex.Equals(oMoveStep.m_StartCellIndex));

                ExecuteBoardMoveStep_BoardUpdateOnly(oBoardState, oMoveStep);

                oCurrentCellIndex = oCurrentCellIndex.GetNeighboringCellIndex(oMoveStep.m_eDirection);
            }

            // Collect initial matches

            List <GameDataInterop.GameState.BoardGemMatch> oBoardMatchList = m_GameLevelState.m_BoardProcessing.FindAllMatches(oBoardState);

            oBoardMoveResult.m_oBoardMatchList_PreCascade = oBoardMatchList;

            int nCascadeIteration = 0;

            while (true)
            {
                // Initial check, in case we didn't produce any pre-cascade matches
                if (oBoardMatchList.Count() == 0)
                {
                    break;
                }

                ++nCascadeIteration;

                ExecuteBoardClearMatches(oBoardState, oBoardMatchList);
                ExecuteBoardCascade_Consolidate(oBoardState);
                ExecuteBoardCascade_Skyfall(oBoardState);

                oBoardMatchList = m_GameLevelState.m_BoardProcessing.FindAllMatches(oBoardState);
                if (oBoardMatchList.Count() == 0)
                {
                    // We're done
                    break;
                }

                if (oBoardMoveResult.m_oBoardMatchList_PostCascade == null)
                {
                    oBoardMoveResult.m_oBoardMatchList_PostCascade = new List <GameDataInterop.GameState.BoardGemMatch>();
                }

                // Mark all matches in this generation with the applicable iteration number,
                // and add to results list
                foreach (var oBoardGemMatch in oBoardMatchList)
                {
                    oBoardGemMatch.m_nCascadeIteration = nCascadeIteration;
                    oBoardMoveResult.m_oBoardMatchList_PostCascade.Add(oBoardGemMatch);
                }
            }

            // TODO: Calculate point total

            return(oBoardMoveResult);
        }