engine.cpp 1.47 KB
#include "engine.h"

namespace othello
{

    bool OthelloGameEngine::initNewGame()
    {
      clearGame();

      m_board[0].set(36);
      m_board[0].set(27);
      m_board[1].set(35);
      m_board[1].set(28);

      m_playerid = PlayerId::One;

      return true;
    }

    void OthelloGameEngine::clearGame() {
        //removes all pieces from the board
        m_board[0].reset();
        m_board[1].reset();
    }

    bool OthelloGameEngine::performMoveForCurrentHuman(const BitPos& board_pos)
    {
        if (utility::isLegalMove(m_board, m_playerid, board_pos)){
            utility::placeAndFlip(m_board, m_playerid, board_pos);
            switchCurrentPlayerId();
            return true;
        }
        return false;

    }

    void OthelloGameEngine::think(const std::chrono::seconds& /*time_limit*/)
    {

    }

    void OthelloGameEngine::switchCurrentPlayerId()
    {
        if (m_playerid == PlayerId::One){
            m_playerid = PlayerId::Two;
        }
        else m_playerid = PlayerId::One;
    }

    PlayerId OthelloGameEngine::currentPlayerId() const
    {

        return m_playerid;
    }

    PlayerType OthelloGameEngine::currentPlayerType() const
    {
        //for use after implementing AI
        return {};
    }

    BitPieces OthelloGameEngine::pieces(const PlayerId& player_id) const
    {
        return m_board[static_cast<size_t>(player_id)];
    }

    const BitBoard& OthelloGameEngine::board() const {return m_board;}


}   // namespace othello