Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]fixed check flush bags and improve api performance #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[fix]fixed check flush bags and improve api performance
前回の修正でflush 判定に不具合があったので修正したのと
一部メソッドについてparameter をlist -> string に変更しました。
namagon committed Jul 25, 2017
commit 0d04df76af4a9ebd7e2fdc2acadbf9f96c8bde9c
33 changes: 22 additions & 11 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -129,21 +129,24 @@ def get_best_hands(best_hands, hands):

def seven_hand_checker(param_hands):
u"""
:param list param_hands: ハンド + コミュニティの7枚のカード
:param string param_hands: ハンド + コミュニティの7枚のカード
:return list best_hands: ハンドの中で最も強い組み合わせ
"""
# todo: 適切なライブラリはないか?
# start_time = time.time()
global CARDS_RANK

#
hands = param_hands.split(',')
val_hands = []
for val in param_hands:
for val in hands:
val_hands.append({"rank": list(val)[0], "suit": list(val)[1]})

# ハンド + ボードをソートする
val_hands = sorted(val_hands, key=lambda x: CARDS_SUIT[x['suit']])
val_hands = sorted(val_hands, key=lambda x: CARDS_RANK[x['rank']], reverse=True)

sorted_hands_list = list(itertools.combinations(val_hands, 5))
# print(sorted_hands_list)

best_hands = None
for sorted_hands in sorted_hands_list:
@@ -153,9 +156,6 @@ def seven_hand_checker(param_hands):
hands = hand_checker(sorted_hands)
best_hands = get_best_hands(best_hands, hands)

# end_time = time.time()
# interval = end_time - start_time
# print("seven: " + str(interval) + "sec")
return best_hands


@@ -165,7 +165,9 @@ def hand_checker(param_hands):
:param list param_hands: ハンド
:return dict: 判定結果
"""
# todo: そもそもハンド + ボード で一気に判定できない?
global CARDS_RANK
global CARDS_SUIT
# start_time = time.time()

# todo: rank_num の要素数無意味に15個とってしまっている
@@ -199,8 +201,10 @@ def hand_checker(param_hands):
is_straight = True

# フラッシュ判定
# todo: param_hands[-1](存在しない) != param_hands[0] みたいな実装してるのはよろしくない。
# todo: 最悪len(p_h) for<len-1とかで実装する
for i, hands in enumerate(param_hands):
if hands != param_hands[i + 1]['suit']:
if CARDS_SUIT[param_hands[i - 1]['suit']] != CARDS_SUIT[param_hands[i]['suit']]:
is_flush = False
break

@@ -267,9 +271,17 @@ def get_hand(hands, community):
return None


def get_community_simulation(community):
def get_community_simulation(param_com):
u"""
ボード生成メソッド
:param string param_com: ボード
:return list com_list: ボードとなるハンドの一覧:
"""
global cards

# list型への変換は先で行う
community = param_com.split(',')

com_list = []
if len(community[0]) == 0:
gen_list = list((itertools.combinations(cards, 5)))
@@ -303,7 +315,7 @@ def equity_calculator():
# すでに使われいているカードをデッキから排除
remove_cards(post_param)

community = post_param['community'].split(',')
community = post_param['community']
com_sim = get_community_simulation(community)

# todo: このループ3回やってるんだよなぁ・・・
@@ -319,8 +331,7 @@ def equity_calculator():
# todo: このループ3回やってるんだよなぁ・・・
for key, value in post_param.items():
if re.compile("player*").search(key):
hands = value["hands"].split(',') + com_val
#print(hands)
hands = value["hands"] + ',' + ','.join(com_val)
hands_rank = seven_hand_checker(hands)
hands_rank['player'] = key
hands_rank['is_best'] = True