Difference between revisions of "AS 2019 RandomPlayerStarts"
(→Where) |
(→Idea) |
||
Line 7: | Line 7: | ||
=Idea= | =Idea= | ||
− | create a random, then generate a random number, and then use it to decide if A or B goes first. | + | create a random, then generate a random number, and then use it to decide if A or B goes first. So: |
− | |||
− | |||
<syntaxhighlight lang=c#> | <syntaxhighlight lang=c#> | ||
string nextPlayer; | string nextPlayer; | ||
Line 18: | Line 16: | ||
Console.WriteLine(nextPlayer + " goes first!!"); | Console.WriteLine(nextPlayer + " goes first!!"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | This generates a random number between 0 and 100, we therefore check if the random is less than or equal to 50. |
Revision as of 08:10, 1 April 2019
Where
Find the Game method, and look for:
string nextPlayer = "a";
Idea
create a random, then generate a random number, and then use it to decide if A or B goes first. So:
string nextPlayer;
if (rnd.Next(100) <= 50)
nextPlayer = "a";
else
nextPlayer = "b";
Console.WriteLine(nextPlayer + " goes first!!");
This generates a random number between 0 and 100, we therefore check if the random is less than or equal to 50.