From 67eaa637c6dd44a09de470e5284c7c31289fa447 Mon Sep 17 00:00:00 2001 From: Is Isilon Date: Sat, 27 Feb 2016 14:50:06 +0800 Subject: [PATCH] Made into next card game --- bower.json | 9 +- css/style.css | 68 ++- index.html | 250 ++++---- js/app.js | 287 +++++---- js/detector/bubblr.js | 230 ------- js/detector/detector.js | 130 +--- js/detector/flame.js | 219 ------- js/game.js | 231 +++----- js/gameobjects.js | 7 +- js/rules.js | 472 ++++++++++++--- json/elements.json | 1122 +++++++++++++++++++++++++++++++++-- test/unit/directivesSpec.js | 33 +- test/unit/ruleSpec.js | 74 ++- test/unit/servicesSpec.js | 11 +- 14 files changed, 2025 insertions(+), 1118 deletions(-) delete mode 100644 js/detector/bubblr.js delete mode 100644 js/detector/flame.js diff --git a/bower.json b/bower.json index 56518bc..636b5f1 100644 --- a/bower.json +++ b/bower.json @@ -10,8 +10,7 @@ "**/.*", "node_modules", "bower_components", - "test", - "tests" + "test" ], "dependencies": { "angular": "1.4.x", @@ -22,6 +21,10 @@ "angular-resource": "1.4.x", "angular-animate": "1.4.x", "angular-dragdrop": "~1.0.13", - "lodash": "~4.5.1" + "lodash": "~4.5.1", + "chai": "~3.5.0", + "angular-ui-grid": "~3.1.1", + "jquery-ui": "~1.11.4", + "font-awesome": "~4.5.0" } } diff --git a/css/style.css b/css/style.css index 1860cfa..29ae19b 100644 --- a/css/style.css +++ b/css/style.css @@ -30,20 +30,6 @@ h1 br { position: relative; } -#detector-flame{ - position: relative; - /* So it looks like the flame it touching the test-tube */ - top: -60px; -} - -#detector-core { - z-index: 0; -} - -#detector-events { - z-index: 1; -} - #detector-info { z-index: 10; position: absolute; @@ -140,9 +126,9 @@ h1 br { width: 99%; } -.panel { +/*.panel { margin-bottom: 0; -} +}*/ .media-list-no-margin { margin-top: -15px; @@ -209,8 +195,8 @@ h1 br { @media screen and (min-width: 768px) { #detector-holder { - margin-left: -15px; - margin-right: -15px; + /*margin-left: -15px; + margin-right: -15px;*/ } .status { @@ -250,11 +236,11 @@ h1 br { @media screen and (min-width: 992px) and (max-width: 1199px){ .col-md-3s { - width:20%; + /*width:20%;*/ } .col-md-5s { - width:40%; + /*width:40%;*/ } } @@ -418,3 +404,45 @@ h1 br { .ui-grid-viewport .ui-grid-cell-contents{ font-size: 22px; } + +.card-panel { + min-height: 130px; + min-width: 100px; + /*border: 1px solid black;*/ + /*border-radius: 4px;*/ + /*padding: 5px;*/ + /*margin: 15px;*/ + /*font-size: 20px;*/ +} +.short-lines { + line-height: 3em; +} +.main-line{ + border: 3px green solid; + border-radius: 5px; + /*margin: 10px;*/ +} +.side-line { + /*padding-top: 10px;*/ + /*margin: 10px;*/ + border:2px red solid; + border-radius: 5px; + min-height: 200px; +} +.card-line{ + margin-bottom: 5px; +} +.left-list ul{ + padding-left: 5px; +} +.hypotheses select{ + height:20px; + padding:1px; + +} +.guess-correct{ + +} +.guess-wrong{ + +} diff --git a/index.html b/index.html index f43573d..ce41327 100644 --- a/index.html +++ b/index.html @@ -11,11 +11,10 @@ - + - @@ -23,14 +22,7 @@ - - - +
+

- Elements + Hand

-
- + {{r.key}} - {{r.state.amount}} + {{r.state.amount}}
@@ -112,111 +103,142 @@
-
- +
+ + +
+
+ Score
+ {{ lc.lab.state.score | niceNumber }} +
+
+
+ +
-
-
- - {{r.key}} - -
- -
- - - Your detector. Click on it to generate events. - - 🂠 - - +
+
+
+ + {{r.key}} + +
+
+
+
+
+
+
+
+ + {{r.key}} + +
+
+
+
+
+
+ +
+
+
+
+

