-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHost.cpp
53 lines (39 loc) · 1.35 KB
/
Host.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "Host.h"
#include <iostream>
Host::Host(unsigned int numberOfOptions, bool playerWillChangeChoice, bool beVerbose) : beVerbose(beVerbose), choices(numberOfOptions, false), numberOfOptions(numberOfOptions), player(playerWillChangeChoice)
{
std::random_device rd;
gen.seed(rd());
const unsigned int correct = gen() % numberOfOptions;
choices[correct] = true;
if (beVerbose)
{
std::cout << "Correct Options is " << correct << "\n";
}
}
void Host::PlayGame()
{
player.MakeChoice(numberOfOptions, gen);
if (beVerbose)
{
std::cout << "Player Choose " << player.GetCurrentChoice() << "\n";
}
auto invertedChoices = choices;
invertedChoices.flip();
invertedChoices[player.GetCurrentChoice()] = false;
std::discrete_distribution<int> dist(invertedChoices.begin(), invertedChoices.end());
const unsigned int wrongChoice = dist(gen);
if (beVerbose)
{
std::cout << "Choice to reveal is " << wrongChoice << "\n";
}
player.ChangeChoiceIfSetGivenWrongChoice(numberOfOptions, wrongChoice, gen);
if (beVerbose)
{
std::cout << "Player Changed Choice to " << player.GetCurrentChoice() << "\n";
}
}
bool Host::IsPlayerCorrect() const
{
return choices[player.GetCurrentChoice()];
}