LoginSignup
0
2

More than 5 years have passed since last update.

めざせpythonライブラリマスター (68)pazudorasolver

Posted at

【ライブラリ説明】

 パズドラで最適な解を求められる?
 (コードについてはよく分からない・・・)
 (実行結果もどうやって使っていいのか分からない・・・)

【環境】

 python2.7では実行時にライブラリのエラーが出たため、python3.5で実行

【プログラム】

# -*- coding: utf-8 -*-

from pazudorasolver.board import Board
from pazudorasolver.piece import Fire, Wood, Water, Dark, Light, Heart, Poison, Jammer, Unknown
from pazudorasolver.heuristics.greedy_dfs import GreedyDfs
from pazudorasolver.heuristics.pruned_bfs import PrunedBfs

weights = {Fire.symbol: 2.0,
           Wood.symbol: 2.0,
           Water.symbol: 2.0,
           Dark.symbol: 2.0,
           Light.symbol: 2.0,
           Heart.symbol: 1.0,
           Poison.symbol: 0.5,
           Jammer.symbol: 0.5,
           Unknown.symbol: 0.0}

board = Board.create_randomized_board(5, 6)
matches = board.get_matches()

print(board)
print(matches)

# try GreedyDfs heuristic
solver1 = GreedyDfs(weights)
solution = solver1.solve(board, 50)

print(solution)

# try PrunedBfs heuristic
solver2 = PrunedBfs(weights)
solution = solver2.solve(board, 50)

print(solution)

【結果】

  | 0 1 2 3 4 5
---------------
0 | G B G Y B P
1 | B Y B R R Y
2 | Y Y Y P G Y
3 | R P G H R B
4 | R H G P H H

[(Y, {(2, 0), (2, 1), (2, 2)})]
(2163.113082258987, ((2, 2), (0, -1), (-1, 0), (-1, 0), (0, -1), (0, 1), (0, -1), (0, 1), (0, 1), (0, -1), (0, -1), (0, 1), (0, -1), (0, 1), (0, 1), (0, -1), (0, 1), (0, 1), (0, 1), (0, 1), (1, 0), (-1, 0), (1, 0), (1, 0), (-1, 0), (1, 0), (-1, 0), (-1, 0), (1, 0), (-1, 0), (1, 0), (1, 0), (-1, 0), (1, 0), (-1, 0), (-1, 0), (1, 0), (-1, 0), (1, 0), (1, 0), (-1, 0), (-1, 0), (1, 0), (-1, 0), (1, 0), (1, 0), (-1, 0), (1, 0), (-1, 0), (1, 0), (-1, 0)),   | 0 1 2 3 4 5
---------------
0 | G G Y B P Y
1 | B B B R R Y
2 | Y Y Y P G Y
3 | R P G H R B
4 | R H G P H H
)
(4293.289237815047, ((2, 4), (-1, 0), (0, -1), (0, -1), (0, -1), (-1, 0), (0, 1), (1, 0), (0, 1), (-1, 0), (0, -1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, -1), (0, 1), (0, -1), (0, 1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, -1), (0, 1), (0, -1), (0, 1), (0, -1), (0, 1), (0, 1), (0, -1), (0, 1)),   | 0 1 2 3 4 5
---------------
0 | G G G Y B P
1 | B B B Y R Y
2 | Y Y Y P R Y
3 | R P G H R B
4 | R H G P H H
)

pythonのIDE、Spyderで実行したが出力結果のボードは色付きで表示されていた。

【参考サイト】

github
pypi

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2