lab_ml
Lazy Machine Learning
NimLearner Class Reference

Represents a algorithm to learn the game of Nim. More...

#include <NimLearner.h>

Collaboration diagram for NimLearner:
[legend]

Public Member Functions

 NimLearner (unsigned startingTokens)
 Constructor to create a game of Nim with startingTokens starting tokens. More...
 
std::vector< EdgeplayRandomGame () const
 Plays a random game of Nim, returning the path through the state graph as a vector of Edge classes. More...
 
void updateEdgeWeights (const std::vector< Edge > &path)
 
void labelEdgesFromThreshold (int threshold)
 Label the edges as "WIN" or "LOSE" based on a threshold. More...
 
const GraphgetGraph () const
 Returns a constant reference to the state space graph. More...
 

Private Attributes

Graph g_
 
Vertex startingVertex_
 

Detailed Description

Represents a algorithm to learn the game of Nim.

Constructor & Destructor Documentation

◆ NimLearner()

NimLearner::NimLearner ( unsigned  startingTokens)

Constructor to create a game of Nim with startingTokens starting tokens.

This function creates a graph, g_ representing all of the states of a game of Nim with vertex labels "p#-X", where:

  • # is the current player's turn; p1 for Player 1, p2 for Player2
  • X is the tokens remaining at the start of a player's turn

For example: "p1-4" is Player 1's turn with four (4) tokens remaining "p2-8" is Player 2's turn with eight (8) tokens remaining

All legal moves between states are created as edges with initial weights of 0.

Parameters
startingTokensThe number of starting tokens in the game of Nim.

Member Function Documentation

◆ getGraph()

const Graph & NimLearner::getGraph ( ) const

Returns a constant reference to the state space graph.

Returns
A constant reference to the state space graph.

◆ labelEdgesFromThreshold()

void NimLearner::labelEdgesFromThreshold ( int  threshold)

Label the edges as "WIN" or "LOSE" based on a threshold.

◆ playRandomGame()

std::vector< Edge > NimLearner::playRandomGame ( ) const

Plays a random game of Nim, returning the path through the state graph as a vector of Edge classes.

The origin of the first Edge must be the vertex with the label "p1-#", where # is the number of starting tokens. (For example, in a 10 token game, result[0].origin must be the vertex "p1-10".)

Returns
A random path through the state space graph.

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