t0nyx1ang / noqx Goto Github PK
View Code? Open in Web Editor NEWExtended logic puzzle solver of noq.
License: GNU General Public License v3.0
Extended logic puzzle solver of noq.
License: GNU General Public License v3.0
All the connectivity structures contain three parts:
Hence, it is possible to create a uniform constructor.
The following things are regarded as a connectivity structure:
Current adjacent relationship are not tied to color, but it is possible to add a color specification on it.
This process may reduce propagation time, as many branches are ignored during the adjacent calculation.
for hitori, add a "safe" cell condition
for kuromasu, add both "safe" and "unsafe" cell condition
Nonogram UI: parameter loading is not by a standard approach.
Yajikazu UI: example loading is wrong.
An example has been added to dev branch.
As the rule of onsen mentioned, there is an empty circle case.
This feature aims to make solvers behave like plugins.
The following code might be used:
def solve(E: encoding) -> str:
# do anything or use the default behavior
For large grids, the performance of current solver is degraded.
该接口能够更好表达行列元素相同
In a common shading puzzle, the shading rule should be:
{ black(R, C) } :- grid(R, C).
black(r1, c1).
not black(r2, c2).
But the shading space could be reduced by:
{ black(R, C) } :- grid(R, C), not clue(R, C).
clue(R, C).
We are unsure whether the second approach is better.
maybe a separation in the game types is better?
Some rules and constraints are general, while others are not. Putting specific rules and constraints in the utils will make more efforts to maintain.
So, if a rule/constraint is assumed to be specific to only one puzzle, it will be moved to the puzzle's workspace. Once this rule/constraint can be extended to different puzzles, we will consider to put it back to the utils.rules directory.
Currently, the following rules/constraints will be modifed:
The following rules/constraints may be modifed:
Currently transformed solver(s):
As far as we think, Django would be too large for a simple application like noqx which only interacts with APIs.
Hence, we will replace django with FastAPI + uvicorn + jinja2 for simplicity.
We can see that all the clues are gone.
This issue can be avoided in 73e1591, just before the initial value is set. So the issue is along with the initial value setting.
Analysis of this bug:
DirectSum
function merges the NonogramElf
with BgColorElf
, and both elves handle "Delete Key"BgColorElf
will call Elf
first, which will clear the innerTextHTMLMethods to fix:
BgColorElf
firstThe user can't jump to the rule pages since fivecells and fourcells are different puzzle types in puzz.link.
Current adjacent rule are not very flexible, since only one adjacent types can be included in the program.
Consider the case that different colors have different adjacent rules. The adjacent rule is invalid here.
Since many puzzles can be played on <puzz.link>, it is natural to use the globally recognized pzprv3 format. In this way, noqx will become a solving backend eventually, and the frontend will be implemented simply by adding a html object
tag:
A sample frontend is as follows (with problem loading):
<script>
function changeData() {
var object = document.getElementById('object');
object.data = "https://puzz.link/p?type=player&embed=yes&pzprv3/nonogram/6/6/.%20.%20.%20.%201%20.%201%20.%20.%20/.%20.%20.%202%201%20.%201%202%20.%20/.%20.%20.%201%201%201%201%201%20.%20/.%202%201%20%23%20%23%20%2B%20%23%20%2B%20%2B%20/.%201%201%20%23%20%2B%20%2B%20%2B%20%23%20%2B%20/.%201%202%20%2B%20%23%20%2B%20%23%20%23%20%2B%20/.%20.%20.%20%2B%20%2B%20%2B%20%2B%20%2B%20%2B%20/.%201%201%20%23%20%2B%20%2B%20%2B%20%23%20%2B%20/.%20.%203%20%2B%20%23%20%23%20%23%20%2B%20%2B%20//";
}
</script>
<div class="object-container" style="text-align: center;">
<object
data="https://puzz.link/p?type=player&embed=yes&pzprv3/nonogram/6/6/.%20.%20.%20.%201%20.%201%20.%20.%20/.%20.%20.%202%201%20.%201%202%20.%20/.%20.%20.%201%201%201%201%201%20.%20/.%202%201%20.%20.%20.%20.%20.%20.%20/.%201%201%20.%20.%20.%20.%20.%20.%20/.%201%202%20.%20.%20.%20.%20.%20.%20/.%20.%20.%20.%20.%20.%20.%20.%20.%20/.%201%201%20.%20.%20.%20.%20.%20.%20/.%20.%203%20.%20.%20.%20.%20.%20.%20//"
style="width: 80%; height: 95%;" id="object">
</object>
</div>
<div class="button-container" style="text-align: center;">
<button onclick="changeData()" style="align-content: center;">Solve!</button>
</div>
I plan to implement this after 90% or more solvers in noqx are solved in Clingo.
我们以Hitori为例,讲一下如何给一个puzzle增加初始条件。
首先是前端部分:这些puzzle前端部分的代码主要在static/noq/elves.js中。以Hitori为例,首先在代码最后的
let elf_types = {
...
}
中找到
hitori: HitoriElf,
可以发现,Hitori前端完全依靠HitoriElf。随后我们在文件中查找HitoriElf的定义部分并进行修改:
class HitoriElf extends
增加初始条件其实只需要把extends的class变为
DirectSum(
class, BgColorElf({'x': ['black', 'darkgray']}, false)
)
即可,也就是在原先的基础上加了一个BgColorElf,初始条件设定使用BgColorElf即可。注意到设置颜色(初始值)一般是用x键,但Hitori的LetterElf把x键给占了(被我们魔改掉了),因此这里我们把设置初始值的按键改为x。
到此前端部分修改完毕。下面修改后端部分:
在solvers文件夹下找到hitori.py,找到里面的solve函数,打印一下E.clues可以发现,加了颜色之后发现clues中对应的value会从(比如)4变为['4', 'black']。因此我们可以把含有gray的格子加上必须染色的约束,并把相应的value从['4', 'gray']改回4:
K = list(E.clues.keys())
for i, (r, c) in enumerate(K):
if isinstance(E.clues[(r, c)], list):
num, color = E.clues[(r, c)]
assert color == 'black'
require(s.grid[r][c])
E.clues[(r, c)] = int(num) if '0' <= num <= '9' else num
这样初始条件就加好啦!
reference puzzle: https://jh2024.jianghujiemi.fun/puzzle/beam
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.