Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

RandomSudoku ZeroClickInfo Goodie #140

Closed
wants to merge 1 commit into from

4 participants

@DrDub

My first pass at the RandomSudoku request.

(https://duckduckhack.uservoice.com/forums/5168-plugins/suggestions/2758396-random-sudoku)

This is a light wrapper on Games::Sudoku::Component.
All credit goes to Kenichi Ishigaki for the Sudoku generator.

@nospampleasemam

Oh man this is cool! Strangely though, while I can enter numbers accessing it from my phone, it doesn't seem to work from firefox. I haven't looked at the generated HTML yet though because regardless, it's... not pretty :-). I hope you don't mind me saying so. I'd like to work out a design that fits with the DDG style a bit more. I'm also thinking about adding some javascript for highlighting incorrect entries/a win/a keypad to use with the mouse when clicking on an empty square.

What do you think?

It's live right now on dylan.duckduckgo.com (but please don't rely on this for testing).

Thanks!

@nospampleasemam

By the way, CSS can be included in spice.css :-)

@DrDub
@nospampleasemam

Hi DrDub,

It's been a while and I wanted to check in :-). Have you had any luck with styling via spice.css?

Thanks again

@jagtalon
Owner

@DrDub just checking in. Any luck?

@djinn

Sudoku on search page is such an enticing idea. I would love to see @DrDub get back on this. Meanwhile @jagtalon can we please close the PR.

@djinn

I have created an idea page. Additionally I tested the instant answer locally. The instant answer requires revamp of HTML ui. @jagtalon your call.
screenshot from 2013-11-14 20 34 31

@mintsoft mintsoft referenced this pull request
Merged

Random Sudoku remake/redo #255

@jagtalon
Owner

Development is getting continued on #255

@jagtalon jagtalon closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 6, 2012
  1. @DrDub
This page is out of date. Refresh to see the latest.
Showing with 67 additions and 0 deletions.
  1. +1 −0  dist.ini
  2. +66 −0 lib/DDG/Goodie/Sudoku.pm
View
1  dist.ini
@@ -41,6 +41,7 @@ XML::SAX::Expat = 0
XML::Simple = 0
Astro::MoonPhase = 0
Acme::rafl::Everywhere = 0.008
+Games::Sudoku::Component = 0
[Prereqs / TestRequires]
Test::More = 0.98
View
66 lib/DDG/Goodie/Sudoku.pm
@@ -0,0 +1,66 @@
+package DDG::Goodie::Sudoku;
+# ABSTRACT: Show a small sudoku puzzle.
+
+use DDG::Goodie;
+
+use Games::Sudoku::Component;
+
+triggers start => 'sudoku';
+triggers start => 'i\'m bored';
+triggers start => 'i am bored';
+triggers start => 'this is boring';
+
+zci is_cached => 0;
+zci answer_type => "sudoku";
+
+primary_example_queries 'sudoku 4x4 easy';
+secondary_example_queries 'I am bored';
+description 'show a little sudoku you can play in the browser';
+name 'Sudoku';
+code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Sudoku.pm';
+category 'random';
+attribution github => ['https://github.com/DrDub', 'DrDub'],
+ web => ['http://duboue.net/', 'Pablo Duboue'];
+
+handle query => sub {
+ return unless /^sudoku|(i(\'m)|( am) bored)|(this is boring)/i;
+ my($number, undef, $difficulty) = m/^sudoku ([49])?(x[49])?\s*((easy)|(medium)|(hard))?/;
+ $number = 4 unless ($number); # fast
+ $difficulty = "easy" unless ($difficulty); # and easy
+
+ if(m/(i(\'m)|( am) bored)|(this is boring)/i){
+ # prepare to be unbored!
+ $number = 9;
+ $difficulty = "hard";
+ }
+
+ my $sudoku = Games::Sudoku::Component->new(size=>$number);
+ my $blanks = 0.25; # can't be easier
+ if ($difficulty eq "hard") {
+ $blanks = 0.75; # now we're talking
+ }elsif($difficulty eq "medium"){
+ $blanks = 0.5; # fun games are fun
+ }
+
+ $sudoku->generate(blanks => ($number ** 2) * $blanks);
+
+ my$as_str = $sudoku->as_string(separator=>" ", linebreak=>"\n");
+ $as_str =~ s/0/ /g;
+
+ my$as_html = $sudoku->as_HTML(border=>1, color_by_block=>1);
+ if ($blanks > 0.25){
+ $as_html =~ s/0/\<input size=\"1\">\<\/input>/g;
+ }else{
+ $as_html =~ s/0/ /g;
+ }
+
+ return $as_str, html => '<style type="text/css">td.odd { background-color: lightgray } table.sudoku { border-spacing: 0px; border-collapse: collapse; }</style>'.$as_html;
+};
+
+1;
+
+
+
+
+
+
Something went wrong with that request. Please try again.