<commit_before>#include <iostream>
#include "Game.h"

Game::Game()
{
	std::cout << "Game constructor called\n";
}


Game::~Game()
{
	std::cout << "Game destructor called!\n";
	delete _pBoard;
	delete _pOne;
	delete _pTwo;
}

void Game::Play()
{
	/*std::cout << _pOne->GetName() << std::endl;;

	_pOne->NineDartFinish1(*_pBoard);
	std::cout << std::endl;
	_pTwo->NineDartFinish2(*_pBoard);*/
	
	//std::cout << "Hello Fella! You are about to simulate exciting game of Darts 501!\n";
	//std::cout << "How many times you want to simulate? ";
	//std::cout << "Choose strategy:\n";
	//std::cout << "1 - Cheek Strategy\n";
	std::cout << "How many times you want to play? ";
	std::cin >> _simulateCounter;
	std::cout << std::endl;

	for (int i = 0; i < _simulateCounter; ++i)
	{
		uint8_t r = rand() % 2; //used to randomize strategy

		switch (r) {
		case 0:
			PlayAdvancedStrategy();
			break;
		case 1:
			PlayNineDartFinish1();
			break;
		}
		
	}
	std::cin.get();
}

//do {
//	std::cin >> _simulateCounter;
//	std::cout << std::endl;
//	_fail = std::cin.fail();
//
//	std::cin.clear();
//	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
//} while (_fail);

void Game::PlayAdvancedStrategy()
{
	_pOne->SetScore(_newScore);
	_pTwo->SetScore(_newScore);

	do
	{
		////////Player One Turn
		Throw3Darts(_pOne, _pBoard);
		////////Player Two Turn 
		Throw3Darts(_pTwo, _pBoard);
	} while (_pOne->CheckWin() != true && _pTwo->CheckWin() != true);

	DisplayWinner(_pOne, _pTwo);
}

void Game::PlayNineDartFinish1()
{
	_pOne->SetScore(_newScore);
	_pTwo->SetScore(_newScore);

	do
	{
		if (_nineDartFinish)
		{
			{
				_pOne->AimTon80(*_pBoard);
				_pTwo->AimTon80(*_pBoard);
			}
			{
			_pOne->AimTon80(*_pBoard);
			_pTwo->AimTon80(*_pBoard);
			}
			{
				_pOne->AimCheckout141(*_pBoard);
				if (_pOne->CheckWin())
					break;
			}
			{
				_pTwo->AimCheckout141(*_pBoard);
				if (_pTwo->CheckWin())
					break;
			}
			_nineDartFinish = false;
		}
		////////Player One Turn
		Throw3Darts(_pOne, _pBoard);
		////////Player Two Turn 
		Throw3Darts(_pTwo, _pBoard);
	} while (_pOne->CheckWin() != true && _pTwo->CheckWin() != true);

	DisplayWinner(_pOne, _pTwo);
}

void Game::Throw3Darts(Player* player, Board* board) 
{
	uint16_t _temp = player->GetScore();
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
}

int16_t Game::CheckWinningPosition(Player* player, Board* board)
{
	for (uint8_t i = 0; i < X; ++i)
	{
		for (uint8_t j = 0; j < Y; ++j)
		{
			if (player->GetScore() - board->GetAtPosition(i, j) * 2 == 0) { //check if hitting double will end the game
				return board->GetAtPosition(i, j);
			}
			else if ((player->GetScore()) - BULL == 0) { //check if hitting the bull will end the game
				return BULL;
			}
		}
	}
			
	if (player->IsEven(player->GetScore())) //Check if the score is even
	{
		for (uint8_t i = 20; i >= 0; --i) //Choose the highest possible number to aim for and still be able to win 
		{
			if ((player->GetScore() - (i * 2)) >= 2) { //Check if scoring a double will leave at least the smallest possible winning score
				return i; //A value of 0-20 will be used to throw a double
			}
		}
	}
	else {
		for (uint8_t i = 20; i >= 0; --i) //If score is not even (odd) then throw single.
		{
			if ((player->GetScore() - i) >= 2 && player->IsOdd(i) ) { //Check if scoring a single will leave at least the smallest possible winning score and if aim is an odd number
				player->ThrowSingle(i, *board); //Throw single and aim an odd number to get an even score (odd - odd = even, e.x. 7 - 3 = 4) 
				return 0; //to end the function the value of 0 will be used to throw a double after throwing a single but it doesnt make any diffrence in simulation
			}
		}
	}	
}

