前提・実現したいこと
ここに質問の内容を詳しく書いてください。
(例)Pythonでblocksというゲームを進行するシステムを作っています。
関数内の関数を呼び出すときにエラーは表示されないのですが、関数内の関数を呼び出せていない気がしますが、色々訂正してもなかなか改善されないため困っています。関数sorta 関数sortarouのどこかでおかしいところがあるのであれば教えていただきたいです。インデントなど変えれそうなところは色々と変えてみました。
全体的にゲームのルールを把握していない状態でこのプログラムを考えることは難しいかもしれませんが、sorta,sorta_b,sorta_cとsortarou,sortarou_b,sortarou_cのそれぞれの三つずつの関数の関係性が間違っているのか、関数内の間違いさえ見つかれば、改善は可能であるとは思います。よろしくお願いします。
発生している問題・エラーメッセージ
関数が呼び出されていないためか、関数を使う手数のところで、ブロックが置かれない問題が生じている。
該当のソースコード
Python
1from blokus.player import Player 2from blokus.utils import encodeFourCode 3from blokus.piece import Pieces 4from blokus.move import getAllMovePatterns 5from operator import itemgetter 6class PlayerA(Player): 7 8 9 def __init__(self): 10 super().__init__() 11 self.list1 = ['t','o','u','j','k'] 12 self.list2 = ['l','m','n','p'] 13 self.list3 = ['a','b','c','d','e','f','g','h','i'] 14 self.count = 0 15 self.logs = [] 16 17 18 def log(self, player, move): 19 self.logs.append((player, move)) 20 def move(self, board, pieces): 21 self.count += 1 22 hand = 'pass' 23 def sorta(): 24 a = getAllMovePatterns(board, self.list1, first=False) 25 list1=sorted(a,key=lambda x: x[0]) 26 if len(a) == 0: 27 hand = sorta_b() 28 return hand 29 elif len(a) != 0: 30 self.list1.remove(list1[0][2]) 31 return list1[0] 32 33 def sorta_b(): 34 a = getAllMovePatterns(board, self.list2, first=False) 35 list1=sorted(a,key=lambda x: x[0]) 36 if len(a) == 0: 37 hand = sorta_c() 38 return hand 39 elif len(a) != 0: 40 self.list2.remove(list1[0][2]) 41 return list1[0] 42 43 def sorta_c(): 44 hand = getAllMovePatterns(board, self.list3, first=False) 45 list1=sorted(hand,key=lambda x: x[0]) 46 if len(hand) == 0: 47 return 'pass' 48 elif len(hand) != 0: 49 self.list3.remove(list1[0][2]) 50 return list1[0] 51 def sortarou(): 52 a = getAllMovePatterns(board, self.list1, first=False) 53 list1=sorted(a,key=lambda x: x[1],reverse = True) 54 if len(a) == 0: 55 hand = sortarou_b() 56 return hand 57 elif len(a) != 0: 58 self.list1.remove(list1[0][2]) 59 return list1[0] 60 def sortarou_b(): 61 a = getAllMovePatterns(board, self.list2, first=False) 62 list1=sorted(a,key=lambda x: x[1],reverse = True) 63 if len(a) == 0: 64 hand = sortarou_c() 65 return hand 66 elif len(a) != 0: 67 self.list2.remove(list1[0][2]) 68 return list1[0] 69 70 71 def sortarou_c(): 72 a = getAllMovePatterns(board, self.list3, first=False) 73 list1=sorted(a,key=lambda x: x[1],reverse = True) 74 if len(a) == 0: 75 return 'pass' 76 elif len(a) != 0: 77 self.list3.remove(list1[0][2]) 78 return list1[0] 79 80 81 if self.count == 1: 82 hand = encodeFourCode(18,1,'s',1) 83 elif self.count == 2: 84 hand = encodeFourCode(15,4,'r',2) 85 elif self.count == 3: 86 hand = encodeFourCode(13,8,'q',2) 87 elif self.count == 4: 88 a = getAllMovePatterns(board, pieces, first=False) 89 if ('aau0' in a) == True: 90 hand = encodeFourCode(9, 9, 'u', 0) 91 return hand 92 elif ('aau0' in a) != True: 93 hand = sorta() 94 elif self.count == 5: 95 hand = sorta() 96 elif self.count == 6: 97 hand = sortarou() 98 elif self.count == 7: 99 hand = sorta() 100 elif self.count == 8: 101 hand = sortarou() 102 elif self.count == 9: 103 hand = sorta() 104 elif self.count >= 10: 105 a = getAllMovePatterns(board, pieces, first=False) 106 list1=sorted(a,key=lambda x: x[2],reverse = True) 107 if len(a) == 0: 108 return 'pass' 109 elif len(a) != 0: 110 return list1[0] 111 return hand 112
試したこと
インデントの改善、関数内の改善。→どれも改善にあたらず。
補足情報(FW/ツールのバージョンなど)
Linux
回答3件
あなたの回答
tips
プレビュー