bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::envs::connect2::Connect2 Class Referencefinal

Implementation of Connect2 environment from https://github.com/JoshVarty/AlphaZeroSimple The board has four cells, all empty, 0, at the start. A move puts a stone of the player, 1 or 2, in an empty cell. The player who has two stones in cells next to each other wins, with a reward of 1; a full board with no winner is a draw, with a reward of 0. More...

#include <connect2_env.h>

Inheritance diagram for bitrl::envs::connect2::Connect2:
Collaboration diagram for bitrl::envs::connect2::Connect2:

Public Types

typedef EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > > base_type
 The base type.
typedef base_type::time_step_type time_step_type
 The type of the time step.
typedef base_type::state_space_type state_space_type
 The type describing the state space for the environment.
typedef base_type::action_space_type action_space_type
 The type of the action space for the environment.
typedef base_type::action_type action_type
 The type of the action to be undertaken in the environment.
typedef base_type::state_type state_type
 The state type.
Public Types inherited from bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >
typedef TimeStep< std::vector< uint_t > > time_step_type
 Alias for the type returned when stepping the environment.
typedef DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t >::state_space state_space_type
 Type describing the environment state space.
typedef DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t >::state_type state_type
 Type describing an individual state.
typedef DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t >::action_space action_space_type
 Type describing the environment action space.
typedef DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t >::action_type action_type
 Type representing an individual action.
Public Types inherited from bitrl::envs::DiscreteVectorStateDiscreteActionEnv< StateSpaceSize, AS, AE, StateSpaceItemType >
typedef DiscreteVectorSpace< StateSpaceSize, StateSpaceItemType > state_space
 the state space type
typedef state_space::space_item_type state_type
 the State type
typedef ScalarDiscreteSpace< AS, AE > action_space
 the action space type
typedef action_space::space_item_type action_type
 the Action type

Public Member Functions

 Connect2 ()
 Constructor.
virtual void make (const std::string &version, const std::unordered_map< std::string, std::any > &options, const std::unordered_map< std::string, std::any > &reset_options) override final
 make. Builds the environment. Optionally we can choose if the environment will be slippery
virtual time_step_type step (const action_type &action) override final
 step. Move in the environment with the given action This function always moves player_1
virtual void close () override final
 close
virtual time_step_type reset () override final
 Reset the environment.
uint_t n_states () const noexcept
 n_states. Returns the number of states
uint_t n_actions () const noexcept
 n_actions. Returns the number of actions
time_step_type move (const uint_t pid, const action_type &action)
 Make a move for the player with the given id.
bool is_win (uint_t player) const noexcept
 Returns true if the player has two stones in cells next to each other.
bool has_legal_moves () const noexcept
 Returns true if there are still legal moves to do.
std::vector< uint_t > get_valid_moves () const
 Get the valid moves.
Public Member Functions inherited from bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >
virtual ~EnvBase ()=default
 Virtual destructor.
const std::unordered_map< std::string, std::any > & make_options () const noexcept
 Access the configuration options provided to make().
const std::unordered_map< std::string, std::any > & reset_options () const noexcept
 Access the configuration options provided to make().
T read_option (const std::string &op_name) const
 Read a specific make() option and cast it to the requested type.
std::string idx () const noexcept
 Get the id identifying this environment within a simulation batch. The id is valid only if make has been called.
bool is_created () const noexcept
 Check if make() has successfully initialized the environment.
std::string env_name () const noexcept
 Get the name of this environment instance.
std::string version () const noexcept
 Get the environment version set during make().
uint_t last_reset_seed () const noexcept
 The seed of the latest reset(), for the environments that take one. The first reset after make() uses the "seed" reset option, or DEFAULT_ENV_SEED, and every reset after it the next seed, so that the episodes start differently and a run is the same every time.

Static Public Member Functions

static uint_t n_copies ()

Static Public Attributes

static const std::string name
 name
Static Public Attributes inherited from bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >
static constexpr uint_t DEFAULT_ENV_SEED
 Default seed used in reset() if none provided.
Static Public Attributes inherited from bitrl::envs::DiscreteVectorStateDiscreteActionEnv< StateSpaceSize, AS, AE, StateSpaceItemType >
static constexpr uint_t STATE_SPACE_SIZE = StateSpaceSize
 state space size
