マンハッタン距離の計算を使用して、python で 8 パズルのさまざまな種類の並べ替えアルゴリズムを試していました。バブルとマージで完了。具体的には、クイックソートを実現しようとしています。
以下のコードは私にエラーを与えます:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'
キューは、要素 (現在の状態、親ノード、深さ、パスコスト、manhattanDistance、MisplacedTilesDistance ) を持つ 8 つの Puzzle 状態のノードのリストです。
改善のための指針
def quickSort(queue, length):
less = []
pivotList = []
more = []
returnList = []
if length <= 1:
return queue
else:
if queue == []:
return
else:
pivot = queue[0][3] + queue[0][4]
for i in queue:
if i[3]+i[4] < pivot:
less.append(i)
print less
input("yes")
elif i[3]+i[4] > pivot:
more.append(i)
else:
pivotList.append(i)
less = quickSort(less, length)
more = quickSort(more, length)
#returnList.append(less, pivotList, more)
return less + pivotList + more