TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
module.h
1 /*
2  * Copyright (c) 2017-present, Facebook, Inc.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #pragma once
9 
10 #include <list>
11 
12 #include <torchcraft/client.h>
13 
14 #include "cherrypi.h"
15 
16 namespace cherrypi {
17 
18 class BasePlayer;
19 class State;
20 // Useful for derived classes
21 class Task;
22 struct UPCTuple;
23 struct UpcPostData;
24 
25 /**
26  * Interface for bot modules.
27  *
28  * Use Module::make<T>(args) to construct a new module instance of a given type.
29  */
30 class Module {
31  public:
32  virtual ~Module() = default;
33 
34  template <typename T, typename... Args>
35  static std::shared_ptr<T> make(Args&&... args) {
36  auto m = std::make_shared<T>(std::forward<Args>(args)...);
37  if (m->name().empty()) {
38  m->setName(makeName(typeid(T)));
39  }
40  return m;
41  }
42  static std::shared_ptr<Module> make(std::string const& typeName);
43 
44  virtual void setPlayer(BasePlayer* p) {
45  player_ = p;
46  };
47 
48  void setName(std::string name);
49  std::string name();
50  static std::string makeName(std::type_index const& type);
51 
52  virtual void step(State* s) {}
53  virtual void onGameStart(State* s) {}
54  virtual void onGameEnd(State* s) {}
55 
56  protected:
57  Module();
58 
60  std::string name_;
61 };
62 
63 } // namespace cherrypi
Game state.
Definition: state.h:42
static std::shared_ptr< T > make(Args &&...args)
Definition: module.h:35
void setName(std::string name)
Definition: module.cpp:37
The main bot object.
Definition: baseplayer.h:28
std::string name()
Definition: module.cpp:41
virtual void onGameEnd(State *s)
Definition: module.h:54
virtual void step(State *s)
Definition: module.h:52
Module()
Definition: module.cpp:18
std::string name_
Definition: module.h:60
virtual ~Module()=default
Main namespace for bot-related code.
Definition: areainfo.cpp:17
BasePlayer * player_
Definition: module.h:59
virtual void onGameStart(State *s)
Definition: module.h:53
virtual void setPlayer(BasePlayer *p)
Definition: module.h:44
Interface for bot modules.
Definition: module.h:30
static std::string makeName(std::type_index const &type)
Definition: module.cpp:45