~bonbon/gmcts

bc629d43b5275a68541a130aa8fae7352b71bbec — bonbon 1 year, 3 months ago 874afca
update README to reflect v2.0 changes
4 files changed, 19 insertions(+), 8 deletions(-)

M README.md
M mcts.go
M models.go
M search.go
M README.md => README.md +12 -2
@@ 55,7 55,12 @@ func runGame() {
        mcts.AddTree(tree)

        //Get the best action based off of the trees collected from mcts.AddTree()
        bestAction := mcts.BestAction()
        bestAction, err := mcts.BestAction()
        if err != nil {
            //...
            //handle error
            //...
        }

        //Update the game state using the tree's best action
        gameState, _ = gameState.ApplyAction(bestAction)


@@ 84,7 89,12 @@ for i := 0; i < concurrentTrees; i++ {
//Wait for the 4 trees to finish searching
wait.Wait()

bestAction := mcts.BestAction()
bestAction, err := mcts.BestAction()
if err != nil {
    //...
    //handle error
    //...
}

gameState, _ = gameState.ApplyAction(bestAction)
```

M mcts.go => mcts.go +1 -1
@@ 33,7 33,7 @@ func (m *MCTS) SpawnTree() *Tree {
}

//SetSeed sets the seed of the next tree to be spawned.
//This value is initially set to 1, and increments on each
//This value is initially set to 0, and increments on each
//spawned tree.
func (m *MCTS) SetSeed(seed int64) {
	m.mutex.Lock()

M models.go => models.go +4 -5
@@ 10,8 10,8 @@ type Player int

//Game is the interface that represents game states.
//
//Any implementation of Game should be comparable (i.e. be a key in a map)
//and immutable (state cannot change as this package calls any function).
//Any implementation of Game should be immutable
//(state cannot change as this package calls any function).
type Game interface {
	//Len returns the number of actions to consider.
	Len() int


@@ 45,9 45,8 @@ type gameHash struct {

	//This is to separate states that seemingly look the same,
	//but actually occur on different turn orders. Without this,
	//the directed tree that multiple parent nodes will just
	//become a directed graph, which this MCTS implementation
	//cannot handle properly.
	//the directed acyclic graph will become a directed cyclic graph,
	//which this MCTS implementation cannot handle properly.
	turn int
}


M search.go => search.go +2 -0
@@ 20,6 20,8 @@ func initializeNode(g gameState, tree *Tree) *node {
	}
}

//UCT2 algorithm is described in this paper
//https://www.csse.uwa.edu.au/cig08/Proceedings/papers/8057.pdf
func (n *node) UCT2(i int, p Player) float64 {
	exploit := n.children[i].nodeScore[p] / float64(n.children[i].nodeVisits)