#include "human.h"
#include <iostream>
#include <limits>
using namespace std;

Move Human::nextMove(const Board& board)
{
   int no;
   for (;;)
   {
      cout << "Gib einen Zug ein (1..9): ";
      cin >> no;
      if (cin.fail())
      {
         cin.clear();
         cin.ignore(numeric_limits<streamsize>::max(), '\n');
         continue;
      }
      if (no < 1 || no > 9) continue;

      int row = (no - 1) / 3;
      int col = (no - 1) % 3;
      if (board.isFree(row, col))
      {
         cout << '\n';
         return Move{ row, col, Color::white };
      }
   }
}
