Something went wrong on our end
Select Git revision
eventlog.cpython-311.pyc
-
Aleksandra Dimitrova authored
new file: __pycache__/eventlog.cpython-311.pyc new file: __pycache__/processmodel.cpython-311.pyc new file: __pycache__/rlalgorithm.cpython-311.pyc new file: backend/__pycache__/agent.cpython-311.pyc new file: backend/__pycache__/environment.cpython-311.pyc new file: backend/__pycache__/simplesimmodel.cpython-311.pyc new file: backend/__pycache__/simulationmodel.cpython-311.pyc new file: backend/agent.py new file: backend/environment.py new file: backend/eventlog.py new file: backend/simplesimmodel.py new file: simpy_tutorial/__pycache__/environment.cpython-311.pyc new file: simpy_tutorial/__pycache__/eventlog.cpython-311.pyc new file: simpy_tutorial/__pycache__/processmodel.cpython-311.pyc new file: simpy_tutorial/__pycache__/rlalgorithm.cpython-311.pyc renamed: environment.py -> simpy_tutorial/environment.py renamed: eventlog.py -> simpy_tutorial/eventlog.py renamed: processmodel.py -> simpy_tutorial/processmodel.py renamed: rlalgorithm.py -> simpy_tutorial/rlalgorithm.py
Aleksandra Dimitrova authorednew file: __pycache__/eventlog.cpython-311.pyc new file: __pycache__/processmodel.cpython-311.pyc new file: __pycache__/rlalgorithm.cpython-311.pyc new file: backend/__pycache__/agent.cpython-311.pyc new file: backend/__pycache__/environment.cpython-311.pyc new file: backend/__pycache__/simplesimmodel.cpython-311.pyc new file: backend/__pycache__/simulationmodel.cpython-311.pyc new file: backend/agent.py new file: backend/environment.py new file: backend/eventlog.py new file: backend/simplesimmodel.py new file: simpy_tutorial/__pycache__/environment.cpython-311.pyc new file: simpy_tutorial/__pycache__/eventlog.cpython-311.pyc new file: simpy_tutorial/__pycache__/processmodel.cpython-311.pyc new file: simpy_tutorial/__pycache__/rlalgorithm.cpython-311.pyc renamed: environment.py -> simpy_tutorial/environment.py renamed: eventlog.py -> simpy_tutorial/eventlog.py renamed: processmodel.py -> simpy_tutorial/processmodel.py renamed: rlalgorithm.py -> simpy_tutorial/rlalgorithm.py
Player.cpp 2.31 KiB
/**
* Player.cpp
*
* @author Frederik Keens
*/
#include "Player.hpp"
#include <iostream>
namespace advanced_wars
{
Player::Player(int money, Faction faction)
: m_money(money), m_alive(true), m_activeTurn(false), m_faction(faction)
{
}
Player::~Player() {}
void Player::startTurn(
std::unordered_map<int, std::unique_ptr<Unit>>& lvUnits,
std::unordered_map<int, Building>& lvBuildings)
{
for (auto& [id, unit] : lvUnits)
{
Unit& unitRef = *unit;
if (unitRef.getFaction() == m_faction)
{
unitRef.setState(UnitState::IDLE);
unitRef.setMoved(false);
}
}
int underControl = 0;
for (auto& [id, building] : lvBuildings)
{
switch (m_faction)
{
case Faction::URED:
if (building.getFaction() == Faction::URED)
{
underControl++;
}
break;
case Faction::UBLUE:
if (building.getFaction() == Faction::UBLUE)
{
underControl++;
}
break;
case Faction::UYELLOW:
if (building.getFaction() == Faction::UYELLOW)
{
underControl++;
}
break;
case Faction::UGREEN:
if (building.getFaction() == Faction::UGREEN)
{
underControl++;
}
break;
case Faction::UPURPLE:
if (building.getFaction() == Faction::UPURPLE)
{
underControl++;
}
break;
default:
break;
}
}
m_money += 1000 * underControl;
m_activeTurn = true;
}
void Player::endTurn(std::unordered_map<int, std::unique_ptr<Unit>>& lvUnits)
{
std::cout << "Ending turn for player with faction: " << static_cast<int>(m_faction) << "\n";
for (auto& [id, unit] : lvUnits)
{
Unit& unitRef = *unit;
if (unitRef.getFaction() == m_faction)
{
unitRef.setState(UnitState::UNAVAILABLE);
unitRef.setMoved(true);
}
}
m_activeTurn = false;
}
Faction Player::getFaction()
{
return m_faction;
}
int Player::getMoney()
{
return m_money;
}
void Player::spendMoney(int toSpend)
{
m_money -= toSpend;
}
} // namespace advanced_wars