当前位置: 首页>>代码示例>>C#>>正文


C# Move.AddLetterToPut方法代码示例

本文整理汇总了C#中Move.AddLetterToPut方法的典型用法代码示例。如果您正苦于以下问题:C# Move.AddLetterToPut方法的具体用法?C# Move.AddLetterToPut怎么用?C# Move.AddLetterToPut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Move的用法示例。


在下文中一共展示了Move.AddLetterToPut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AnalyzeMove

        /// <summary>
        /// Analyzes the move: which letter are need to put, calcul score
        /// Load these new "advance" information to input parametr M.
        /// </summary>
        /// <returns>
        /// Is move correct?
        /// </returns>
        /// <param name='M'>
        /// Class Move with basic information about move (like position, word)
        /// </param>
        /// <exception cref='Exception'>
        /// no
        /// </exception>
        public bool AnalyzeMove(Move M)
        {
            int i = M.Start.X ;
            int j = M.Start.Y ;
            int n = 0;
            int score = 0;
            int ActualWordBonus = 1;

            // 1. Is this real start of word?
            try {
            if( M.Down ) {
                if( desk[i,j-1] != '_' ) return false;
            } else {
                if( desk[i-1,j] != '_' ) return false;
            } }
            catch( System.IndexOutOfRangeException ) { /* ok */ }

            // 2. Go through word, now I am at first letter of puted word
            if( j < 0 || j >= desk.GetLength(1) || i < 0 || i >= desk.GetLength(0)) return false;

            bool fail = false;
            while( true ) {

                // 2.a) Determinate which letter is need to put
                if( desk[i,j] == '_' ) {
                    M.AddLetterToPut( new MovedStone( M.Word[n], i, j ) );
                    desk[i,j] = M.Word[n];

                    int k = Cross(i,j,M.Down);
                    if( k < 0 ) {				// Crossword is wrong
                        fail = true;
                        break; }
                    if( k == 0) {} 				// No crossword (only this stone)
                    score += k;					// K > 0 : K is score for crossword

                    ActualWordBonus *= wordBonus[i,j];

                    score += charBonus[i,j] * desk[i,j].ToRank();
                } else {
                    score += desk[i,j].ToRank();
                }

                // Prepare to new iteration or break
                n++;
                if( M.Down ) j++; else i++;
                if( j >= desk.GetLength(1) || i >= desk.GetLength(0) ) break;
                if( n == M.Word.Length ) {
                    if( desk[i,j] == '_' ) break;
                    else {		// Some unknow suffix
                        string s = M.Word;
                        while( i < desk.GetLength(0) && j < desk.GetLength(1) && desk[i,j] != '_') {
                            s += desk[i,j].ToString();
                            M.Score += desk[i,j].ToRank();
                            if( M.Down ) j++; else i++;
                        }
                        if( game.dictionary.Content( s ) ) {
                            M.Word = s;
                            break;
                        } else {
                            fail = true;
                            break;
                        }
                    }
                }
            } // end of while cyklus

            // 3. Delete puted stone (turn is not confirmed
            foreach(MovedStone ms in M.PutedStones ) {
                desk[ms.i, ms.j] = '_';
            }

            if( fail ) return false;

            score *= ActualWordBonus;
            M.Score = score;

            if( game.dictionary.Content( M.Word ) )	return true;
            else return false;
        }
开发者ID:Kedrigern,项目名称:scrabble,代码行数:92,代码来源:desk.cs


注:本文中的Move.AddLetterToPut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。