Browse Source

Temperature loss, refined model

pull/2/head
Robert Chen 11 years ago
parent
commit
be8ce4c28d
  1. 65
      js/model.js
  2. 10
      js/screens.js
  3. 9
      js/ui.js

65
js/model.js

@ -6,11 +6,12 @@ function TurkeyLayer( name, layerNumber1, turkeyModel, ovenModel ){
this.waterLost = 0; this.waterLost = 0;
this.finalTemperature = 20; this.finalTemperature = 20;
this.cookCondition = "Raw"; this.cookCondition = "Raw";
this.highestTemp = 0;
return { return {
updateTemperatureTick: function(){ updateTemperatureTick: function(){
that.finalTemperature = turkeyModel.globTemp[that.layerNumber] that.finalTemperature = turkeyModel.globTemp[that.layerNumber]
console.log(turkeyModel.globTemp) if(DEBUG) console.log(turkeyModel.globTemp);
that.highestTemp = that.finalTemperature > that.highestTemp ? that.finalTemperature : that.highestTemp;
that.waterLost = that.waterLost + UtilityFunctions.waterLoss( that.finalTemperature ); that.waterLost = that.waterLost + UtilityFunctions.waterLoss( that.finalTemperature );
that.cookCondition = UtilityFunctions.cookCondition(that.waterLost, that.name); that.cookCondition = UtilityFunctions.cookCondition(that.waterLost, that.name);
if(DEBUG) console.log( that.name + ": "+ that.waterLost + " " + that.cookCondition + " " + that.finalTemperature + " C" ); if(DEBUG) console.log( that.name + ": "+ that.waterLost + " " + that.cookCondition + " " + that.finalTemperature + " C" );
@ -20,6 +21,9 @@ function TurkeyLayer( name, layerNumber1, turkeyModel, ovenModel ){
}, },
getTemperature: function(){ getTemperature: function(){
return that.finalTemperature; return that.finalTemperature;
},
getHighestTemp: function(){
return that.highestTemp;
} }
} }
@ -40,8 +44,8 @@ function TurkeyModel( weight, ovenModel ){
this.totalLayers = [ new TurkeyLayer("Skin", this.splitsNum-1, this, ovenModel ), this.totalLayers = [ new TurkeyLayer("Skin", this.splitsNum-1, this, ovenModel ),
new TurkeyLayer("Body", this.splitsNum-4, this, ovenModel ), new TurkeyLayer("Body", this.splitsNum-10, this, ovenModel ),
new TurkeyLayer("Core", 0, this, ovenModel ) ]; new TurkeyLayer("Core", 1, this, ovenModel ) ];
// Whenever temperature is changed // Whenever temperature is changed
this.updateLayerTemps = function() { this.updateLayerTemps = function() {
@ -113,15 +117,18 @@ function OvenModel( turkeyWeight, gameState ) {
return { return {
"skin" : { "skin" : {
"temp": turkey.totalLayers[0].getTemperature(), "temp": turkey.totalLayers[0].getTemperature(),
"cond": turkey.totalLayers[0].getCondition() "cond": turkey.totalLayers[0].getCondition(),
"highest" : turkey.totalLayers[0].getHighestTemp()
}, },
"body" : { "body" : {
"temp": turkey.totalLayers[1].getTemperature(), "temp": turkey.totalLayers[1].getTemperature(),
"cond": turkey.totalLayers[1].getCondition() "cond": turkey.totalLayers[1].getCondition(),
"highest" : turkey.totalLayers[1].getHighestTemp()
}, },
"core" : { "core" : {
"temp": turkey.totalLayers[2].getTemperature(), "temp": turkey.totalLayers[2].getTemperature(),
"cond": turkey.totalLayers[2].getCondition() "cond": turkey.totalLayers[2].getCondition(),
"highest" : turkey.totalLayers[2].getHighestTemp()
} }
}; };
}, },
@ -231,7 +238,7 @@ UtilityFunctions = {
for (var k=0; k<splitsNum; k++){ for (var k=0; k<splitsNum; k++){
globTemp[k]=alpha*dPdr[k]/Math.pow(pointRadius[k],2)*deltat + globTemp[k] //dTdr * deltaT in one loop globTemp[k]=alpha*dPdr[k]/Math.pow(pointRadius[k],2)*deltat + globTemp[k] //dTdr * deltaT in one loop
} }
//dTdt(1)=dTdt(1)/2; //dTdt(1)=dTdt(1)/2;
} }
return(globTemp) return(globTemp)
@ -252,28 +259,28 @@ UtilityFunctions = {
}, },
cookCondition: function(cookValue, layerName){ cookCondition: function(cookValue, layerName){
if( layerName == "skin" ){ if( layerName == "Skin" || layerName == "Body" ){
var multiplier = 1; var multiplier = 1;
if (cookValue>=multiplier*600000) { if (cookValue>=multiplier*400000) {
return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"]; return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"];
} }
else if(cookValue>=multiplier*250000) { else if(cookValue>=multiplier*350000) {
return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"]; return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"];
} }
else if (cookValue>=multiplier*150000) { else if (cookValue>=multiplier*300000) {
return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"]; return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"];
} }
else if (cookValue>=multiplier*85000){ else if (cookValue>=multiplier*250000){ // >250000
return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"]; return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"];
} }
else if (cookValue>=multiplier*12000) { else if (cookValue>=multiplier*80000) { // >50000
return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"]; return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"];
} }
else if (cookValue>=multiplier*10000){ else if (cookValue>=multiplier*50000){
return ["Undercooked", (cookValue-5000)/(multiplier*12000), "slightly cooked"]; return ["Undercooked", (cookValue-5000)/(multiplier*10000), "slightly cooked"];
} }
else if (cookValue>=multiplier*5000) { else if (cookValue>=multiplier*25000) { //
return ["Undercooked", (cookValue-5000)/(multiplier*12000), "undercooked"]; return ["Undercooked", (cookValue-5000)/(multiplier*10000), "undercooked"];
} }
else { else {
return ["Raw", 1, "raw"]; return ["Raw", 1, "raw"];
@ -281,26 +288,26 @@ UtilityFunctions = {
} }
else{ else{
var multiplier = 1; var multiplier = 1;
if (cookValue>=multiplier*600000) { if (cookValue>=multiplier*45000) { //
return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"]; return ["Fire", (cookValue-600000)/(multiplier*600000),"fire"];
} }
else if(cookValue>=multiplier*250000) { else if(cookValue>=multiplier*35000){//
return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"]; return ["Burnt", (cookValue-250000)/(multiplier*600000), "burnt"];
} }
else if (cookValue>=multiplier*150000) { else if (cookValue>=multiplier*25000){ //
return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"]; return ["Dry", (cookValue-150000)/(multiplier*250000), "dry"];
} }
else if (cookValue>=multiplier*85000){ else if (cookValue>=multiplier*22000){ //
return ["Cooked", (cookValue-12000)/(multiplier*150000), "overcooked"]; return ["Cooked", (cookValue-22000)/(multiplier*150000), "overcooked"];
} }
else if (cookValue>=multiplier*12000) { else if (cookValue>=multiplier*12000){ //
return ["Cooked", (cookValue-12000)/(multiplier*150000), "cooked"]; return ["Cooked", (cookValue-12000)/(multiplier*85000), "cooked"];
} }
else if (cookValue>=multiplier*10000){ else if (cookValue>=multiplier*7000){ //
return ["Undercooked", (cookValue-5000)/(multiplier*12000), "slightly cooked"]; return ["Undercooked", (cookValue-7000)/(multiplier*7000), "slightly cooked"];
} }
else if (cookValue>=multiplier*5000) { else if (cookValue>=multiplier*3000) {
return ["Undercooked", (cookValue-5000)/(multiplier*12000), "undercooked"]; return ["Undercooked", (cookValue-3000)/(multiplier*7000), "undercooked"];
} }
else { else {
return ["Raw", 1, "raw"]; return ["Raw", 1, "raw"];

10
js/screens.js

@ -405,7 +405,7 @@ function ScoreScreen( stage, gameState ){
var totalScore = 0; var totalScore = 0;
var skinScoreChart = { var skinScoreChart = {
"raw": 0, "raw": -1000,
"undercooked": -100, "undercooked": -100,
"slightly cooked": 75, "slightly cooked": 75,
"cooked": 500, "cooked": 500,
@ -419,7 +419,7 @@ function ScoreScreen( stage, gameState ){
"undercooked": 125, "undercooked": 125,
"slightly cooked": 750, "slightly cooked": 750,
"cooked": 1000, "cooked": 1000,
"overcooked": 1000, "overcooked": 600,
"dry": 400, "dry": 400,
"burnt": 0 "burnt": 0
}; };
@ -444,7 +444,7 @@ function ScoreScreen( stage, gameState ){
var outerTemp = UtilityFunctions.C2F(turkeyState.skin.temp).toFixed(2); var outerTemp = UtilityFunctions.C2F(turkeyState.skin.temp).toFixed(2);
var coreTemp = UtilityFunctions.C2F(turkeyState.core.temp).toFixed(2); var coreTemp = UtilityFunctions.C2F(turkeyState.core.temp).toFixed(2);
var outerTempScore = that.scoreDistribution( outerTemp ) * 200; var outerTempScore = that.scoreDistribution( outerTemp, "skin" ) * 200;
var coreTempScore = that.scoreDistribution( coreTemp ) * 200; var coreTempScore = that.scoreDistribution( coreTemp ) * 200;
totalScore += parseInt(skinScoreChart[ turkeyState.skin.cond[2]]); totalScore += parseInt(skinScoreChart[ turkeyState.skin.cond[2]]);
@ -594,14 +594,14 @@ function ScoreScreen( stage, gameState ){
// Modifiers // Modifiers
var turkeyMod = typeToMod[gameState.turkeyType]; var turkeyMod = typeToMod[gameState.turkeyType];
var turkeyTypeModifierText = new createjs.Text( "+"+(Math.abs(turkeyMod-1)*100).toFixed(0) + "%", "20px Arial", "black" ); var turkeyTypeModifierText = new createjs.Text( ((1-turkeyMod)*100).toFixed(0) + "%", "20px Arial", "black" );
turkeyTypeModifierText.x = 310; turkeyTypeModifierText.x = 310;
turkeyTypeModifierText.y = 437; turkeyTypeModifierText.y = 437;
totalScore *= turkeyMod; totalScore *= turkeyMod;
var stuffingTypeModifierText = new createjs.Text( "+"+(Math.abs(gameState.stuffingTypeModifier-1)*100).toFixed(0)+"%" , "20px Arial", "black" ); var stuffingTypeModifierText = new createjs.Text( ((1-gameState.stuffingTypeModifier-1)*100).toFixed(0)+"%" , "20px Arial", "black" );
stuffingTypeModifierText.x = 310 stuffingTypeModifierText.x = 310
stuffingTypeModifierText.y = 457; stuffingTypeModifierText.y = 457;

9
js/ui.js

@ -523,7 +523,7 @@ function OvenUI( stage, gameState ){
gameState.pubsub.publish("Death",""); gameState.pubsub.publish("Death","");
gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:evalSkin[turkeyState["skin"]["cond"][2]] + "." } ); gameState.pubsub.publish( "ShowDialog", {seq:"custom", autoAdvance:true, customText:evalSkin[turkeyState["skin"]["cond"][2]] + "." } );
gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} ); gameState.pubsub.publish( "AddRecord", {type:"Open ", text:"The turkey looked " + turkeyState["skin"]["cond"][2]} );
//gameState.ovenModel.setRawTemp( (gameState.ovenModel.getRawTemp() - 25) < 150 ? 150 : gameState.ovenModel.getRawTemp() - 25 ); gameState.ovenModel.setRawTemp( (gameState.ovenModel.getRawTemp() - 3 ) < 20 ? 20 : gameState.ovenModel.getRawTemp() - 3 );
gameState.ovenOpened++; gameState.ovenOpened++;
} }
@ -595,8 +595,13 @@ function OvenUI( stage, gameState ){
this.secondTick = function(diff){ this.secondTick = function(diff){
// check if oven door is open // check if oven door is open
if( that.ovenDoor == OVEN_OPEN ){
gameState.ovenModel.setRawTemp( (gameState.ovenModel.getRawTemp() - 1 ) < 20 ? 20 : gameState.ovenModel.getRawTemp() - 1 );
}
gameState.ovenModel.secondTick(); gameState.ovenModel.secondTick();
gameState.currentTime += diff; gameState.currentTime += diff;
gameState.turkeyCookCounter++;
} }
gameState.pubsub.subscribe( "SkipTime", function(){ gameState.pubsub.subscribe( "SkipTime", function(){
@ -765,9 +770,9 @@ function WindowUI( stage, gameState ){
stage.addChild( dayNight ); stage.addChild( dayNight );
stage.addChild( ground ); stage.addChild( ground );
stage.addChild( houses ); stage.addChild( houses );
stage.addChild( stars );
stage.addChild( animation ); stage.addChild( animation );
stage.addChild( mood ); stage.addChild( mood );
stage.addChild( stars );
for( var i in smallWindows ){ for( var i in smallWindows ){
smallWindows[i].visible = UtilityFunctions.randRange(0,1); smallWindows[i].visible = UtilityFunctions.randRange(0,1);

Loading…
Cancel
Save