cangiuli / hanabi

2 stars 1 forks source link

memory for players #6

Open fpvandoorn opened 8 years ago

fpvandoorn commented 8 years ago

I tried adding a ref representing the memory of the players here: 52297b38f307785414d226703312b1186a966833 This is a summary of my approach:

  val play : unit -> state -> action =
  let
    val m : memory ref = ref initialMemory
  in
    fn u => fn s =>
    (...)
  end

I have two problems:

Any ideas?

fpvandoorn commented 8 years ago

A workaround to both problems is to add turnNumber to state, and on the first turn of a player (re)set the memory to initialMemory (players s). I'd be happy to implement that, unless you have a better idea (requiring that the players themselves forget the information of last game is maybe not the best way to set things up).

fpvandoorn commented 8 years ago

I destructively updated my branch, so I don't know whether the above commit will disappear. It's the "start on memory" commit on my personal branch. On that branch, I also added the workaround mentioned in the previous comment.

cangiuli commented 8 years ago

You want the memory initialization to be underneath the fn u, so it gets evaluated every time play () is evaluated. In other words, fun play () = let val ... in fn s => ... end.

fpvandoorn commented 8 years ago

I see that what I did is wrong, in the sense that the players now share memory, which is clearly not what we want. But what you suggest, how does that work? Then every turn there is a different ref, and the data of the ref of that player's previous turn cannot be accessed, right? Probably I am just misunderstanding what your plan was/is.

cangiuli commented 8 years ago

Think of this function as a "player-maker". When you apply it to () you get back a fresh player with initialized memory. This player now functions like the old version of play: you call it every turn with the new state; it just happens to remember what was going on the last time you called it. The only time you deal with the player-maker directly is when you initialize a new game; otherwise you just call the player itself (the thing of type state -> action).

This will also require modifying the game loop and a bunch of interfaces, so it might be better if I take a crack at it. Unfortunately I have some actual research to do at the moment. :)

fpvandoorn commented 8 years ago

I managed to make the memory work. It now remembers the data from the previous turn and new refs are used in new games.