Notabilis has proposed merging lp:~widelands-dev/widelands/bug-1811030-desync-ai into lp:widelands.
Commit message: Replacing logic_rand() with std::rand() in seafaring code of AI. Should fix desyncs while network gaming. Requested reviews: Widelands Developers (widelands-dev) For more details, see: https://code.launchpad.net/~widelands-dev/widelands/bug-1811030-desync-ai/+merge/361689 Calls of logic_rand() have to be done on all participants of a network game. Since the AI code is only executed on the host, calling logic_rand() leads to different random numbers on the participants computers later on, resulting in desynchronized games. -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1811030-desync-ai into lp:widelands.
=== modified file 'src/ai/defaultai_seafaring.cc' --- src/ai/defaultai_seafaring.cc 2018-09-04 15:48:47 +0000 +++ src/ai/defaultai_seafaring.cc 2019-01-11 21:07:24 +0000 @@ -455,7 +455,7 @@ } Widelands::IslandExploreDirection DefaultAI::randomExploreDirection() { - return game().logic_rand() % 20 < 10 ? Widelands::IslandExploreDirection::kClockwise : + return std::rand() % 20 < 10 ? Widelands::IslandExploreDirection::kClockwise : Widelands::IslandExploreDirection::kCounterClockwise; } @@ -486,7 +486,7 @@ spot_score); // we make a decision based on the score value and random - if (game().logic_rand() % 8 < spot_score) { + if (std::rand() % 8 < spot_score) { // we build a port here game().send_player_ship_construct_port(*so.ship, so.ship->exp_port_spaces().front()); so.last_command_time = gametime; @@ -579,15 +579,15 @@ assert(possible_directions.size() >= new_teritory_directions.size()); // If only open sea (no unexplored sea) is found, we don't always divert the ship - if (new_teritory_directions.empty() && game().logic_rand() % 100 < 80) { + if (new_teritory_directions.empty() && std::rand() % 100 < 80) { return false; } if (!possible_directions.empty() || !new_teritory_directions.empty()) { const Direction direction = !new_teritory_directions.empty() ? - new_teritory_directions.at(game().logic_rand() % new_teritory_directions.size()) : - possible_directions.at(game().logic_rand() % possible_directions.size()); + new_teritory_directions.at(std::rand() % new_teritory_directions.size()) : + possible_directions.at(std::rand() % possible_directions.size()); game().send_player_ship_scouting_direction(*so.ship, static_cast<WalkingDir>(direction)); log("%d: %s: exploration - breaking for %s sea, dir=%u\n", pn,
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp