Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add initial conditions in puzzles #1

Closed
T0nyX1ang opened this issue Jan 7, 2024 · 0 comments · Fixed by #11
Closed

[Feature] Add initial conditions in puzzles #1

T0nyX1ang opened this issue Jan 7, 2024 · 0 comments · Fixed by #11
Assignees
Labels
enhancement New feature or request

Comments

@T0nyX1ang
Copy link
Owner

T0nyX1ang commented Jan 7, 2024

在solver中增加初始条件

我们以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

这样初始条件就加好啦!

@T0nyX1ang T0nyX1ang added the enhancement New feature or request label Jan 7, 2024
T0nyX1ang added a commit that referenced this issue Jan 11, 2024
@T0nyX1ang T0nyX1ang pinned this issue Jan 18, 2024
@T0nyX1ang T0nyX1ang linked a pull request Feb 3, 2024 that will close this issue
@T0nyX1ang T0nyX1ang reopened this Feb 3, 2024
@T0nyX1ang T0nyX1ang unpinned this issue Feb 3, 2024
T0nyX1ang added a commit that referenced this issue Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants