AS 2019 RandomPlayerStarts

From TRCCompSci - AQA Computer Science
Revision as of 09:10, 1 April 2019 by Admin (talk | contribs) (Idea)
Jump to: navigation, search

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.