wooster0 / yayagram

Play nonograms/picross in your terminal
https://crates.io/crates/yayagram
38 stars 2 forks source link

Remove square shape requirement #1

Closed AaronErhardt closed 3 years ago

AaronErhardt commented 3 years ago

Hey!

I really enjoyed playing yayagram (I really like nonograms in general) and had the idea of automatically generating .yaya files from images. I quickly implemented a prototype and it worked out pretty well yet during testing I came across a weird error message saying "malformed data" when opening a generated file. When looking for the cause in your code I found the following lines:

if width != height {
    return Err(LoadError {
        message: "malformed data",
        line_number: None,
    });
}

Well, first this error message isn't very descriptive. But more importantly, nonograms are not necessarily square shaped. Especially when converting images this can be a problem as the image would need to be scaled or resized if it's not square shaped which is suboptimal. So I wonder whether this check could be simply removed... at least that would help me a lot with my image to yayagram converter :)

wooster0 commented 3 years ago

Hello, thank you for your interest!

I agree, it would be awesome to have non-squared grids work. There is in fact another check here as well: https://github.com/r00ster91/yayagram/blob/e137dcd702384d84e76e2e6b45fc423c6b146b02/src/grid.rs#L114 The reason they don't work well is because of some strange panic that grid::get_vertical_clues was giving me: the len is 50 but the index is 50. I couldn't quite come up with a solution back then so I simply wrote it down for the time being and moved on. https://github.com/r00ster91/yayagram/blob/e137dcd702384d84e76e2e6b45fc423c6b146b02/src/main.rs#L21

But it's a rather annoying limitation to have so now I took another look and figured out that all this time it mistakenly used a height argument for both a range and get_index but get_index actually always needs the width. That was a pretty well hidden bug. I'm happy that this longstanding issue is now resolved and the checks can be removed.

About your image generation idea, I think that's a really cool idea and making use of the other maybed and crossed cell types would even allow you to preserve some color. There's currently white, blue and red so I suppose it would kind of look like a 3D image.

I'm looking forward to your converter!

AaronErhardt commented 3 years ago

Thanks for fixing the issue. In the meantime I finished my program which is actually pretty simple (so if you want you could actually integrate the code into yayagram).

The repo is here: https://github.com/AaronErhardt/img2yaya.

I couldn't come up with a better name than img2yaya. I think it's ok but maybe you have a better name for it...

Anyway, I'm pretty pleased with the outcome and already played the two examples I generated which was really fun. If you want you can link this repo in your README so people can find it more easily. Maybe we could even post on Reddit (at least that's where I found yayagram) what do you think? ;)

wooster0 commented 3 years ago

It's amazing! Do you want to get into contact? I have sent you a request on Discord.