3

Given a list of poker flops and a str as a target:

target = '5c6d2d'
flops = ['5s4d3s', '6s4d2d', '6s5d3s', '6s4s2d']

I am trying to find the closest match to the target. Currently using fuzzywuzzy.process.extract, but sometimes this doesn't return the desired match. And also (more importantly) it doesn't account for ranks properly because the rank of the face cards are represented by letters so 9c9d9s is more similar too 2c2d2h than it is to TcTdTh. Is there a clever way of parsing the target flop to do this with a simple algorithm? Or would it be best to try and train a machine learning model for this?

Side note in case it's relevant: my fuzzywuzzy uses the pure-python SequenceMatcher as I don't have the privileges to install Visual Studio 14 for python-Levenshtein.

EDIT: To clarify, by closest match I mean the closest in terms of flop texture, i.e. the flop that is strategically the most similar (I understand this is somewhat of a difficult qualification). The initial list of examples I gave is actually not too clear, so here is another example with fuzzywuzzy:

>>> target = '8c8h5s'
>>> flops = ['2d2s6c', '7c5s5d', '8s8d7h', '4h3s3d'] 
>>> matches = process.extract(target, flops)
>>> print(matches)
[('7c5s5d', 50), ('8s8d7h', 50), ('4h3s3d', 33), ('2d2s6c', 17)]

For my purposes '8s8d7h' should score better than '7c5s5d'. So the matching of ranks should be given priority over the matching of suits.

chunpoon
  • 950
  • 10
  • 17

1 Answers1

1

What do you mean by closest match? Do you mean just least number of different characters? If so, here's how you could do it:

def find_closest(main_flop, flops):
  best_match = ''
  matching_characters = 0
  for flop in flops:
      for i, character in enumerate(flop):
          if main_flop[i] == character:
              matching_characters += 1
      if matching characters > max_matching:
          best_match = flop
  return best_match

On the other hand, if you want to find the "closest" flop in terms of how similar of equities it gives to a full range of hands, then you will have to build something quite complex, or use a library like https://github.com/worldveil/deuces or https://poker.readthedocs.io/en/latest/

  • Thanks for the suggestion. I tried to clarify my problem more in the edit. I am not looking for flops close in equity, but for textural similarities. E.g. `As7s5c` should match better with flops with two of a suit rather than flops with one or three of a suit. However, I would prefer if closeness in rank is given priority. – chunpoon Nov 15 '19 at 07:13
  • I think at that point you should make your own scoring function, then sort using that. "Sameness" is hard to define for poker flops and you'll have to write your own function to output a "score" per flop. Then you'll sort using that. – Baptiste Vauthey Nov 19 '19 at 00:04