jonathan-laurent / AlphaZero.jl

A generic, simple and fast implementation of Deepmind's AlphaZero algorithm.
https://jonathan-laurent.github.io/AlphaZero.jl/stable/
MIT License
1.23k stars 138 forks source link

Not invoking alternate implementation of select_move #199

Closed bwanab closed 1 year ago

bwanab commented 1 year ago

I apologize that this is probably a julia question, but...

I've written the following code the intent of which is to make a somewhat more sophisticated player than this, but starting with something simple:

using AZ_Reversi      # my reversi game interface
using AlphaZero
using AlphaZero.GI

struct RandomPlayer <: AbstractPlayer end

function select_move(::RandomPlayer, game, turn)
    rand(GI.available_actions(game))
end

experiment = Reversi.Training.experiment

session = Session(experiment)
interactive!(session.env.gspec, RandomPlayer(), AlphaZeroPlayer(session))

The problem is that when I run this, it doesn't invoke the RandomPlayer version of select_move.

Debugging, I put a breakpoint in this method:

function select_move(p::TwoPlayers, game, turn)
  if GI.white_playing(game)
    return select_move(p.white, game, turn)
  else
    return select_move(p.black, game, turn)
  end
end

Looking at p.white it shows RandomPlayer().

When I directly invoke select_move(RandomPlayer(), game, turn) it returns a good value, but when the code runs it invokes the base select_move(::AbstractPlayer, game, turn) version.

My julia isn't that strong, so I'm sure I'm doing something wrong but I can't see what.

bwanab commented 1 year ago

I answered my own question. Sorry about the issue spam.

Two sources of confusion:

  1. I didn't read enough of the code to see there was already a RandomPlayer.
  2. My code needed to preface select_move to be AlphaZero.select_move.