2 Replies - 1285 Views - Last Post: 17 October 2012 - 05:11 PM Rate Topic: -----

#1 phca2011  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-October 12

How to detect a cheat

Posted 17 October 2012 - 02:57 PM

Hi guys,

I have to make a code where I have to detect that a player cheat.

For example, I have two hands of poker:

3♣ A♣ 3♣ 6♦ 7♠ < A♠ A♦ K♦ Q♥ J♣

It's obvious that player one cheats because we can't have two 3♣.

I want to put 0 to the first hand because I won't let a player play with a tricky hand !


My values and suits are in a dictionnary:

value = {'2': 1, '3': 2, '4': 3, '5': 4, '6': 5, '7': 6, '8': 7, '9': 8, '10': 9,
'J': 10, 'Q': 11, 'K': 12, 'A': 13}

I just want some clue !

Thanks guys !

Is This A Good Question/Topic? 0
  • +

Replies To: How to detect a cheat

#2 Motoma  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 796
  • Joined: 08-June 10

Re: How to detect a cheat

Posted 17 October 2012 - 03:44 PM

A set is a collection type that will only contain unique objects: you could therefore put each player's hand into a set, and if the set doesn't equal five cards, there is a duplicate:

value = {'2': 1, '3': 2, '4': 3, '5': 4, '6': 5, '7': 6, '8': 7, '9': 8, '10': 9, 'J': 10, 'Q': 11, 'K': 12, 'A': 13}
suit = {'Clubs': 1, 'Diamonds': 2, 'Spades': 3, 'Hearts': 4}

# Using the hands above:
player1 = [(2, 1), (13, 1), (2, 1), (7, 2), (8, 3)]
player2 = [(13, 3), (13, 2), (12, 2), (11, 4), (10, 1)]

if is_cheating_hand(player1):
    print("Player 1 is cheating")
if is_cheating_hand(player2):
    print("Player 2 is cheating")

def is_cheating_hand(hand):
    # If the hand with duplicates removed is not the same length
    # as the original hand, there was at least one duplicate card
    return len(set(hand)) != len(hand)


Was This Post Helpful? 1
  • +
  • -

#3 phca2011  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-October 12

Re: How to detect a cheat

Posted 17 October 2012 - 05:11 PM

Thanks it works !
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1