Return-To-The-Roots / s25client

Return To The Roots (Settlers II(R) Clone)
http://www.rttr.info
GNU General Public License v2.0
476 stars 75 forks source link

Quickstart AI Battle #1565

Closed wichern closed 1 year ago

wichern commented 1 year ago

This change allows to quick-start into an AI-only game.

Example: ./bin/s25client -m share/s25rttr/RTTR/MAPS/NEW/Bagel5.SWD --ai aijh --ai aijh --ai dummy

Will result in Screenshot from 2023-03-18 22-15-57

Implementation: This change adds a new program option (--ai) and extends QuickStartGame(). In order to have the requested AIs ready in dskGameLobby, the AI configuration is stored in GameClient. In GameClient::GameLoaded() we call ToggleHumanAIPlayer() to turn the human player into an AI as well.

Notes: There are no further limitations. The user can still add buildings and roads.

wichern commented 1 year ago

@Flamefire Thank you very much for your review! I tried to fix all your findings.

Tomorrow, I'll check if it is possible to save and load an ai battle.

wichern commented 1 year ago

Starting an AI-Battle from a savegame seems to work.

The provided AI players (--ai) have no effect in that case, except when none is given at all. In the latter case, player 0 will be played by the human player.

wichern commented 1 year ago

I did not see an existing UT for QuickStartGame(). How should I handle missing code coverage? Would you like me to create a UT for it?

Flamefire commented 1 year ago

I did not see an existing UT for QuickStartGame(). How should I handle missing code coverage? Would you like me to create a UT for it?

As that method is not critical I'm OK with missing coverage for that, as we have the review at least. If you can come up with a test then feel free. However I imagine that this would be very complicated due to the client, server, windowmanager and desktop being involved (so it's rather an integration test). Hence the idea to factor out the AI name parsing to have at least that tested, and skip the rest which "should work" after inspection ;-)