void Game::CheckBusted(Player* player, uint16_t temp)
{
	if (player->GetScore() < 0 || player->GetScore() == 1) //Busted if score is smaller then 0 or equal to 1
	{
		player->SetScore(temp);
	}
}

void Game::DisplayWinner(Player* playerOne, Player* playerTwo)
{
	if (playerOne->CheckWin()) {
		_player1WinCounter++;
		if (_player1WinCounter == 1) {
			std::cout << "Player One wins! He has won " << _player1WinCounter << " time!\n";
			std::cout << "Player Two has won " << _player2WinCounter << " times!\n";
		}
		else {
			std::cout << "Player One wins! He has won " << _player1WinCounter << " times!\n";
			std::cout << "Player Two has won " << _player2WinCounter << " times!\n";
		}
	}
	else if (playerTwo->CheckWin()) {
		_player2WinCounter++;
		if (_player2WinCounter == 1) {
			std::cout << "Player Two wins! He has won " << _player2WinCounter << " time!\n";
			std::cout << "Player One has won " << _player1WinCounter << " times!\n";
		}<commit_msg>MAC changes<commit_after>#include <iostream>
#include "Game.h"

Game::Game()
{
	std::cout << "Game constructor called\n";
}


Game::~Game()
{
	std::cout << "Game destructor called!\n";
	delete _pBoard;
	delete _pOne;
	delete _pTwo;
}

void Game::Play()
{
	/*std::cout << _pOne->GetName() << std::endl;;

	_pOne->NineDartFinish1(*_pBoard);
	std::cout << std::endl;
	_pTwo->NineDartFinish2(*_pBoard);*/
	
	//std::cout << "Hello Fella! You are about to simulate exciting game of Darts 501!\n";
	//std::cout << "How many times you want to simulate? ";
	//std::cout << "Choose strategy:\n";
	//std::cout << "1 - Cheek Strategy\n";
	std::cout << "How many times you want to play? ";
	std::cin >> _simulateCounter;
	std::cout << std::endl;

	for (int i = 0; i < _simulateCounter; ++i)
	{
		uint8_t r = rand() % 2; //used to randomize strategy

		switch (r) {
		case 0:
			PlayAdvancedStrategy();
			break;
		case 1:
			PlayNineDartFinish1();
			break;
		}
		
	}
	std::cin.get();
}

//do {
//	std::cin >> _simulateCounter;
//	std::cout << std::endl;
//	_fail = std::cin.fail();
//
//	std::cin.clear();
//	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
//} while (_fail);

void Game::PlayAdvancedStrategy()
{
	_pOne->SetScore(_newScore);
	_pTwo->SetScore(_newScore);

	do
	{
		////////Player One Turn
		Throw3Darts(_pOne, _pBoard);
		////////Player Two Turn 
		Throw3Darts(_pTwo, _pBoard);
	} while (_pOne->CheckWin() != true && _pTwo->CheckWin() != true);

	DisplayWinner(_pOne, _pTwo);
}

void Game::PlayNineDartFinish1()
{
	_pOne->SetScore(_newScore);
	_pTwo->SetScore(_newScore);

	do
	{
		if (_nineDartFinish)
		{
			{
				_pOne->AimTon80(*_pBoard);
				_pTwo->AimTon80(*_pBoard);
			}
			{
			_pOne->AimTon80(*_pBoard);
			_pTwo->AimTon80(*_pBoard);
			}
			{
				_pOne->AimCheckout141(*_pBoard);
				if (_pOne->CheckWin())
					break;
			}
			{
				_pTwo->AimCheckout141(*_pBoard);
				if (_pTwo->CheckWin())
					break;
			}
			_nineDartFinish = false;
		}
		////////Player One Turn
		Throw3Darts(_pOne, _pBoard);
		////////Player Two Turn 
		Throw3Darts(_pTwo, _pBoard);
	} while (_pOne->CheckWin() != true && _pTwo->CheckWin() != true);

	DisplayWinner(_pOne, _pTwo);
}

void Game::Throw3Darts(Player* player, Board* board) 
{
	uint16_t _temp = player->GetScore();
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
	player->ThrowDouble(CheckWinningPosition(player, board), *board);
	CheckBusted(player, _temp);
}

int16_t Game::CheckWinningPosition(Player* player, Board* board)
{
	for (uint8_t i = 0; i < X; ++i)
	{
		for (uint8_t j = 0; j < Y; ++j)
		{
			if (player->GetScore() - board->GetAtPosition(i, j) * 2 == 0) { //check if hitting double will end the game
				return board->GetAtPosition(i, j);
			}
			else if ((player->GetScore()) - BULL == 0) { //check if hitting the bull will end the game
				return BULL;
			}
		}
	}
			
	if (player->IsEven(player->GetScore())) //Check if the score is even
	{
		for (uint8_t i = 20; i >= 0; --i) //Choose the highest possible number to aim for and still be able to win 
		{
			if ((player->GetScore() - (i * 2)) >= 2) { //Check if scoring a double will leave at least the smallest possible winning score
				return i; //A value of 0-20 will be used to throw a double
			}
		}
	}
	else {
		for (uint8_t i = 20; i >= 0; --i) //If score is not even (odd) then throw single.
		{
			if ((player->GetScore() - i) >= 2 && player->IsOdd(i) ) { //Check if scoring a single will leave at least the smallest possible winning score and if aim is an odd number
				player->ThrowSingle(i, *board); //Throw single and aim an odd number to get an even score (odd - odd = even, e.x. 7 - 3 = 4) 
				return 0; //to end the function the value of 0 will be used to throw a double after throwing a single but it doesnt make any diffrence in simulation
			}
		}
	}
    return 0;
}

void Game::CheckBusted(Player* player, uint16_t temp)
{
	if (player->GetScore() < 0 || player->GetScore() == 1) //Busted if score is smaller then 0 or equal to 1
	{
		player->SetScore(temp);
	}
}

void Game::DisplayWinner(Player* playerOne, Player* playerTwo)
{
	if (playerOne->CheckWin()) {
		_player1WinCounter++;
		if (_player1WinCounter == 1) {
			std::cout << "Player One wins! He has won " << _player1WinCounter << " time!\n";
			std::cout << "Player Two has won " << _player2WinCounter << " times!\n";
		}
		else {
			std::cout << "Player One wins! He has won " << _player1WinCounter << " times!\n";
			std::cout << "Player Two has won " << _player2WinCounter << " times!\n";
		}
	}
	else if (playerTwo->CheckWin()) {
		_player2WinCounter++;
		if (_player2WinCounter == 1) {
			std::cout << "Player Two wins! He has won " << _player2WinCounter << " time!\n";
			std::cout << "Player One has won " << _player1WinCounter << " times!\n";
		}
{'fraction_non_alphanumeric': 0.17248397272819782, 'fraction_numerical': 0.016383433397781623, 'mean_word_length': 3.4774487471526196, 'pattern_counts': {'":': 0, '<': 135, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5069356', 'n_tokens_mistral': 3993, 'n_tokens_neox': 3562, 'n_words': 973}