Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ai-battle cli #1652

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

wichern
Copy link
Contributor

@wichern wichern commented Mar 10, 2024

Adds an optional binary that runs headless (no UI) AI battles.
This can be useful when creating training data or testing new AIs.

image

I'm not sure if this is placed correctly or whether it should even be part of the master branch.
In any case, I would like your feedback on this tool. It aims to reuse as much of s25main as possible in order to create accurate replays.

Copy link
Member

@Flamefire Flamefire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few remarks to fix compilation

This will likely glitch on Windows though:

   `printf("\x1b[%dA", 8 + world_.GetNumPlayers()); // Move cursor back up`


try
{
unsigned random_init = std::chrono::high_resolution_clock::now().time_since_epoch().count();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unsigned random_init = std::chrono::high_resolution_clock::now().time_since_epoch().count();
auto random_init = static_cast<unsigned>(std::chrono::high_resolution_clock::now().time_since_epoch().count());

if(replay_.IsRecording())
{
replay_.StopRecording();
printf("Replay written to %s\n", canonical(replayPath_).c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf("Replay written to %s\n", canonical(replayPath_).c_str());
bnw::cout << "Replay written to " << canonical(replayPath_) << '\n';

save.sgd.MakeSnapshot(game_);
save.Save(path, "AI Battle");

printf("Savegame written to %s\n", canonical(path).c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printf("Savegame written to %s\n", canonical(path).c_str());
bnw::cout << "Savegame written to " << canonical(path) << '\n';


#include <boost/filesystem.hpp>
#include <boost/nowide/args.hpp>
#include <boost/nowide/iostream.hpp>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/filesystem.hpp>
#include <boost/nowide/iostream.hpp>


int main(int argc, char** argv)
{
bnw::args _(argc, argv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bnw::args _(argc, argv);
bnw::nowide_filesystem();
bnw::args _(argc, argv);

Comment on lines +16 to +27

#include <boost/nowide/iostream.hpp>

#include <chrono>
#include <sstream>

std::vector<PlayerInfo> GeneratePlayerInfo(const std::vector<AI::Info>& ais);
std::string ToString(const std::chrono::milliseconds& time);
std::string HumanReadableNumber(unsigned num);

namespace bfs = bfs;
using bfs::canonical;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <boost/nowide/iostream.hpp>
#include <chrono>
#include <sstream>
std::vector<PlayerInfo> GeneratePlayerInfo(const std::vector<AI::Info>& ais);
std::string ToString(const std::chrono::milliseconds& time);
std::string HumanReadableNumber(unsigned num);
namespace bfs = bfs;
using bfs::canonical;
#include <boost/nowide/iostream.hpp>
#include <chrono>
#include <sstream>
std::vector<PlayerInfo> GeneratePlayerInfo(const std::vector<AI::Info>& ais);
std::string ToString(const std::chrono::milliseconds& time);
std::string HumanReadableNumber(unsigned num);
namespace bfs = boost::filesystem;
namespace bnw = boost::nowide;
using bfs::canonical;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants