cangiuli/hanabi

modify play datatype

Opened this issue · 2 comments

The datatype play is currently

  datatype play = Discarded of card
                | Played of card
                | HintedSuit of player * suit * card list
                | HintedRank of player * rank * card list

This has two problems:

  • It is not clear which card is played/discarded when a player has two copies of the same card in their hand.
  • The information which was known about the played/discarded card is lost.

I propose to replace the occurrences of card by the rank of that card in the hand. Also, in Played and Discarded add fields of type info list which represents all the clues given to that player while that card was in their hand. Concretely, the datatype will be

  datatype play = Discarded of int * info list
                | Played of int * info list
                | HintedSuit of player * suit * int list
                | HintedRank of player * rank * int list

This has as extra advantage that the fields HintedSuit/HintedRank don't have to be modified for the player Me before passing the information.

A different thing: I think it would also simplify things a little bit if datatype player (which is currently Me | Other of int is just int, where 0 is Me and i+1 is Other i)

If you agree, I can make these changes (or if you want you can do them, that's of course also fine, but then please first merge my branch personal to avoid merge conflicts).

I wrote a function which returns a list of the states of the last n turns (from the perspective of a player) here (but there are probably still bugs in it, I haven't actually tested it).

To make this possible the datatype play now is

  (* Played has arguments: (index of card, card, successfulness (false=bomb),
   * clues given on that card, whether a hint was received as result of that play) *)
  datatype play = Discarded of int * card * info list
                | Played of int * card * bool * info list * bool
                | HintedSuit of player * suit * int list
                | HintedRank of player * rank * int list

I tested both the memory and the function which returns the previous states by "remembering" the current state, and then in the next turn comparing that memory with the state computed from the log, and they agree (of course there may still be obscure bugs).