Hint

+
(-{{dc.hintCost}} score)
+
+
+
    +
  • {{h}}
  • +
+
+
+
+
+
+
+

Rule

+
(-{{dc.ruleCost}} score)
+
+
+ {{dc.rule}} +
+ +
+
+
+ +
- + -
+ -
-
-
-

- Observations -

-
-
- - - -
-
-
- -
-
+
+ + + + + - - - - + + + - + + - - - - + + + - - - - - - - - - + + + - - - - - diff --git a/js/app.js b/js/app.js index db57dff..9d2ed60 100644 --- a/js/app.js +++ b/js/app.js @@ -8,6 +8,80 @@ var app = (function () { var app = angular.module('scienceAlchemy', ['ngDragDrop', 'ui.grid']); // directives + /** + * Provides an easy way to toggle a checkboxes indeterminate property + * + * @example + */ + // app.directive('uiIndeterminate', [ + // function () { + // + // return { + // compile: function (tElm, tAttrs) { + // if (!tAttrs.type || tAttrs.type.toLowerCase() !== 'checkbox') { + // return angular.noop; + // } + // + // return function ($scope, elm, attrs) { + // $scope.$watch(attrs.uiIndeterminate, function (newVal) { + // elm[0].indeterminate = !!newVal; + // }); + // }; + // } + // }; + // } + // ]); + + + /** + * Directive to render a rule and bind it's option with select boxes + * This expects ng-model="rule" as an attribute + */ + function cfsRule($compile) { + return { + link: function (scope, element, attrs) { + scope.$eval("$index"); + var rule = scope.$eval(attrs.ngModel); + + // first generate a select box for each option (using lodash templating) + _.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; + var optionTmpl = '' + + '\n'; + + var tmplParams = _.defaults({},rule.options,rule.otherOptions); + for (var option in rule.optionDesc) { + if (rule.optionDesc.hasOwnProperty(option)) { + var vals = rule.optionDesc[option].possibleVals; + if (vals) { + tmplParams[option] = _.template(optionTmpl)({ + option: option + }); + } else { + // if there are no options replace '{{color}}' with 'color' + tmplParams[option] = option; + } + } + } + // now put each select box into description + // replace '{{color}}' with '\n'; + // for (var i = 0; i < vals.length; i++) { + // s += '\n'; + // } + // s += '\n'; + // tmplParams[option] = s; + // } else { + // tmplParams[option] = option; + // } + // } + // } + // return _.template(this.description)(tmplParams); + // }; + /** Generate angular template for this rule **/ + // Rule.prototype.describeNg = function (arguments) { + // + // // first put option name into this option template + // // _.templateSettings.interpolate = /<%=([\s\S]+?)%>/g; + // optionTmpl = '' + + // '\n'; + // + // // we want template params where each options is replace with a select box + // var tmplParams = {}; + // + // for (var option in this.optionDesc) { + // if (this.optionDesc.hasOwnProperty(option)) { + // var vals = this.optionDesc[option].possibleVals; + // if (vals) { + // tmplParams[option] = _.template(optionTmpl)({ + // option: option + // }); + // } else { + // tmplParams[option] = option; + // } + // } + // } + // + // // now in description replace params with select box + // return _.template(this.description)(tmplParams); + // }; /** Compile description using options to express rule**/ Rule.prototype.describeVariation = function (options) { var compiled = _.template(this.description); - return compiled(_.defaults(options,this.options)); + return compiled(_.defaults(options, this.options, this.otherOptions)); }; /** Return options string for humans **/ Rule.prototype.describeOptions = function () { var s = ""; // explicit python style - var template = '{{option}} \n\tDescription: {{description}}\n\tType {{type}} \n\tValues: current:{{current}}, default:{{defaultVal}}, all:[{{possibleVals}}]\n '; + var template = '<%= option %> \n\tDescription: <%= description %>\n\tType <%= type %> \n\tValues: current:<%= current %>, default:<%= defaultVal %>, all:[<%= possibleVals %>]\n '; // jsdoc style I think - // var template = '{{type}}\t[{{option}}={{defaultVal}}]\t{{description}}. ({{current}})[{{possibleVals}}]\n'; + // var template = '<%= type %>\t[<%= option %>=<%= defaultVal %>]\t<%= description %>. (<%= current %>)[<%= possibleVals %>]\n'; for (var option in this.optionDesc) { if (this.optionDesc.hasOwnProperty(option)) { - var tmplParams = _.defaults({option:option,defaultVal:this.optionDefaults[option],current:this.options[option]},this.optionDesc[option]); - s+=_.template(template)(tmplParams); + var tmplParams = _.defaults({ + option: option, + defaultVal: this.optionDefaults[option], + current: this.options[option] + }, this.optionDesc[option]); + s += _.template(template)(tmplParams); } } return s; }; /** Describe all variations on the default options **/ Rule.prototype.describeVariations = function () { - var s=""; + var s = []; for (var option in this.optionDesc) { if (this.optionDesc.hasOwnProperty(option)) { var vals = this.optionDesc[option].possibleVals; for (var i = 0; i < vals.length; i++) { - var options={}; - options[option]=vals[i]; - s+=this.describeVariation(options)+'\n'; + var options = {}; + options[option] = vals[i]; + var v = this.describeVariation(options) + '\n'; + s.push(v); } } @@ -120,13 +183,13 @@ var Rules = (function functionName(_) { Rule.prototype.nextHint = function () { var hint = this.hints[this.hintsUsed]; this.hintsUsed++; - return hint||""; + return hint || ""; }; /** Generate an automatic hint from params **/ Rule.prototype.genHints = function () { // first manual hints - this.hintsUsed=0; + this.hintsUsed = 0; var hints = []; // compile hints for each unused property @@ -138,15 +201,15 @@ var Rules = (function functionName(_) { if (this.optionDesc.hasOwnProperty(option)) { // for each option find any unused options var posVals = this.optionDesc[option].possibleVals; - if (posVals){ - var optionUnused = _.difference(posVals,[this.options[option]]); - unusedOptions[option+'Unused']=optionUnused; + if (posVals) { + var optionUnused = _.difference(posVals, [this.options[option]]); + unusedOptions[option + 'Unused'] = optionUnused; } } } // copy options - var tmplParams = _.extend({},this.options); + var tmplParams = _.defaults({}, this.options, this.otherOptions); // make hint from unused options if there are hint templates for them @@ -156,12 +219,12 @@ var Rules = (function functionName(_) { // find hint templats that take this unused option for (var i = 0; i < this.hintTmpls.length; i++) { var tmpl = this.hintTmpls[i]; - if (tmpl.indexOf(optionUnused)>=0){ + if (tmpl.indexOf(optionUnused) >= 0) { var tmplCmp = _.template(tmpl); var unused = unusedOptions[optionUnused]; // generate a hint for each unsed options for (var j = 0; j < unused.length; j++) { - tmplParams[optionUnused]=unused[j]; + tmplParams[optionUnused] = unused[j]; var hint = tmplCmp(tmplParams); hints.push(hint); } @@ -181,22 +244,51 @@ var Rules = (function functionName(_) { hints.push("You cheeky blighter. Feel free to restart the game to get a new rule if this one is no fun (it will happen)."); // and finally remove duplicate hints - hints=_.uniq(hints); + hints = _.uniq(hints); return hints; }; /** How many combination of this rule **/ Rule.prototype.combinations = function (arguments) { - var pos = _.map(this.optionDesc,'possibleVals'); - var c=0; + var pos = _.map(this.optionDesc, 'possibleVals'); + var c = 0; for (var i = 0; i < pos.length; i++) { - c*pos[i].length; + c * pos[i].length; } return c; }; // TODO estimate hardness perhaps through simulation, combinatorics or hints + /** Helper to format numbers **/ + Rule.prototype.nth = function (d) { + if (d > 3 && d < 21) return 'th'; // thanks kennebec + switch (d % 10) { + case 1: + return "st"; + case 2: + return "nd"; + case 3: + return "rd"; + default: + return "th"; + } + }; + /** Helper to format numbers **/ + Rule.prototype.lastn = function (d) { + if (d > 3 && d < 21) return d+'th to last'; // thanks kennebec + switch (d % 10) { + case 1: + return d+" st to last"; + case 2: + return d+" nd to last"; + case 3: + return d+" rd to last"; + default: + return d+" th to last"; + } + }; + // Now defined actual rules var rules = []; @@ -205,40 +297,286 @@ var Rules = (function functionName(_) { // here is a example rule where the card must have differen't color etc from the last card // but it's abstracted to allow variations new Rule( - "Next card must not have the same {{property}} as the last {{n}}'th card", + "Next card must not have the same <%= property %> as the <%= lastn(n) %> card", function (card, lastCards, allCards, options) { - var lastNCard = lastCards[this.options.n-1]; + var lastNCard = lastCards[lastCards.length - this.options.n]; var property = this.options.property; return chai.expect(card) .to.have.property(property) .not.equal(lastNCard[property]); - }, - { + }, { property: 'color', n: 1 - }, - { + }, { property: { description: 'The property to compare in last and current card', - possibleVals: ['color','face','number','value','suit'], + possibleVals: ['color', 'face', 'number', 'value', 'suit'], type: 'String' }, n: { description: 'Number for how many cards back. Start counting at 1', - possibleVals: [1,2,3], + possibleVals: [1, 2, 3], type: 'Number' } - }, - [ - 'This rule does not involve {{propertyUnused}}', - // 'This rule does not involve the {{nUnused}}th last card', - 'This rule does involve {{property}}', - 'This rule does involve the {{n}}th last card', + }, [ + 'This rule does not involve <%= propertyUnused %>', + 'This rule does involve <%= property %>', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + 'This rule does not involve the <%= nUnused %><%=nth(n)%> last card', // only indirectly + ] + ), + new Rule( + "If last <%= n %><%=nth(n)%> cards value was between <%= min %> and <%= max %> play a card that isn't and vice versa.", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - this.options.n]; + var property = this.options.property; + var lastWasbetween = options.min < lastNCard.value && lastNCard.value < options.max; + if (lastWasbetween) + return chai.expect(card) + .to.have.property('value') + .not.within(options.min, options.max); + else + return chai.expect(card) + .to.have.property('value') + .within(options.min, options.max); + }, { + n: 1, + min: 0, + max: 7 + }, { + min: { + description: 'The min bounds to compare value to', + possibleVals: [0, 1, 2, 3, 4, 5], + type: 'Number' + }, + max: { + description: 'The max bounds to compare value to', + possibleVals: [7, 8, 9, 10, 11, 12, 13, 14, 15], + type: 'Number' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + } + }, [ + 'This rule does not involve color', + 'This rule does not involve if it\'s a face card', + 'This rule does not involve royalty', + 'This rule does not involve color', + 'This rule does not involve suit', + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does involve value', + 'This rule does involve a value cuttoff', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + ] + ), + new Rule( + "Play a card with a value <%= min %> to <%= max %> higher than the value of the last <%=n%><%=nth(n)%> card. The numbers wrap around once they reach the max", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - this.options.n]; + var property = this.options.property; + var lastWasbetween = options.min < lastNCard.value && lastNCard.value < options.max; + if (lastWasbetween) + return chai.expect(card) + .to.have.property('value') + .not.within(options.min, options.max); + else + return chai.expect(card) + .to.have.property('value') + .within(options.min, options.max); + }, { + n: 1, + min: 1, + max: 4 + }, { + min: { + description: 'The min difference to the last nth card', + possibleVals: [1, 2, 3], + type: 'Number' + }, + max: { + description: 'The max difference to the last nth card', + possibleVals: [4, 5, 6, 7, 8], + type: 'Number' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + } + }, [ + 'This rule does not involve color', + 'This rule does not involve if it\'s a face card', + 'This rule does not involve royalty', + 'This rule does not involve color', + 'This rule does not involve suit', + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does involve value', + 'This rule does involve the difference in value to the last card', + 'This rule does involve the difference in values that wraps around', + 'This rule does involve the difference in values of at least <%= min %>', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + ] + ), + + + + new Rule( + "If the last <%= n %><%=nth(n)%> card is an even-valued card, play a <%= evenColor %> card. Otherwise play the other color", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - this.options.n]; + var lastWasEven = lastNCard % 2 == 0; + if (lastWasEven) + return chai.expect(card) + .to.have.property('color') + .equals(options.evenColor); + else + return chai.expect(card) + .to.have.property('color') + .not.equals(options.evenColor); + }, { + n: 1, + evenColor: 'red', + }, { + evenColor: { + description: 'The color to play if lastNCard was even', + possibleVals: ['red', 'black'], + type: 'String' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + } + }, [ + 'This rule does not involve if it\'s a face card', + 'This rule does not involve royalty', + 'This rule does not involve suit', + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does not involve the difference in value to the last card', + 'This rule does involve color', + 'This rule does involve value', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + ] + ), + + new Rule( + "Play a card that has the same <%= property %> or color as the last <%= n %><%=nth(n)%> card but not both.", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - options.n]; + var matchesColor = lastNCard.color === card.color; + var matches2 = lastNCard.suit === lastNCard.suit; + return ((matchesColor && !matches2) || (!matchesColor && matches2)); + }, { + n: 1, + property: 'suit', + }, { + property: { + description: 'The property to compare to the lastNCard', + possibleVals: ['suit', 'value', 'face', 'royal'], + type: 'String' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + } + }, [ + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does involve color', + 'This rule does not involve <%= propertyUnused %>', + 'This rule does involve <%= property %>', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + ] + ), + + new Rule( + "If the last <%= n %><%=nth(n)%> card's number is higher than <%= min %>, change <%= property %>, and if lower, keep it the same.", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - options.n]; + var lastWasHigher = lastNCard.value > options.min; + if (lastWasHigher) { + return chai.expect(card) + .to.have.property(options.property) + .not.equals(lastNCard[options.property]); + } else { + return chai.expect(card) + .to.have.property(options.property) + .equals(lastNCard[options.property]); + } + var matches2 = lastNCard.suit === lastNCard.suit; + return ((matchesColor && !matches2) || (!matchesColor && matches2)); + }, { + n: 1, + min: 7, + property: 'suit', + }, { + property: { + description: 'The property to compare to the lastNCard', + possibleVals: ['suit', 'face', 'royal', 'color'], + type: 'String' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + }, + min: { + description: 'The min difference to the last nth card', + possibleVals: [5, 6, 7, 8, 9], + type: 'Number' + }, + }, [ + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does not involve <%= propertyUnused %>', + 'This rule does involve value', + 'This rule does a minimum value', + 'This rule does involve <%= property %>', + 'This rule does involve the <%= n %><%=nth(n)%> last card', + ] + ), + new Rule( + "If the last <%= n %><%=nth(n)%> card was a <%= property %> card, play a higher value card otherwise lower.", + function (card, lastCards, allCards, options) { + var lastNCard = lastCards[lastCards.length - options.n]; + var lastHadProperty = lastNCard[options.property]; + if (lastHadProperty) { + return chai.expect(card) + .to.have.property('value') + .above(lastNCard[options.value]); + } else { + return chai.expect(card) + .to.have.property('value') + .lessThan(lastNCard[options.value]); + } + }, { + n: 1, + property: 'face', + }, { + property: { + description: 'The property to compare to the lastNCard', + possibleVals: ['face', 'royal', 'spade', 'club', 'diamond', 'heart', 'red', 'black'], + type: 'String' + }, + n: { + description: 'Number for how many cards back. Start counting at 1', + possibleVals: [1, 2, 3], + type: 'Number' + }, + }, [ + 'This rule does not involve the <%= nUnused %><%=nth(nUnused)%> last card', + 'This rule does not check for <%= propertyUnused %> cards', + 'This rule does involve <%= property %>', + 'This rule wants you to play a higher card in some circumstances', + 'This rule does involve the <%= n %><%=nth(n)%> last card', ] ) - ); + + ); + return { Rule: Rule, rules: rules, diff --git a/json/elements.json b/json/elements.json index 0d567c5..1603c53 100644 --- a/json/elements.json +++ b/json/elements.json @@ -1,59 +1,1063 @@ -[{"key": "🂡","name":"Ace","value":1,"suit":"Spades","color":"Black","royal":false,"face":false,"number":false}, -{"key": "🂢","name":"Two","value":2,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂣","name":"Three","value":3,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂤","name":"Four","value":4,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂥","name":"Five","value":5,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂦","name":"Six","value":6,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂧","name":"Seven","value":7,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂨","name":"Eight","value":8,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂩","name":"Nine","value":9,"suit":"Spades","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🂪","name":"Ten","value":10,"suit":"Spades","color":"Black","royal":false,"face":true,"number":true}, -{"key": "🂫","name":"Jack","value":11,"suit":"Spades","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🂬","name":"Knight","value":12,"suit":"Spades","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🂭","name":"Queen","value":13,"suit":"Spades","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🂮","name":"King","value":14,"suit":"Spades","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🂱","name":"Ace","value":1,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":false}, -{"key": "🂲","name":"Two","value":2,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂳","name":"Three","value":3,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂴","name":"Four","value":4,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂵","name":"Five","value":5,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂶","name":"Six","value":6,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂷","name":"Seven","value":7,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂸","name":"Eight","value":8,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂹","name":"Nine","value":9,"suit":"Hearts","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🂺","name":"Ten","value":10,"suit":"Hearts","color":"Red","royal":false,"face":true,"number":true}, -{"key": "🂻","name":"Jack","value":11,"suit":"Hearts","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🂼","name":"Knight","value":12,"suit":"Hearts","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🂽","name":"Queen","value":13,"suit":"Hearts","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🂾","name":"King","value":14,"suit":"Hearts","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🃁","name":"Ace","value":1,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":false}, -{"key": "🃂","name":"Two","value":2,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃃","name":"Three","value":3,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃄","name":"Four","value":4,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃅","name":"Five","value":5,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃆","name":"Six","value":6,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃇","name":"Seven","value":7,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃈","name":"Eight","value":8,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃉","name":"Nine","value":9,"suit":"Diamonds","color":"Red","royal":false,"face":false,"number":true}, -{"key": "🃊","name":"Ten","value":10,"suit":"Diamonds","color":"Red","royal":false,"face":true,"number":true}, -{"key": "🃋","name":"Jack","value":11,"suit":"Diamonds","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🃌","name":"Knight","value":12,"suit":"Diamonds","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🃍","name":"Queen","value":13,"suit":"Diamonds","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🃎","name":"King","value":14,"suit":"Diamonds","color":"Red","royal":true,"face":true,"number":false}, -{"key": "🃑","name":"Ace","value":1,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":false}, -{"key": "🃒","name":"Two","value":2,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃓","name":"Three","value":3,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃔","name":"Four","value":4,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃕","name":"Five","value":5,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃖","name":"Six","value":6,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃗","name":"Seven","value":7,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃘","name":"Eight","value":8,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃙","name":"Nine","value":9,"suit":"Clubs","color":"Black","royal":false,"face":false,"number":true}, -{"key": "🃚","name":"Ten","value":10,"suit":"Clubs","color":"Black","royal":false,"face":true,"number":true}, -{"key": "🃛","name":"Jack","value":11,"suit":"Clubs","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🃜","name":"Knight","value":12,"suit":"Clubs","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🃝","name":"Queen","value":13,"suit":"Clubs","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🃞","name":"King","value":14,"suit":"Clubs","color":"Black","royal":true,"face":true,"number":false}, -{"key": "🂠","name":"Playing Card","value":15,"suit":"Black","color":"Black","royal":false,"face":false,"number":false}, -{"key": "🃏","name":"Joker","value":16,"suit":"Black","color":"Black","royal":false,"face":true,"number":false}, -{"key": "🃟","name":"Joker","value":16,"suit":"Red","color":"Red","royal":false,"face":true,"number":false}] +[{ + "key": "🂡", + "name": "Ace", + "value": 1, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂢", + "name": "Two", + "value": 2, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂣", + "name": "Three", + "value": 3, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂤", + "name": "Four", + "value": 4, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂥", + "name": "Five", + "value": 5, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂦", + "name": "Six", + "value": 6, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂧", + "name": "Seven", + "value": 7, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂨", + "name": "Eight", + "value": 8, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂩", + "name": "Nine", + "value": 9, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂪", + "name": "Ten", + "value": 10, + "suit": "Spades", + "color": "Black", + "royal": false, + "face": true, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂫", + "name": "Jack", + "value": 11, + "suit": "Spades", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂬", + "name": "Knight", + "value": 12, + "suit": "Spades", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂭", + "name": "Queen", + "value": 13, + "suit": "Spades", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂮", + "name": "King", + "value": 14, + "suit": "Spades", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂱", + "name": "Ace", + "value": 1, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂲", + "name": "Two", + "value": 2, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂳", + "name": "Three", + "value": 3, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂴", + "name": "Four", + "value": 4, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂵", + "name": "Five", + "value": 5, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂶", + "name": "Six", + "value": 6, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂷", + "name": "Seven", + "value": 7, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂸", + "name": "Eight", + "value": 8, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂹", + "name": "Nine", + "value": 9, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂺", + "name": "Ten", + "value": 10, + "suit": "Hearts", + "color": "Red", + "royal": false, + "face": true, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂻", + "name": "Jack", + "value": 11, + "suit": "Hearts", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂼", + "name": "Knight", + "value": 12, + "suit": "Hearts", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂽", + "name": "Queen", + "value": 13, + "suit": "Hearts", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂾", + "name": "King", + "value": 14, + "suit": "Hearts", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃁", + "name": "Ace", + "value": 1, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃂", + "name": "Two", + "value": 2, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃃", + "name": "Three", + "value": 3, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃄", + "name": "Four", + "value": 4, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃅", + "name": "Five", + "value": 5, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃆", + "name": "Six", + "value": 6, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃇", + "name": "Seven", + "value": 7, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃈", + "name": "Eight", + "value": 8, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃉", + "name": "Nine", + "value": 9, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃊", + "name": "Ten", + "value": 10, + "suit": "Diamonds", + "color": "Red", + "royal": false, + "face": true, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃋", + "name": "Jack", + "value": 11, + "suit": "Diamonds", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃌", + "name": "Knight", + "value": 12, + "suit": "Diamonds", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃍", + "name": "Queen", + "value": 13, + "suit": "Diamonds", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃎", + "name": "King", + "value": 14, + "suit": "Diamonds", + "color": "Red", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃑", + "name": "Ace", + "value": 1, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃒", + "name": "Two", + "value": 2, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃓", + "name": "Three", + "value": 3, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃔", + "name": "Four", + "value": 4, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃕", + "name": "Five", + "value": 5, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃖", + "name": "Six", + "value": 6, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃗", + "name": "Seven", + "value": 7, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃘", + "name": "Eight", + "value": 8, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃙", + "name": "Nine", + "value": 9, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": false, + "number": true, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃚", + "name": "Ten", + "value": 10, + "suit": "Clubs", + "color": "Black", + "royal": false, + "face": true, + "number": true, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃛", + "name": "Jack", + "value": 11, + "suit": "Clubs", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃜", + "name": "Knight", + "value": 12, + "suit": "Clubs", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃝", + "name": "Queen", + "value": 13, + "suit": "Clubs", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": true, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃞", + "name": "King", + "value": 14, + "suit": "Clubs", + "color": "Black", + "royal": true, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🂠", + "name": "Playing Card", + "value": 15, + "suit": "Black", + "color": "Black", + "royal": false, + "face": false, + "number": false, + "red": false, + "black": false, + "even": false, + "odd": true, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃏", + "name": "Joker", + "value": 16, + "suit": "Black", + "color": "Black", + "royal": false, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}, { + "key": "🃟", + "name": "Joker", + "value": 16, + "suit": "Red", + "color": "Red", + "royal": false, + "face": true, + "number": false, + "red": false, + "black": false, + "even": true, + "odd": false, + "loop": false, + "heart": false, + "spade": false, + "club": false, + "diamond": false +}] diff --git a/test/unit/directivesSpec.js b/test/unit/directivesSpec.js index 2e5469a..44b8bc0 100644 --- a/test/unit/directivesSpec.js +++ b/test/unit/directivesSpec.js @@ -2,6 +2,37 @@ /* jasmine specs for directives go here */ -describe('directives', function() { +describe('directives', function () { + var $compile, + $rootScope; + // Load the myApp module, which contains the directive + beforeEach(module('scienceAlchemy')); + // beforeEach(module('Rules')); + + // Store references to $rootScope and $compile + // so they are available to all tests in this describe block + beforeEach(inject(function (_$compile_, _$rootScope_) { + // The injector unwraps the underscores (_) from around the parameter names when matching + $compile = _$compile_; + $rootScope = _$rootScope_; + })); + + it('Replaces the element with the appropriate content', function () { + // define a rule for testing + $rootScope.rule = Rules.rules[0]; + + // Compile a piece of HTML containing the directive + var element = $compile('
')($rootScope); + + // fire all the watches, so the scope expressions will be evaluated + // $rootScope.$digest(); + $rootScope.$apply(); + + // Check that the compiled element contains the templated content + var html = element.html(); + expect(html).toContain("
')($rootScope); + + // fire all the watches, so the scope expressions will be evaluated + // $rootScope.$digest(); + $rootScope.$apply(); + + // Check that the compiled element contains the templated content + var html = element.html(); + expect(html).toContain("