Fixing rules

This commit is contained in:
2016-03-01 11:04:28 +08:00
parent 903824d2e8
commit f91fd433da
3 changed files with 42 additions and 24 deletions
+14 -5
View File
@@ -312,11 +312,11 @@
<p class="small bg-warning">This is a pre-release. <p>Cards For Science is a card game where you work out the secret rule to determine which cards can be played. This game is based on <a href="http://www.logicmazes.com/games/eleusis/">Eleusis</a> by Robert Abbott and John Golden's <a href="http://www.logicmazes.com/games/eleusis/express.html">Eleusis</a> Express.
<h5>Authors</h5>
<h5><em>Authors</em></h5>
<ul>
<li><a href="https://github.com/wassname">wassname</a></li>
</ul>
<p>Feel free to get in touch with via GitHub or by sending a message on<br>cardsforscience at wassname.org</a>.</p>
<p>Feel free to get in touch via GitHub or by sending a message on<br>cardsforscience at wassname.org</a>.</p>
</div>
</div>
</div>
@@ -331,6 +331,14 @@
</div>
<div class="modal-body">
<p class="small bg-warning">This is a pre-release.</p>
<p>
Cards For Science is a card game where you work out the secret rule. The rule decides which card can be played next so you play cards to test the rule.
<h5><strong>Credits</strong></h5>
This game is based on <a href="http://www.logicmazes.com/games/eleusis/">Eleusis</a> by Robert Abbott and John Golden's <a href="http://www.logicmazes.com/games/eleusis/express.html">Eleusis</a> Express.
<h5><strong>Rules</strong></h5>
<ul>
<li>Guess the rule correctly to win the game</li>
@@ -347,7 +355,8 @@
<h5><strong>Hints:</strong></h5>
<ul>
<li>Try to disprove rules, those which remain must be the truth</li>
<li>Don't be afraid to use hints</li>
<li>Don't be afraid to reveal the rule hints</li>
<li>Don't spend too much time thinking before 6 cards have been played.</li>
<li>If this rule is too hard restart the game to get a new rule</li>
</ul>
<p>
@@ -357,7 +366,7 @@
<table class="table">
<thead>
<tr>
<th ng-repeat='key in ["key", "name", "value", "suit", "color", "royal", "face", "number"]'>
<th ng-repeat='key in ["key", "name", "value", "suit", "color", "royal", "face", "number","loop"]'>
{{key}}
</th>
</tr>
@@ -367,7 +376,7 @@
<!-- <th>
{{card.key}}
</th> -->
<td ng-repeat='key in ["key", "name", "value", "suit", "color", "royal", "face", "number"]'>
<td ng-repeat='key in ["key", "name", "value", "suit", "color", "royal", "face", "number","loop"]'>
{{card[key]|boolToTick}}
</td>
</tr>
+7 -7
View File
@@ -90,11 +90,11 @@ var Game = module.exports =(function (Helpers, GameObjects, ObjectStorage,Rules,
// deal new initial cards that follow the rule
this.lastCards.splice(0,this.lastCards.length);
this.lastCards.push(_.sample(this.cards));
this.lastCards.push(angular.copy(_.sample(this.cards)));
var error,i;
for (i = 0; i < 52; i++) {
if (this.lastCards.length>2) break; // stop here
var card = _.sample(this.cards);
var card = angular.copy(_.sample(this.cards));
var res;
try{
res = this.rule.test(card,this.lastCards,this.cards);
@@ -103,9 +103,9 @@ var Game = module.exports =(function (Helpers, GameObjects, ObjectStorage,Rules,
// in case of an error just add a random card
// this is probobly because it is looking back 2 or 3 cards
// yet we only have 1
this.lastCards.push(_.sample(this.cards));
this.lastCards.push(card);
}
if (res) this.lastCards.push(_.sample(this.cards));
if (res) this.lastCards.push(angular.copy(_.sample(this.cards)));
}
if (this.lastCards.length<3) {
console.warn(
@@ -119,9 +119,9 @@ var Game = module.exports =(function (Helpers, GameObjects, ObjectStorage,Rules,
);
// feck, just deal 3 random then
this.lastCards.splice(0,this.lastCards.length);
this.lastCards.push(_.sample(this.cards));
this.lastCards.push(_.sample(this.cards));
this.lastCards.push(_.sample(this.cards));
this.lastCards.push(angular.copy(_.sample(this.cards)));
this.lastCards.push(angular.copy(_.sample(this.cards)));
this.lastCards.push(angular.copy(_.sample(this.cards)));
}
// this.lastCards.push.apply(this.lastCards,_.sampleSize(this.cards,3));
+21 -12
View File
@@ -406,7 +406,7 @@ var Rules = module.exports = (function functionName(_,chai) {
}, {
property: {
description: 'The property to compare in last and current card',
possibleVals: ['color', 'face', 'number', 'value', 'suit'],
possibleVals: ['color', 'face', 'number', 'suit'],
type: 'String'
},
n: {
@@ -473,8 +473,12 @@ var Rules = module.exports = (function functionName(_,chai) {
function (card, lastCards, allCards, options) {
var lastNCard = lastCards[lastCards.length - this.options.n];
var val = card.value%16;
var a = (lastNCard.value+options.max)%16;
var b = (lastNCard.value+options.min)%16;
var max = _.max([a,b]);
var min = _.min([a,b]);
return chai.expect(val).to.be
.within(lastNCard.value+options.min, lastNCard.value+options.max);
.within(min,max);
}, {
n: 1,
min: 1,
@@ -517,7 +521,7 @@ var Rules = module.exports = (function functionName(_,chai) {
"If the <%= lastn(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;
var lastWasEven = lastNCard.value % 2 == 0;
if (lastWasEven)
return chai.expect(card)
.to.have.property('color')
@@ -528,11 +532,11 @@ var Rules = module.exports = (function functionName(_,chai) {
.not.equals(options.evenColor);
}, {
n: 1,
evenColor: 'red',
evenColor: 'Red',
}, {
evenColor: {
description: 'The color to play if lastNCard was even',
possibleVals: ['red', 'black'],
possibleVals: ['Red', 'Black'],
type: 'String'
},
n: {
@@ -607,7 +611,7 @@ var Rules = module.exports = (function functionName(_,chai) {
}, {
property: {
description: 'The property to compare to the lastNCard',
possibleVals: ['suit', 'face', 'royal', 'color'],
possibleVals: ['face', 'royal', 'color'],
type: 'String'
},
n: {
@@ -617,7 +621,7 @@ var Rules = module.exports = (function functionName(_,chai) {
},
min: {
description: 'The min difference to the last nth card',
possibleVals: [5, 6, 7, 8, 9],
possibleVals: [3,4,5, 6, 7],
type: 'Number'
},
}, [
@@ -631,19 +635,24 @@ var Rules = module.exports = (function functionName(_,chai) {
),
new Rule(
"f4fba793-f886-4db8-9853-240002bb112e",
"If the <%= lastn(n) %> card was a <%= property %> card, play a higher value card otherwise lower.",
//TODO what if we have a high card? we can only go higher
"If the <%= lastn(n) %> card was a <%= property %> card, play a higher value card otherwise lower. But any card is OK if the <%= lastn(n) %> card was an Ace, King to Joker.",
function (card, lastCards, allCards, options) {
var lastNCard = lastCards[lastCards.length - options.n];
var value = lastNCard.value;
var lastHadProperty = lastNCard[options.property];
// reverse on card of these values
var reverseOn=[1,14,15,16];
if (reverseOn.indexOf(value)>-1) return true;
if (lastHadProperty) {
return chai.expect(card)
.to.have.property('value')
.above(lastNCard[options.value]);
.above(lastNCard.value);
} else {
return chai.expect(card)
.to.have.property('value')
.lessThan(lastNCard[options.value]);
.lessThan(lastNCard.value);
}
}, {
n: 1,
@@ -651,7 +660,7 @@ var Rules = module.exports = (function functionName(_,chai) {
}, {
property: {
description: 'The property to compare to the lastNCard',
possibleVals: ['face', 'royal', 'spade', 'club', 'diamond', 'heart', 'red', 'black'],
possibleVals: ['spade', 'club', 'diamond', 'heart', 'red', 'black'],
type: 'String'
},
n: {