This repository has been archived by the owner on Jan 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* syncro * Create horoscope.py * Update horoscope.py * Update horoscope.py * Update README.md * Update horoscope.py * Update riddle.py * Update riddle.py * testing * Create horoscope.py * Update STD_PLUGINS.conf * Update riddle.py * Update horoscope.py * Update news.py * Update horoscope.py * Update horoscope.py * Update weather.py * Update horoscope.py * Update horoscope.py * Update horoscope.py * Update riddle.py * Update riddle.py * Update riddle.py * Update riddle.py * Update riddle.py * Update horoscope.py * create russian_roulette plugin * Create converter.py * support converter * test kick command * fix plugin bugs * kick command testing * create python asset files and import in plugin * add monopoly to standard plugins * create echo plugin for testing * debug * add start command * Update monopoly.py * monopoly basis * Update monopoly.py * wierd commit * Update plugins_info.md * Update russian_roulette.py * roll function development * it works!!! OMG * update description * Create echo.py * Delete echo.py * Update STD_PLUGINS.conf * remove echo * monopoly development * monopoly roll command development * community deck * chance card half developed * created card functions, just need to execute * community and chance card development complete * Update monopoly.py * make card arguments iterable * completed all tasks apart from commenting, now testing * bug fixes * fix bugs * fix bugs * fix no plugin. bug * Update monopoly.py * more bug fixes * str not tuple bug fix * even more bug fixes, must check chance function * finally got it to work decently * Update monopoly.py * Update monopoly.py * fix bug * initial development complete * Update monopoly.py * Update plugins_info.md * Update PLUGINS.conf * Update monopoly_assets.py * Update monopoly.py * update the about for currency * bot-suite initial commit * change kill to quit * Update plugins.txt * change structure * Update plugins.txt * honeybot poker assets * bug fix for poker assets * remove bot-suite functions for poker PR
- Loading branch information
1 parent
bca001d
commit 2fe71a6
Showing
14 changed files
with
662 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
''' poker hand evaluator ''' | ||
|
||
# pylint: disable=W0612 | ||
|
||
import itertools | ||
|
||
def best_hand(hand): | ||
''' from a 7-card hand, return the best 5 card hand ''' | ||
|
||
return max(itertools.combinations(hand, 5), key=hand_rank) | ||
|
||
def hand_rank(hand): | ||
''' return a value indicating the ranking of a hand ''' | ||
|
||
ranks = card_ranks(hand) | ||
if straight(ranks) and flush(hand): | ||
return 8, max(ranks) | ||
|
||
elif kind(4, ranks): | ||
# four of a kind | ||
return 7, kind(4, ranks), kind(1, ranks) | ||
|
||
elif kind(3, ranks) and kind(2, ranks): | ||
# full house | ||
return 6, kind(3, ranks), kind(2, ranks) | ||
|
||
elif flush(hand): | ||
# all cards of same suit | ||
return 5, ranks | ||
|
||
elif straight(ranks): | ||
# cards in sequence | ||
return 4, max(ranks) | ||
|
||
elif kind(3, ranks): | ||
# 3 cards of same rank | ||
return 3, kind(3, ranks), ranks | ||
|
||
elif two_pair(ranks): | ||
# 2 pairs of same rank | ||
return 2, two_pair(ranks), ranks | ||
|
||
elif kind(2, ranks): | ||
# 1 pair of same rank | ||
return 1, kind(2, ranks), ranks | ||
|
||
else: | ||
# Nothing (High Card) | ||
return 0, ranks | ||
|
||
def card_ranks(hand): | ||
''' return a list of the ranks, sorted with higher first ''' | ||
|
||
ranks = ['--23456789TJQKA'.index(r) for r, s in hand] | ||
ranks.sort(reverse=True) | ||
# to handle the (A-5) straight case | ||
return [5, 4, 3, 2, 1] if (ranks == [14, 5, 4, 3, 2]) else ranks | ||
|
||
def flush(hand): | ||
''' return True if all the cards have the same suit ''' | ||
|
||
suits = [s for r, s in hand] | ||
return len(set(suits)) == 1 | ||
|
||
def straight(ranks): | ||
''' return True if the ordered ranks form a 5-card straight ''' | ||
|
||
return (max(ranks) - min(ranks) == 4) and len(set(ranks)) == 5 | ||
|
||
def kind(n, ranks): | ||
''' return the first rank that this hand has exactly n-of-a-kind of. Return None if there is no | ||
n-of-a-kind in the hand ''' | ||
|
||
for r in ranks: | ||
|
||
if ranks.count(r) == n: | ||
return r | ||
|
||
return None | ||
|
||
def two_pair(ranks): | ||
''' if there are two pair here, return the two ranks of the two pairs, else None ''' | ||
|
||
pair = kind(2, ranks) | ||
lowpair = kind(2, list(reversed(ranks))) | ||
if pair and lowpair != pair: | ||
return pair, lowpair | ||
|
||
else: | ||
return None | ||
|
||
def test_best_hand(playerhand): | ||
# S = Spade | ||
# D = Diamond | ||
# C = Club | ||
# H = Heart | ||
# assert (sorted(best_hand('6C 7C 8C 9C TC 5C JS'.split())) == ['6C', '7C', '8C', '9C', 'TC']) | ||
# assert (sorted(best_hand('TD TC TH 7C 7D 8C 8S'.split())) == ['8C', '8S', 'TC', 'TD', 'TH']) | ||
# assert (sorted(best_hand('JD TC TH 7C 7D 7S 7H'.split())) == ['7C', '7D', '7H', '7S', 'JD']) | ||
# return 'test_best_hand passes' | ||
# return sorted(best_hand('2D 2C 2H 7C 7D KC KS'.split())) | ||
return sorted(best_hand(playerhand.split())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
''' board class ''' | ||
|
||
# pylint: disable=E1601 | ||
class Board(object): | ||
''' board class ''' | ||
|
||
def __init__(self, board): | ||
''' board initialization ''' | ||
|
||
self.__board = board | ||
self.__flop = board[:3] | ||
self.__flop1 = board[0] | ||
self.__flop2 = board[1] | ||
self.__flop3 = board[2] | ||
self.__turn = board[3] | ||
self.__river = board[4] | ||
|
||
def get_board(self): | ||
'''return card objects of board''' | ||
return self.__board | ||
|
||
def show_board(self): | ||
''' show board ''' | ||
return(" ".join([c.show_card() for c in self.__board])) | ||
|
||
def flop(self): | ||
''' show flop ''' | ||
|
||
return(" ".join([c.show_card() for c in self.__flop])) | ||
|
||
def flop1(self): | ||
''' show flop1 ''' | ||
|
||
return self.__flop1.show_card() | ||
|
||
def flop2(self): | ||
''' show flop2 ''' | ||
|
||
return self.__flop2.show_card() | ||
|
||
def flop3(self): | ||
''' show flop3 ''' | ||
|
||
return self.__flop3.show_card() | ||
|
||
def turn(self): | ||
''' show turn ''' | ||
|
||
return self.__turn.show_card() | ||
|
||
def river(self): | ||
''' show river ''' | ||
|
||
return self.__river.show_card() | ||
|
||
def __len__(self): | ||
return len(self.__board) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
''' card class ''' | ||
|
||
# pylint: disable=E1601 | ||
|
||
class Card(object): | ||
''' card class ''' | ||
|
||
def __init__(self, card): | ||
''' card initialization; Card('8s'), Card('QC') ''' | ||
values = [0,1,2,3] #0 is for a low: 2 3 4, 1 for a medium 4 5 6 7, 2 for a high 8 9 10, 3 for a suit J Q K A | ||
|
||
self.__figure = card[0] | ||
self.__color = card[1].upper() | ||
self.__card = self.__figure + self.__color | ||
|
||
if self.__figure == 'A': | ||
self.__value = 14 | ||
|
||
elif self.__figure == 'K': | ||
self.__value = 13 | ||
|
||
elif self.__figure == 'Q': | ||
self.__value = 12 | ||
|
||
elif self.__figure == 'J': | ||
self.__value = 11 | ||
|
||
elif self.__figure == 'T': | ||
self.__value = 10 | ||
|
||
else: | ||
self.__value = int(self.__figure) | ||
|
||
def show_card(self): | ||
''' show card ''' | ||
if self.__card == "0X": | ||
print("This card does not exist, check your index!") | ||
pass | ||
else: | ||
return self.__card | ||
|
||
def figure(self): | ||
''' show figure ''' | ||
|
||
return self.__figure | ||
|
||
def color(self): | ||
''' show color ''' | ||
|
||
return self.__color | ||
|
||
def value(self): | ||
''' show value ''' | ||
|
||
return self.__value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
''' deck class ''' | ||
|
||
# pylint: disable=E1601, W0612 | ||
|
||
import random | ||
import card | ||
|
||
class Deck(object): | ||
''' deck class ''' | ||
|
||
colors = ['C', 'D', 'H', 'S'] | ||
figures = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'] | ||
|
||
i = 0 | ||
for color in colors: | ||
|
||
for figure in figures: | ||
|
||
locals()['card%s' % i] = card.Card(figure + color) | ||
i += 1 | ||
def __init__(self): | ||
''' deck initialization ''' | ||
|
||
self.__deck = [] | ||
for color in self.colors: | ||
|
||
for figure in self.figures: | ||
|
||
self.__deck.append(card.Card(figure + color)) | ||
|
||
def show_deck(self): | ||
''' show deck ''' | ||
|
||
return(" ".join([c.show_card() for c in self.__deck])) | ||
|
||
def nth_card(self, n): | ||
''' show the n-th card from deck ''' | ||
|
||
try: | ||
return self.__deck[n] | ||
except BaseException: | ||
print('Wrong index') | ||
return card.Card("0X") | ||
|
||
def draw_by_number(self, nr): | ||
''' pick card from deck by nr ''' | ||
|
||
try: | ||
pick = self.__deck[nr] | ||
if pick == "OX": | ||
raise BaseException | ||
self.__deck.remove(pick) | ||
return pick | ||
|
||
except BaseException: | ||
print('Wrong index') | ||
return card.Card("0X") | ||
|
||
def draw_by_name(self, name): | ||
''' pick card from deck by name ''' | ||
|
||
flag = 0 | ||
for pick in self.__deck: | ||
|
||
if pick.show_card() == name: | ||
self.__deck.remove(pick) | ||
flag = 1 | ||
break | ||
|
||
if flag == 0: | ||
print('Wrong name') | ||
pass | ||
|
||
else: | ||
return pick | ||
|
||
def make_board(self): | ||
''' make a random board ''' | ||
|
||
board = [] | ||
for i in range(5): | ||
|
||
random_number = random.randint(0, len(self.__deck) - 1) | ||
board.append(self.draw_by_number(random_number)) | ||
|
||
return board | ||
|
||
def make_hand(self): | ||
''' make a random hand ''' | ||
|
||
hand = [] | ||
for i in range(2): | ||
|
||
random_number = random.randint(0, len(self.__deck) - 1) | ||
hand.append(self.draw_by_number(random_number)) | ||
|
||
return hand | ||
|
||
def __len__(self): | ||
'''return the number of cards in the deck ''' | ||
return len(self.__deck) |
Oops, something went wrong.