TorchCraftAI
A bot for machine learning research on StarCraft: Brood War
upcfilter.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 "upc.h"
11 
12 namespace cherrypi {
13 
14 class Module;
15 class State;
16 
17 /**
18  * Base class for UPC filters.
19  *
20  * Note that the ownership of UPCs are yielded to the blackboard when posted.
21  * These filters are then applied to each UPC to ensure validity.
22  * If Upcs are slightly incorrect but fixable, then they will be modified to
23  * comply with the specification. Otherwise, if they are wrong and we cannot fix
24  * them, the "filter" method should return false, indicating a wrong UPC. In
25  * that case, the corresponding UPC should not be posted in the blackboard.
26  *
27  * Possible use cases for UPC filters are consistency checks (which would log a
28  * warning if simple conditions are violated, for example) or enforcing unit
29  * allocations according to a set of rules based on which tasks are currently
30  * holding on to units. See below for a concrete application of the latter.
31  */
32 class UPCFilter {
33  public:
34  UPCFilter() {}
35  virtual ~UPCFilter() {}
36 
37  // This function ensures that the UPC is valid. If that is the case (possibly
38  // after being fixed), it returns true, and false otherwise
39  virtual bool
40  filter(State* state, std::shared_ptr<UPCTuple> upc, Module* origin) = 0;
41 };
42 
43 /**
44  * Removes units from an UPC that are allocated to high-priority tasks.
45  */
47  public:
49  virtual ~AssignedUnitsFilter() {}
50 
51  bool filter(State* state, std::shared_ptr<UPCTuple> upc, Module* origin)
52  override;
53 };
54 
55 /**
56  * Try to fix the malformed UPCs. It does two checks:
57  * - Remove nullptr from unit, positionU, and createType
58  * - Clamp probabilities in [0,1]
59  * Note that all UPCs will be accepted (after being fixed)
60  */
61 class SanityFilter : public UPCFilter {
62  public:
64  virtual ~SanityFilter() {}
65 
66  bool filter(State* state, std::shared_ptr<UPCTuple> upc, Module* origin)
67  override;
68 };
69 
70 } // namespace cherrypi
Game state.
Definition: state.h:42
Try to fix the malformed UPCs.
Definition: upcfilter.h:61
virtual ~UPCFilter()
Definition: upcfilter.h:35
virtual ~AssignedUnitsFilter()
Definition: upcfilter.h:49
virtual ~SanityFilter()
Definition: upcfilter.h:64
Removes units from an UPC that are allocated to high-priority tasks.
Definition: upcfilter.h:46
Base class for UPC filters.
Definition: upcfilter.h:32
Main namespace for bot-related code.
Definition: areainfo.cpp:17
UPCFilter()
Definition: upcfilter.h:34
virtual bool filter(State *state, std::shared_ptr< UPCTuple > upc, Module *origin)=0
Interface for bot modules.
Definition: module.h:30