static constexpr uint_t ACTION_SPACE_SIZE = action_space::size
 state space size

Additional Inherited Members

Protected Member Functions inherited from bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >
 EnvBase (const std::string &idx=bitsim::consts::INVALID_STR, const std::string &name=bitsim::consts::INVALID_STR)
 Constructor (protected — for subclassing only).
 EnvBase (const EnvBase &)
 Copy constructor.
void set_version_ (const std::string &version) noexcept
 Set internal version string.
void set_idx_ (const std::string &idx) noexcept
 Set the id of the environment.
void set_make_options_ (const std::unordered_map< std::string, std::any > &options) noexcept
 Store options for future access.
void set_reset_options_ (const std::unordered_map< std::string, std::any > &options) noexcept
 Store reset options for future access.
uint_t next_reset_seed_ ()
 The seed for the next reset: the "seed" reset option, or DEFAULT_ENV_SEED, plus the number of resets since make().
void invalidate_is_created_flag_ () noexcept
 Mark environment as not created.
void make_created_ () noexcept
 Mark environment creation as successful.
time_step_type & get_current_time_step_ () noexcept
 Mutable access to the current time step.
const time_step_type & get_current_time_step_ () const noexcept
 Read-only access to the current time step.

Detailed Description

Implementation of Connect2 environment from https://github.com/JoshVarty/AlphaZeroSimple The board has four cells, all empty, 0, at the start. A move puts a stone of the player, 1 or 2, in an empty cell. The player who has two stones in cells next to each other wins, with a reward of 1; a full board with no winner is a draw, with a reward of 0.

Member Typedef Documentation

◆ action_space_type

The type of the action space for the environment.

◆ action_type

The type of the action to be undertaken in the environment.

◆ base_type

◆ state_space_type

The type describing the state space for the environment.

◆ state_type

◆ time_step_type

Constructor & Destructor Documentation

◆ Connect2()

bitrl::envs::connect2::Connect2::Connect2 ( )

Constructor.

Member Function Documentation

◆ close()

void bitrl::envs::connect2::Connect2::close ( )
inlinefinaloverridevirtual

◆ get_valid_moves()

std::vector< uint_t > bitrl::envs::connect2::Connect2::get_valid_moves ( ) const

Get the valid moves.

◆ has_legal_moves()

bool bitrl::envs::connect2::Connect2::has_legal_moves ( ) const
noexcept

Returns true if there are still legal moves to do.

◆ is_win()

bool bitrl::envs::connect2::Connect2::is_win ( uint_t player) const
noexcept

Returns true if the player has two stones in cells next to each other.

◆ make()

virtual void bitrl::envs::connect2::Connect2::make ( const std::string & version,
const std::unordered_map< std::string, std::any > & options,
const std::unordered_map< std::string, std::any > & reset_options )
finaloverridevirtual

make. Builds the environment. Optionally we can choose if the environment will be slippery

Implements bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >.

◆ move()

time_step_type bitrl::envs::connect2::Connect2::move ( const uint_t pid,
const action_type & action )

Make a move for the player with the given id.

◆ n_actions()

uint_t bitrl::envs::connect2::Connect2::n_actions ( ) const
inlinenoexcept

n_actions. Returns the number of actions

◆ n_copies()

uint_t bitrl::envs::connect2::Connect2::n_copies ( )
inlinestatic

Get the number of copies of this class

Returns

◆ n_states()

uint_t bitrl::envs::connect2::Connect2::n_states ( ) const
inlinenoexcept

n_states. Returns the number of states

◆ reset()

virtual time_step_type bitrl::envs::connect2::Connect2::reset ( )
finaloverridevirtual

◆ step()

virtual time_step_type bitrl::envs::connect2::Connect2::step ( const action_type & action)
finaloverridevirtual

step. Move in the environment with the given action This function always moves player_1

Parameters
action
Returns

Implements bitrl::envs::EnvBase< TimeStep< std::vector< uint_t > >, DiscreteVectorStateDiscreteActionEnv< 53, 0, 4, uint_t > >.

Member Data Documentation

◆ name

const std::string bitrl::envs::connect2::Connect2::name
static

name


The documentation for this class was generated from the following file: