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
#include "HumanNimPlayer.hpp"
#include <iostream>

HumanNimPlayer::HumanNimPlayer()
{
    std::cout << "Welcome!  What is your name?" << std::endl;
    do {
        std::cout << "Name: ";
        if (!(std::cin >> name)) {
            name"Anonymous";
        }
    } while (name=="");
}

const std::string&
HumanNimPlayer::get_name() const
{
    return name;
}

NimMove
HumanNimPlayer::get_move(const NimGame& game) const
{
     NimMove move;
     do {
         unsigned int heap_index, count;
         std::cout << name << ", your move: ";
         if (!(std::cin >> heap_index >> count)) {
            return NimMove();
         }
         move = NimMove(heap_index, count);
     } while (!game.valid_move(move));
     return move;
}

// support dynamic loading
extern "C" {

NimPlayer*
construct() {
    return new HumanNimPlayer();
}

// extern "C"