From 489583486bd9d31de5bec8751d7e63997c325fd3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 30 Oct 2023 00:18:04 -0400 Subject: added archive page and some expert puzzles --- app/assets/stylesheets/wittle/general.css.scss | 26 +++++ app/controllers/wittle/puzzles_controller.rb | 3 +- app/views/wittle/puzzles/about.html.haml | 1 + app/views/wittle/puzzles/index.html.haml | 25 +++++ ext/wittle_generator/wittle_generator.cpp | 132 ++++++++++++++++++++++++- lib/tasks/wittle_tasks.rake | 1 + 6 files changed, 184 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/wittle/general.css.scss b/app/assets/stylesheets/wittle/general.css.scss index c258734..a0eb980 100644 --- a/app/assets/stylesheets/wittle/general.css.scss +++ b/app/assets/stylesheets/wittle/general.css.scss @@ -143,3 +143,29 @@ input[type="range"]::-ms-thumb { padding-left: 1em; text-align: right; } + +#archive { + width: 50%; + margin: 0 auto; + border-spacing: 0; + text-align: center; + + tr { + &.odd { + background-color: #fff; + } + + &.even { + background-color: #edf; + } + } + + th, td { + padding: 0.5em; + } + + ul { + list-style-type: none; + padding: 0; + } +} diff --git a/app/controllers/wittle/puzzles_controller.rb b/app/controllers/wittle/puzzles_controller.rb index 2949f94..3c3c8a6 100644 --- a/app/controllers/wittle/puzzles_controller.rb +++ b/app/controllers/wittle/puzzles_controller.rb @@ -3,10 +3,11 @@ module Wittle def about @normal_puzzle = Puzzle.normal.order(created_at: :desc).first @hard_puzzle = Puzzle.hard.order(created_at: :desc).first + @expert_puzzle = Puzzle.expert.order(created_at: :desc).first end def index - #@puzzle = WittleGenerator.new.generate_medium + @puzzles = Puzzle.select(:id, :created_at, :category).order(created_at: :asc).all.chunk { |puzzle| puzzle.created_at.localtime.to_date }.to_h.transform_values { |by_date| by_date.sort_by(&:category).chunk { |puzzle| puzzle.category }.to_h } end def show diff --git a/app/views/wittle/puzzles/about.html.haml b/app/views/wittle/puzzles/about.html.haml index 628ba0b..6a47972 100644 --- a/app/views/wittle/puzzles/about.html.haml +++ b/app/views/wittle/puzzles/about.html.haml @@ -1,3 +1,4 @@ %p by Hatkirby, with help from Sigma144 and jbzdarkid %p= link_to "Normal", @normal_puzzle %p= link_to "Hard", @hard_puzzle +%p= link_to "Expert", @expert_puzzle diff --git a/app/views/wittle/puzzles/index.html.haml b/app/views/wittle/puzzles/index.html.haml index e69de29..097eb87 100644 --- a/app/views/wittle/puzzles/index.html.haml +++ b/app/views/wittle/puzzles/index.html.haml @@ -0,0 +1,25 @@ +%h1 Archive +%table#archive + %tr + %th + %th Normal + %th Hard + %th Expert + - @puzzles.each do |date, dps| + %tr{ class: cycle("even", "odd") } + %td= date.strftime("%B %-d, %Y") + %td + - if dps.has_key? "normal" + %ul + - dps["normal"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle + %td + - if dps.has_key? "hard" + %ul + - dps["hard"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle + %td + - if dps.has_key? "expert" + %ul + - dps["expert"].each do |puzzle| + %li= link_to "\##{puzzle.id}", puzzle diff --git a/ext/wittle_generator/wittle_generator.cpp b/ext/wittle_generator/wittle_generator.cpp index e1b5323..f3d2947 100644 --- a/ext/wittle_generator/wittle_generator.cpp +++ b/ext/wittle_generator/wittle_generator.cpp @@ -392,7 +392,6 @@ Rice::Object wittle_generator_generate_easy(Rice::Object /* self */) { {{{Decoration::Star | Decoration::Color::Magenta, 6}, {Decoration::Stone | Decoration::Color::Orange, 4}, {Decoration::Stone | Decoration::Color::Green, 4}}}); - generator.place_gaps(8); break; } } @@ -404,7 +403,7 @@ Rice::Object wittle_generator_generate_easy(Rice::Object /* self */) { Rice::Object wittle_generator_generate_medium(Rice::Object /* self */) { Generate generator; - int choice = Random::rand() % 30; + int choice = Random::rand() % 33; std::cout << "Generate MEDIUM: choice " << std::dec << choice << std::endl; switch (choice) { @@ -679,6 +678,132 @@ Rice::Object wittle_generator_generate_medium(Rice::Object /* self */) { 4, 4, {{{Decoration::Triangle | Decoration::Color::Orange, 8}}}); break; } + case 30: { + generator.setFlag(Generate::RegularStartEnd); + generator.setFlag(Generate::LongestPath); + generator.setFlag(Generate::FullGaps); + generator.generate( + 6, 6, {{{Decoration::Dot_Intersection, 12}, {Decoration::Gap, 18}}}); + break; + } + case 31: { + generator.generate(5, 5, + {{{Decoration::Start, 8}, + {Decoration::Exit, 1}, + {Decoration::Dot_Intersection, 36}}}); + break; + } + case 32: { + generator.setFlag(Generate::RegularStartEnd); + generator.setSymmetry(Panel::Horizontal); + generator.generate( + 6, 6, + {{{Decoration::Triangle | Decoration::Color::Orange, 12}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + } + + Rice::String str(generator.AsCode()); + return str; +} + +Rice::Object wittle_generator_generate_expert(Rice::Object /* self */) { + Generate generator; + + int choice = Random::rand() % 8; + std::cout << "Generate EXPERT: choice " << std::dec << choice << std::endl; + + switch (choice) { + case 0: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setSymmetry(Panel::Rotational); + generator.generate( + 6, 6, + {{{Decoration::Triangle | Decoration::Color::Orange, 12}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + case 1: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setFlag(Generate::WriteInvisible); + generator.setSymmetry(Panel::Rotational); + generator.generate(7, 7, + {{{Decoration::Dot | Decoration::Color::Blue, 4}, + {Decoration::Dot | Decoration::Color::Yellow, 4}, + {Decoration::Dot, 7}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + case 2: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setFlag(Generate::WriteInvisible); + generator.setSymmetry(Panel::Rotational); + generator.generate(7, 7, + {{{Decoration::Stone | Decoration::Color::Black, 6}, + {Decoration::Stone | Decoration::Color::White, 6}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + case 3: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setFlag(Generate::WriteInvisible); + generator.setSymmetry(Panel::Rotational); + generator.generate(7, 7, + {{{Decoration::Star | Decoration::Color::Orange, 6}, + {Decoration::Star | Decoration::Color::Green, 6}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + case 4: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setFlag(Generate::WriteInvisible); + generator.setFlag(Generate::RequireCombineShapes); + generator.setSymmetry(Panel::Rotational); + generator.generate(5, 5, + {{{Decoration::Poly | Decoration::Color::Yellow, 3}, + {Decoration::Start, 1}, + {Decoration::Exit, 1}}}); + break; + } + case 5: { + generator.setFlag(Generate::StartEdgeOnly); + generator.setFlag(Generate::WriteInvisible); + generator.setSymmetry(Panel::Rotational); + generator.generate(7, 7, + {{{Decoration::Dot | Decoration::Color::Blue, 2}, + {Decoration::Dot | Decoration::Color::Yellow, 2}, + {Decoration::Dot, 8}, + {Decoration::Eraser | Decoration::Color::Purple, 1}, + {Decoration::Start, 1}}}); + break; + } + case 6: { + generator.setFlag(Generate::RegularStartEnd); + generator.generate( + 4, 4, + {{{Decoration::Triangle | Decoration::Color::Orange, 15}, + {Decoration::Eraser | Decoration::Color::Purple, 1}}}); + break; + } + case 7: { + generator.setFlag(Generate::RegularStartEnd); + generator.generate( + 4, 4, + {{{Decoration::Stone | Decoration::Color::White, 1}, + {Decoration::Stone | Decoration::Color::Black, 2}, + {Decoration::Stone | Decoration::Color::Red, 2}, + {Decoration::Star | Decoration::Color::White, 4}, + {Decoration::Star | Decoration::Color::Black, 3}, + {Decoration::Star | Decoration::Color::Red, 3}, + {Decoration::Decoration::Eraser | Decoration::Color::Green, 1}}}); + break; + } } Rice::String str(generator.AsCode()); @@ -689,5 +814,6 @@ extern "C" void Init_wittle_generator() { Rice::Class rb_cWittleGenerator = Rice::define_class("WittleGenerator") .define_method("generate_easy", &wittle_generator_generate_easy) - .define_method("generate_medium", &wittle_generator_generate_medium); + .define_method("generate_medium", &wittle_generator_generate_medium) + .define_method("generate_expert", &wittle_generator_generate_expert); } diff --git a/lib/tasks/wittle_tasks.rake b/lib/tasks/wittle_tasks.rake index debf249..b9300c7 100644 --- a/lib/tasks/wittle_tasks.rake +++ b/lib/tasks/wittle_tasks.rake @@ -3,5 +3,6 @@ namespace :wittle do task :generate_puzzles => :environment do Wittle::Puzzle.create(data: WittleGenerator.new.generate_easy, category: :normal) Wittle::Puzzle.create(data: WittleGenerator.new.generate_medium, category: :hard) + Wittle::Puzzle.create(data: WittleGenerator.new.generate_expert, category: :expert) end end -- cgit 1.4.1