int GetRandomGem() { // Get the next sequence if (m_lSequence.Count <= m_nSequenceIndex) { m_mSequenceGemTypeMap.Clear(); m_nSequenceIndex = 0; m_lSequence = m_SpawnPattern.GetSequence(m_nLevel, ref m_nSequenceIndexFromList); // Determine gem type while (m_mSequenceGemTypeMap.Count != m_nGemTypeNum) { // Get a range excluding these numbers var range = Enumerable.Range(0, m_nGemTypeNum).Where(i => !m_mSequenceGemTypeMap.Contains(i)); // On assumption 'LOOKBACK_NUM < LANE_NUM' var rand = new System.Random(); int index = rand.Next(0, m_nGemTypeNum - m_mSequenceGemTypeMap.Count); int gemType = range.ElementAt(index); m_mSequenceGemTypeMap.Add(gemType); } /* * string log = "[ "; * for ( int j = 0; j < m_mSequenceGemTypeMap.Count; ++j ) * { * log += m_mSequenceGemTypeMap[j] + " "; * } * log += "]"; * Debug.Log( "Gem type map: " + log ); */ } int gemMapKey = m_lSequence[m_nSequenceIndex]; m_nSequenceIndex++; return(m_mSequenceGemTypeMap[gemMapKey]); // Old /* * bool random = true; * * if ( m_PreviousGems.Count > 0 ) * { * random = ( m_PreviousGems.Count == 1 && m_nTotalGemCount < 3 ) ? Random.Range( 0, m_nGemTypeNum - 1 ) == 0 : false; * } * * int gem = ( random ) ? Random.Range( 0, m_nGemTypeNum ) : m_PreviousGems[0]; * * // If linkable, don't need to force generate same gem the next time round * if ( m_aGemCount[gem] + 1 >= 3 ) * { * m_PreviousGems.Remove( gem ); * } * else * { * if( !m_PreviousGems.Contains( gem ) ) * { * m_PreviousGems.Add( gem ); * } * } * * return gem; */ }