Skip to content
Snippets Groups Projects
Select Git revision
  • 78c2c20be9ae6121b531d2472668809e413cadb7
  • main default protected
  • nour2
  • aleks4
  • geno2
  • petri-net-output
  • nour
  • deep-rl-1
  • geno3
  • paula
  • aleks2
  • aleks3
  • Nour
  • geno
  • aleks
15 results

eventlog.cpython-311.pyc

Blame
    • Aleksandra Dimitrova's avatar
      12381837
      new file: __pycache__/environment.cpython-311.pyc · 12381837
      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
      12381837
      History
      new file: __pycache__/environment.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
    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