Can you find the best solution in Puzzle & Dragons? (I'm not sure about the code ...) (I don't know how to use the execution result ...)
In python2.7, I got a library error at runtime, so I ran it in 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
)
I ran it with python's IDE, Spyder, but the output board was displayed in color.
Recommended Posts