Difference between revisions of "The player that has the letter that is closest to “A” will begin the game. A blank tile will win the start of the game"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "The easiest way to do this, although not the most efficient, is to have two for or foreach loops. Each foreach loop would cycle though a players hand with a check to see if th...")
 
m
Line 1: Line 1:
The easiest way to do this, although not the most efficient, is to have two for or foreach loops. Each foreach loop would cycle though a players hand with a check to see if the ascii value of the letter is less then the best (which would be stored in a variable for each player), if it is the that is the best. After both players have the best values, they would be compared and whichever is lower will have their turn played first.
+
The easiest way to do this, although not the most efficient, is to have two for or foreach loops. Each foreach loop would cycle though a players hand with a check to see if the ascii value of the letter is less then the best (which would be stored in a variable for each player), if it is the that is the best. After both players have the best values, they would be compared and whichever is lower will have their turn played first. This doesn't account for blanks, unless a blank uses a lower ascii value then A.
  
 
<syntaxhighlight lang="C#">
 
<syntaxhighlight lang="C#">

Revision as of 14:08, 24 May 2018

The easiest way to do this, although not the most efficient, is to have two for or foreach loops. Each foreach loop would cycle though a players hand with a check to see if the ascii value of the letter is less then the best (which would be stored in a variable for each player), if it is the that is the best. After both players have the best values, they would be compared and whichever is lower will have their turn played first. This doesn't account for blanks, unless a blank uses a lower ascii value then A.

            int P1BestScore = int.MaxValue;
            int P2BestScore = int.MaxValue;
            bool PlayerOnePlayedFirst = false;
            while (/*Normal Information*/)
            {
                foreach (char Letter in PlayerOneTiles)
                {
                    if ((int)Letter < P1BestScore)
                    {
                        P1BestScore = (int)Letter;
                    }
                }
                foreach (char Letter in PlayerTwoTiles)
                {
                    if ((int)Letter < P2BestScore)
                    {
                        P2BestScore = (int)Letter;
                    }
                }
                if (PlayerOnePlayedFirst)
                {
                    HaveTurn(/* Player one data */ );
                }
                else
                {
                    HaveTurn(/* Player two data */);
                }
                // . . .
                if (PlayerOnePlayedFirst)
                {
                    HaveTurn(/* Player two data */);
                }
                else
                {
                    HaveTurn(/* Player one data */);
                }
            }
        // . . .
        }