TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
lambda.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 "module.h"
11 
12 #include <mapbox/variant.hpp>
13 
14 namespace cherrypi {
15 
16 /**
17  * Lets you construct a lightweight module by providing your own step()
18  * as an std::function.
19  */
20 class LambdaModule : public Module {
21  public:
22  using StepFunctionState = std::function<void(State*)>;
23  using StepFunctionStateModule = std::function<void(State*, Module*)>;
24 
25  LambdaModule(StepFunctionState fn, std::string name = std::string());
26  LambdaModule(StepFunctionStateModule fn, std::string name = std::string());
27  virtual ~LambdaModule() = default;
28 
29  virtual void step(State* state) override;
30 
31  protected:
32  mapbox::util::variant<StepFunctionState, StepFunctionStateModule> fn_;
33 };
34 
35 } // namespace cherrypi
Game state.
Definition: state.h:42
virtual ~LambdaModule()=default
std::string name()
Definition: module.cpp:41
virtual void step(State *state) override
Definition: lambda.cpp:22
Lets you construct a lightweight module by providing your own step() as an std::function.
Definition: lambda.h:20
std::function< void(State *, Module *)> StepFunctionStateModule
Definition: lambda.h:23
Main namespace for bot-related code.
Definition: areainfo.cpp:17
LambdaModule(StepFunctionState fn, std::string name=std::string())
Definition: lambda.cpp:12
std::function< void(State *)> StepFunctionState
Definition: lambda.h:22
mapbox::util::variant< StepFunctionState, StepFunctionStateModule > fn_
Definition: lambda.h:32
Interface for bot modules.
Definition: module.h:30