Initial Game of Life Cheat sheet
parent
71ad58040f
commit
3953b463ec
|
@ -0,0 +1,62 @@
|
|||
package DDG::Goodie::GameOfLife;
|
||||
|
||||
# ABSTRACT: Write an abstract here
|
||||
|
||||
# Start at http://docs.duckduckhack.com/walkthroughs/calculation.html if you are new
|
||||
# to instant answer development
|
||||
|
||||
use DDG::Goodie;
|
||||
use strict;
|
||||
|
||||
zci answer_type => 'game_of_life';
|
||||
|
||||
# Caching - http://docs.duckduckhack.com/backend-reference/api-reference.html#caching`
|
||||
zci is_cached => 1;
|
||||
|
||||
# Triggers - http://docs.duckduckhack.com/walkthroughs/calculation.html#triggers
|
||||
triggers any => 'triggerword', 'trigger phrase';
|
||||
|
||||
# Handle statement
|
||||
handle remainder => sub {
|
||||
|
||||
my $remainder = $_;
|
||||
|
||||
# Optional - Guard against no remainder
|
||||
# I.E. the query is only 'triggerWord' or 'trigger phrase'
|
||||
#
|
||||
# return unless $remainder;
|
||||
|
||||
# Optional - Regular expression guard
|
||||
# Use this approach to ensure the remainder matches a pattern
|
||||
# I.E. it only contains letters, or numbers, or contains certain words
|
||||
#
|
||||
# return unless qr/^\w+|\d{5}$/;
|
||||
|
||||
return "plain text response",
|
||||
structured_answer => {
|
||||
|
||||
# ID - Must be unique and match Instant Answer page
|
||||
# E.g. https://duck.co/ia/view/calculator has `id => 'calculator'``
|
||||
id => 'game_of_life',
|
||||
|
||||
# Name - Used for Answer Bar Tab
|
||||
# Value should be chosen from existing Instant Answer topics
|
||||
# see http://docs.duckduckhack.com/frontend-reference/display-reference.html#name-string-required
|
||||
name => 'Answer',
|
||||
|
||||
data => {
|
||||
title => "My Instant Answer Title",
|
||||
subtitle => "My Subtitle",
|
||||
# image => "http://website.com/image.png"
|
||||
},
|
||||
|
||||
templates => {
|
||||
group => "text",
|
||||
# options => {
|
||||
#
|
||||
# }
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
1;
|
|
@ -0,0 +1,146 @@
|
|||
{
|
||||
"id": "game_of_life_cheat_sheet",
|
||||
"name": "Conway's Game of Life",
|
||||
"description": "Conway's Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.",
|
||||
|
||||
"metadata": {
|
||||
"sourceName": "Wikipedia",
|
||||
"sourceUrl" : "https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life"
|
||||
},
|
||||
|
||||
"aliases": [
|
||||
"game of life", "gol", "conways game", "conway's game"
|
||||
],
|
||||
|
||||
"template_type": "reference",
|
||||
|
||||
"section_order": [
|
||||
"Terms",
|
||||
"Transition Rules",
|
||||
"Live Cell Cheat Sheet",
|
||||
"Dead Cell Cheat Sheet"
|
||||
],
|
||||
|
||||
"sections": {
|
||||
"Terms": [
|
||||
{
|
||||
"key": "Grid",
|
||||
"val": "An infinite two-dimensional grid composed of square cells."
|
||||
},
|
||||
{
|
||||
"key": "Cell",
|
||||
"val": "A single square in a grid. Can be in one of two states: dead or alive."
|
||||
},
|
||||
{
|
||||
"key": "Neighbour",
|
||||
"val": "Every cell has 8 neighbours. They are the cells horizontally, vertically and diagonally immediately adjacent to it."
|
||||
},
|
||||
{
|
||||
"key": "Seed",
|
||||
"val": "The initial pattern of cells on the grid."
|
||||
},
|
||||
{
|
||||
"key": "Transition",
|
||||
"val": "Also known as a tick, every transition is a step in time. During each transition, every cell checks the number of neighbours it has to see whether or not it should change state. Every cell changes state at once."
|
||||
},
|
||||
{
|
||||
"key": "Generation",
|
||||
"val": "The number of transitions since the seed was set."
|
||||
}
|
||||
],
|
||||
"Transition Rules": [
|
||||
{
|
||||
"key": "Any live cell with fewer than two live neighbours dies",
|
||||
"val": "As if caused by under-population"
|
||||
},
|
||||
{
|
||||
"key": "Any live cell with two or three live neighbours lives on to the next generation.",
|
||||
"val": ""
|
||||
},
|
||||
{
|
||||
"key": "Any live cell with more than three live neighbours dies",
|
||||
"val": "As if caused by over-population"
|
||||
},
|
||||
{
|
||||
"key": "Any dead cell with exactly three live neighbours becomes a live cell",
|
||||
"val": "As if caused by reproduction"
|
||||
}
|
||||
],
|
||||
"Live Cell Cheat Sheet": [
|
||||
{
|
||||
"key": "No Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "One Neighbour",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Two Neighbours",
|
||||
"val": "Alive"
|
||||
},
|
||||
{
|
||||
"key": "Three Neighbours",
|
||||
"val": "Alive"
|
||||
},
|
||||
{
|
||||
"key": "Four Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Five Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Six Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Seven Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Eight Neighbours",
|
||||
"val": "Dead"
|
||||
}
|
||||
],
|
||||
"Dead Cell Cheat Sheet": [
|
||||
{
|
||||
"key": "No Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "One Neighbour",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Two Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Three Neighbours",
|
||||
"val": "Alive"
|
||||
},
|
||||
{
|
||||
"key": "Four Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Five Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Six Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Seven Neighbours",
|
||||
"val": "Dead"
|
||||
},
|
||||
{
|
||||
"key": "Eight Neighbours",
|
||||
"val": "Dead"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use DDG::Test::Goodie;
|
||||
|
||||
zci answer_type => "game_of_life";
|
||||
zci is_cached => 1;
|
||||
|
||||
ddg_goodie_test(
|
||||
[qw( DDG::Goodie::GameOfLife )],
|
||||
# At a minimum, be sure to include tests for all:
|
||||
# - primary_example_queries
|
||||
# - secondary_example_queries
|
||||
'example query' => test_zci('query'),
|
||||
# Try to include some examples of queries on which it might
|
||||
# appear that your answer will trigger, but does not.
|
||||
'bad example query' => undef,
|
||||
);
|
||||
|
||||
done_testing;
|
Loading…
Reference in New Issue