WillFlame14 / hanabi-bot

A bot that plays on the hanab.live interface.
GNU General Public License v3.0
14 stars 9 forks source link

Disallowed duplicated hidden finesses are not actually disallowed #269

Closed flackr closed 4 weeks ago

flackr commented 1 month ago

I suspect the disallowed hidden finesse of cards which may be duplicated in the giver's hand may be in the wrong place in the code.

// Could be duplicated in giver's hand - disallow hidden finesse unless it could be a bluff.
if (!bluff && giver === state.ourPlayerIndex && state.hands[giver].some(c => c.clued && game.players[giver].thoughts[c.order].inferred.has(identity))) {
  logger.warn(`disallowed hidden finesse on ${logCard(finesse)} ${finesse.order}, true ${logCard(identity)} could be duplicated in giver's hand`);
  return;
}

While I think it may be a good idea for the bot to avoid giving a layered finesse that duplicates a card in its own hand, I think having this code here prevents it from correctly understanding someone else giving such a clue.

E.g.

xx xx xx xx
xx p1 xx xx
xx r2 xx xx
g1 r1 xx xx

Alice clues 1 to Bob. Bob clues red to Cathy.

In this situation, Bob fully believes he may have a g1, but I think Cathy should still interpret the clue as if it could be a layered finesse through Donald's hand.

I read through https://hanabi.github.io/level-5 and don't see anything saying that you should avoid potentially duplicating your own hand. Even if it did duplicate Bob's hand it would be trivial for someone else to fix this later with a fix clue.

WillFlame14 commented 4 weeks ago

The condition already includes giver === state.ourPlayerIndex, which means that the bot is only prevented from giving such clues but will interpret clues from others correctly.

This is because of the Certain Finesse convention at level 10 ("...performing a Layered Finesse on a card that could potentially be clued in your own hand is illegal").

Is there a particular replay where you found the bot didn't interpret such a clue correctly? #180 was an example of this issue which I fixed a few updates ago.

flackr commented 4 weeks ago

Interesting, the example is nice and simple and makes sense when the potentially duplicated card would be known by the blind discard. Does this still apply if the duplicated card's position would not be known by the blind discard? E.g. if instead of having a red card Alice had two 3's clued in hand?

The condition already includes giver === state.ourPlayerIndex, which means that the bot is only prevented from giving such clues but will interpret clues from others correctly.

Oops, thanks for pointing this out. Do you think we should replicate this for the real identity of bluffed cards? I have seen cases where the bot bluffs out cards that it may have? I had to add the !bluff at the time because it was using the assumed identity of the bluffed card.

WillFlame14 commented 4 weeks ago

Does this still apply if the duplicated card's position would not be known by the blind discard? E.g. if instead of having a red card Alice had two 3's clued in hand?

Yes, as far as I know it works like a Sarcastic Discard where position isn't and doesn't need to be promised. It's just a convention to avoid duplication, at the cost of a little bit of tempo.

Do you think we should replicate this for the real identity of bluffed cards?

Conventionally, Certain Finesses cannot be given from bluff seat (see the last bullet point of the Certain Finesse convention), so we don't need to worry about this. Personally, I think this is reversed; it makes more sense to me to disallow a Bluff when a Certain Finesse could be possible, but that's not how it's written.

flackr commented 4 weeks ago

Conventionally, Certain Finesses cannot be given from bluff seat (see the last bullet point of the Certain Finesse convention), so we don't need to worry about this. Personally, I think this is reversed; it makes more sense to me to disallow a Bluff when a Certain Finesse could be possible, but that's not how it's written.

Right, I get that you're allowed to duplicate cards in your own hand with a bluff, but I was wondering if the bot should avoid the real identity of a bluffed card potentially duplicating one of its own clued cards to avoid the need to potentially fix it later. Maybe it's even a question of probability, e.g. given three 1's in hand, there's a 3/5 probability that bluffing a 1 out will duplicate one of your own and since it isn't certain the receiver can't discard it so it will result in a bad touch that eventually may need to be fixed.

E.g. Alice (the bot) should probably not give the blue clue here. But we should still interpret it correctly if the clue is given since I think most people may not pay close enough attention to realize they may have a duplicate.

** *1 *1 *1
g1 ** ** **
** b2 ** **
** ** ** ** 
flackr commented 4 weeks ago

Closing this since my understanding of the code was incorrect - it only prevents the bot from giving such clues not interpreting it from others. I'll open a PR later with an idea for avoiding duplication with bluffs and we can debate the details there.