tlongstretch / freeserf-with-AI-plus

THIS PROJECT WAS MOVED TO 'Forkserf', GO THERE INSTEAD
https://github.com/forkserf/forkserf
GNU General Public License v3.0
1 stars 0 forks source link

AI logic - missing code to check if 2nd road is actually better than first one - or don't build 2nd #61

Open tlongstretch opened 3 years ago

tlongstretch commented 3 years ago
  //
  // insert code here to check if the second road is actually better than the first road built (if one was built) !!
  //   otherwise, don't build. 
  //
  if (true) {
    if (roads_built >= 1) {
      AILogDebug["util_build_best_road"] << name << " TODO - check to see if this road is better than the first one built!";
    }
    AILogDebug["util_build_best_road"] << name << " about to build road, dumping some road stats.  source=" << road.get_source() << ", end=" << road.get_end(game->get_map().get());
    AILogDebug["util_build_best_road"] << name << " thread #" << std::this_thread::get_id() << " AI is locking mutex before calling game->build_road (non-direct road)";
    game->get_mutex()->lock();
    AILogDebug["util_build_best_road"] << name << " thread #" << std::this_thread::get_id() << " AI has locked mutex before calling game->build_road (non-direct road)";
    bool was_built = game->build_road(road, game->get_player(player_index));
    AILogDebug["util_build_best_road"] << name << " thread #" << std::this_thread::get_id() << " AI is unlocking mutex after calling game->build_road (non-direct road)";
    game->get_mutex()->unlock();
    AILogDebug["util_build_best_road"] << name << " thread #" << std::this_thread::get_id() << " AI has unlocked mutex after calling game->build_road (non-direct road)";
    if (was_built) {
      AILogDebug["util_build_best_road"] << name << " successfully built road from " << start_pos << " to " << end_pos << " as specified in PotentialRoad";
      roads_built++;
      continue;
    }
    else {
      AILogDebug["util_build_best_road"] << name << " ERROR - failed to build road from " << start_pos << " to " << end_pos << ", FIND OUT WHY!   trying next best solution...";
    }
  }
  else {
    AILogDebug["util_build_best_road"] << name << " last road built is better than this proposed one, not building second road (should only happy for dual-affinity buildings)";
  }