Example #1
0
int evalState(char funcBoard[BOARDROWS][BOARDCOLS]){
  int ourMoves, oppMoves;
  ourMoves = findPossibleMoves(funcBoard, computerColour);
  oppMoves = findPossibleMoves(funcBoard, playerColour) * 3;

  if (oppMoves == 0){
    return 900;
  } else {
    return (ourMoves / (oppMoves * 3));
  }
}
Example #2
0
bool			IA::play()
{
  int			i = 0;
  int			best, value = 0;
  Pos			pos = {static_cast<int>(Rules::getSize()) / 2, static_cast<int>(Rules::getSize()) / 2};
  std::pair<int, Pos>*	res;
  auto			start = std::chrono::system_clock::now();

  _toTreat->clear();
  findPossibleMoves();
  dispatcher();
  best = -MAXINT;
  while (i < MAX_THREAD)
    {
      if ((res = _shared->popProcessed()) != NULL)
  	{
	  ++i;
  	  if (res->first > best)
  	    {
  	      best = res->first;
  	      pos = res->second;
  	    }
	  delete res;
  	}
    }
  std::cout << static_cast<int>(pos.x) << ":" << static_cast<int>(pos.y) << " player = " << _id;
  auto			end = std::chrono::system_clock::now();
  auto			elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
  std::cout << " -> [" << elapsed.count() << " ms] "<< " weight = " << best << std::endl;
  _board->move(pos, _id);
  _gui->updateDisplay();
  return true;
}