Q&A
前提・実現したいこと
アプリケーション内から手牌とアガリ牌を入力して、点数などの情報を出力するプログラムを作りたいのですがエラーがでて困っています。
all_tilesとwin_tileに引数を与えて実行するプログラムのはずなので、アプリケーションで入力した値を2つの変数に代入するように書いたはずなのですが以下のエラー文がでてしまいます。
発生している問題・エラーメッセージ
TypeError: analyze() missing 2 required positional arguments: 'all_tiles' and 'win_tile' ERROR: The function received no value for the required argument: all_tiles Usage: test.py ALL_TILES WIN_TILE <flags> optional flags: --player_wind | --round_wind additional flags are accepted
該当のソースコード
Python
1#!/usr/bin/env python3 2 3 4# Hamukichi (Nombiri), MIT License 5 6 7from mahjong import agari, constants, shanten, tile 8from mahjong.hand_calculating import hand, hand_config 9import fire 10import copy 11import tkinter as tk 12import tkinter.ttk as ttk 13from tkinter import messagebox 14 15global all_tiles 16global win_tile 17 18OPT_RULES = hand_config.OptionalRules(has_open_tanyao=True) 19WIND_STR2CONST = {"EAST": constants.EAST, 20 "SOUTH": constants.SOUTH, 21 "WEST": constants.WEST, 22 "NORTH": constants.NORTH} 23WIND_STR2CHARA = {"EAST": "東", 24 "SOUTH": "南", 25 "WEST": "西", 26 "NORTH": "北"} 27 28def __analyze(all_tiles, win_tile, player_wind, round_wind, **hand_confs): 29 all_tiles_136 = tile.TilesConverter.one_line_string_to_136_array(all_tiles) 30 all_tiles_34 = tile.TilesConverter.one_line_string_to_34_array(all_tiles) 31 win_tile_136 = tile.TilesConverter.one_line_string_to_136_array(win_tile)[0] 32 player_wind = player_wind.upper() 33 round_wind = round_wind.upper() 34 player_wind_136 = WIND_STR2CONST[player_wind] 35 round_wind_136 = WIND_STR2CONST[round_wind] 36 all_hand_confs = copy.copy(hand_confs) 37 all_hand_confs["player_wind"] = player_wind_136 38 all_hand_confs["round_wind"] = round_wind_136 39 config = hand_config.HandConfig(options=OPT_RULES, **all_hand_confs) 40 sh_obj = shanten.Shanten() 41 sh_res = sh_obj.calculate_shanten(all_tiles_34) 42 ag = agari.Agari() 43 if not ag.is_agari(all_tiles_34): 44 return (sh_res, None) 45 else: 46 calc = hand.HandCalculator() 47 hand_res = calc.estimate_hand_value(tiles=all_tiles_136, 48 win_tile=win_tile_136, 49 config=config) 50 wind = "{}場{}".format(WIND_STR2CHARA[round_wind], WIND_STR2CHARA[player_wind]) 51 han_fu = "{} 飜 {} 符".format(hand_res.han, hand_res.fu) 52 if hand_res.han <= 5: 53 basic_score = hand_res.fu * 2 ** (hand_res.han + 2) 54 if basic_score > 2000: 55 gan = "満貫" 56 else: 57 gan = "" 58 elif hand_res.han <= 7: 59 gan = "跳満" 60 elif hand_res.han <= 10: 61 gan = "倍満" 62 elif hand_res.han <= 12: 63 gan = "三倍満" 64 else: 65 n = hand_res.han // 13 66 if n == 1: 67 gan = "役満" 68 else: 69 gan = "{} 倍役満".format(n) 70 71 is_tsumo = hand_confs.get("is_tsumo", False) 72 is_dealer = player_wind == "EAST" 73 if hand_res.han < 1: 74 all_cost = "1 飜縛りを満たしていません" 75 elif is_tsumo: 76 if is_dealer: 77 all_cost = "{} 点 オール".format(hand_res.cost["additional"]) 78 else: 79 all_cost = "{} 点 / {} 点".format(hand_res.cost["additional"], 80 hand_res.cost["main"]) 81 else: 82 all_cost = "{} 点".format(hand_res.cost["main"]) 83 hand_report = {"hand_res": hand_res, "wind": wind, 84 "han_fu": han_fu, "gan": gan, "all_cost": all_cost, "yakus": hand_res.yaku} 85 return (sh_res, hand_report) 86 87 88def analyze(all_tiles, win_tile, player_wind="SOUTH", round_wind="EAST", **hand_confs): 89 analyze_res = __analyze(all_tiles, win_tile, player_wind, round_wind, **hand_confs) 90 sh_res, hand_report = analyze_res 91 if hand_report is None: 92 if sh_res != 0: 93 print("{} 向聴".format(sh_res)) 94 else: 95 print("聴牌") 96 else: 97 print(hand_report["wind"]) 98 print(hand_report["han_fu"], end=" ") 99 print(hand_report["gan"]) 100 print(hand_report["all_cost"]) 101 if hand_report["yakus"] is not None: 102 for yaku in hand_report["yakus"]: 103 print(yaku.japanese) 104 105 106def main(): 107 fire.Fire(analyze) 108 109root = tk.Tk() 110root.title("点数計算") 111root.geometry("500x300") 112 113 114frame = ttk.Frame(root) 115frame.grid(column=0, row=0, sticky=tk.NSEW, padx=5, pady=10) 116 117label = ttk.Label(frame, text="アガリ形") 118entry_all_tiles = ttk.Entry(frame) 119entry_win_tile = ttk.Entry(frame) 120button_execute = ttk.Button(frame, text="点数を計算する", command=analyze) 121 122label.grid(row=0, column=0) 123entry_all_tiles.grid(row=0, column=1) 124entry_win_tile.grid(row=1, column=1) 125button_execute.grid(row=2, column=1) 126 127entry_all_tiles.insert(tk.END,"アガリ形") 128entry_win_tile.insert(tk.END,"アガリ牌") 129 130all_tiles = entry_all_tiles.get() 131win_tile = entry_win_tile.get() 132 133root.mainloop() 134 135if __name__ == '__main__': 136 main()
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2022/01/17 15:32