Darwin Neuroevolution Framework
tic_tac_toe.h
1 // Copyright 2018 The Darwin Neuroevolution Framework Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <core/darwin.h>
18 #include <core/properties.h>
19 #include <core/stringify.h>
20 #include <core/tournament_implementations.h>
21 
22 namespace tic_tac_toe {
23 
25 enum class AnnType {
26  Value,
27  Policy,
28 };
29 
30 inline auto customStringify(core::TypeTag<AnnType>) {
32  { AnnType::Value, "value" },
33  { AnnType::Policy, "policy" },
34  };
35  return stringify;
36 }
37 
39 struct Config : public core::PropertySet {
40  PROPERTY(ann_type, AnnType, AnnType::Value, "The role of the evolved brains");
41  PROPERTY(calibration_matches, int, 100, "Number of calibration games");
42 
43  VARIANT(tournament_type,
46  "Tournament type");
47 };
48 
49 extern Config g_config;
50 
51 void init();
52 
82 class TicTacToe : public darwin::Domain {
83  public:
84  size_t inputs() const override;
85  size_t outputs() const override;
86 
87  bool evaluatePopulation(darwin::Population* population) const override;
88 
89  unique_ptr<core::PropertySet> calibrateGenotype(
90  const darwin::Genotype* genotype) const override;
91 };
92 
93 class Factory : public darwin::DomainFactory {
94  unique_ptr<darwin::Domain> create(const core::PropertySet& config) override {
95  g_config.copyFrom(config);
96  return make_unique<TicTacToe>();
97  }
98 
99  unique_ptr<core::PropertySet> defaultConfig(
100  darwin::ComplexityHint hint) const override {
101  auto config = make_unique<Config>();
102  switch (hint) {
104  config->tournament_type.simple_tournament.eval_games = 2;
105  config->tournament_type.simple_tournament.rematches = false;
106  config->tournament_type.selectCase(tournament::TournamentType::Simple);
107  config->calibration_matches = 3;
108  break;
109 
112  break;
113  }
114  return config;
115  }
116 };
117 
118 } // namespace tic_tac_toe
ComplexityHint
A generic hint for the initial population & domain setup.
Definition: darwin.h:47
A population implementation encapsulates the fixed-size set of genotypes, together with the rules for...
Definition: darwin.h:161
best guess for the ideal performance/results trade-offs
bool evaluatePopulation(darwin::Population *population) const override
Assigns fitness values to every genotype.
Definition: tic_tac_toe.cpp:46
bare minimum, fast but poor results (mostly useful for testing)
Tournament configurations.
Definition: tournament_implementations.h:42
size_t inputs() const override
Number of inputs to a Brain.
Definition: tic_tac_toe.cpp:38
AnnType ann_type
"The role of the evolved brains"
Definition: tic_tac_toe.h:40
Interface to the domain factory.
Definition: darwin.h:263
size_t outputs() const override
Number of outputs from a Brain.
Definition: tic_tac_toe.cpp:42
Domain: Tic-tac-toe
Definition: tic_tac_toe.h:82
Tic-Tac-Toe domain configuration.
Definition: tic_tac_toe.h:39
Definition: ann_player.cpp:24
might produce more sophisticated solutions, but very slow
void copyFrom(const PropertySet &src)
Transfer values between two property sets.
Definition: properties.h:416
The foundation for data structures supporting runtime reflection.
Definition: properties.h:388
Swiss-system tournament.
tournament::TournamentVariant tournament_type
"Tournament type"
Definition: tic_tac_toe.h:46
Interface to a domain implementation.
Definition: darwin.h:229
Handles types with a fixed, known set of values (enumerations for example)
Definition: stringify.h:85
A basic tournament implementation.
const Stringify< T > * stringify()
Returns the stringifier for type T.
Definition: stringify.h:166
The interface to the population-specific "genetic material", the Genotype
Definition: darwin.h:126
int calibration_matches
"Number of calibration games"
Definition: tic_tac_toe.h:41