Skip to content

Commit

Permalink
Fix build due to new Closure stub in Blockly
Browse files Browse the repository at this point in the history
Also remove some Closure from Genetics.
  • Loading branch information
NeilFraser committed Aug 23, 2019
1 parent 22b06b5 commit c175717
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ deps:

@# messages.js confuses the compiler by also providing "Blockly.Msg.en".
rm $(APP_ENGINE_THIRD_PARTY)/blockly/msg/messages.js
@# Blockly includes a Closure stub that confuses the compiler by also providing "goog".
rm -r $(APP_ENGINE_THIRD_PARTY)/blockly/closure

svn checkout https://github.com/NeilFraser/JS-Interpreter/trunk/ $(APP_ENGINE_THIRD_PARTY)/JS-Interpreter
@# Remove @license tag so compiler will strip Google's license.
Expand Down
12 changes: 8 additions & 4 deletions appengine/genetics/js/cage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ goog.provide('Genetics.Cage');

goog.require('Genetics.Mouse');

goog.require('goog.array');


/**
* The maximum population in a cage.
Expand Down Expand Up @@ -605,8 +603,14 @@ Genetics.Cage.addMouse = function(mouse) {
* @param {!Genetics.Mouse} mouse The mouse to kill.
*/
Genetics.Cage.die = function(mouse) {
goog.array.remove(Genetics.Cage.nextRoundMice_, mouse);
goog.array.remove(Genetics.Cage.currentRoundMice_, mouse);
var i = Genetics.Cage.nextRoundMice_.indexOf(mouse);
if (i != -1) {
Genetics.Cage.nextRoundMice_.splice(i, 1);
}
i = Genetics.Cage.currentRoundMice_.indexOf(mouse);
if (i != -1) {
Genetics.Cage.nextRoundMice_.splice(i, 1);
}
delete Genetics.Cage.miceMap_[mouse.id];
};

Expand Down
19 changes: 8 additions & 11 deletions appengine/genetics/js/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ goog.provide('Genetics.Mouse');

goog.require('Blockly.utils.math');

goog.require('goog.math');


/**
* Creates a mouse.
Expand All @@ -45,15 +43,15 @@ Genetics.Mouse = function(id, sex, playerId, opt_parentOne, opt_parentTwo) {
// Returns a random integer between two integers; minValue (inclusive)
// and maxValue (inclusive).
function randomInt(minValue, maxValue) {
return goog.math.randomInt(maxValue - minValue + 1) + minValue;
return Math.floor(Math.random() * maxValue - minValue + 1) + minValue;
}
if (opt_parentOne && opt_parentTwo) {
// Choose which functions are inherited from parents.
var pickFightParent = goog.math.randomInt(2);
var mateQuestionParent = goog.math.randomInt(2);
var pickFightParent = randomInt(0, 1);
var mateQuestionParent = randomInt(0, 1);
// Guarantee that at least one function is inherited from each parent.
var acceptMateParent = (pickFightParent === mateQuestionParent) ?
!mateQuestionParent : goog.math.randomInt(2);
!mateQuestionParent : randomInt(0, 1);
this.pickFightOwner = pickFightParent ? opt_parentOne.pickFightOwner :
opt_parentTwo.pickFightOwner;
this.proposeMateOwner = mateQuestionParent ?
Expand All @@ -62,17 +60,16 @@ Genetics.Mouse = function(id, sex, playerId, opt_parentOne, opt_parentTwo) {
opt_parentTwo.acceptMateOwner;
// Assign stats based on parents with some mutations.
this.size = Blockly.utils.math.clamp(
goog.math.average(opt_parentOne.size + opt_parentTwo.size) +
(opt_parentOne.size + opt_parentTwo.size) / 2 +
randomInt(Genetics.Mouse.MIN_MUTATION, Genetics.Mouse.MAX_MUTATION),
Genetics.Mouse.MIN_SIZE, Genetics.Mouse.MAX_SIZE);
this.startAggressiveness = Math.max(0, Math.round(
goog.math.average(opt_parentOne.startAggressiveness,
opt_parentTwo.startAggressiveness)) +
(opt_parentOne.startAggressiveness, opt_parentTwo.startAggressiveness)
/ 2) +
randomInt(Genetics.Mouse.MIN_MUTATION, Genetics.Mouse.MAX_MUTATION));
this.aggressiveness = this.startAggressiveness;
this.startFertility = Math.max(0, Math.round(
goog.math.average(opt_parentOne.startFertility,
opt_parentTwo.startFertility)) +
(opt_parentOne.startFertility + opt_parentTwo.startFertility) / 2) +
randomInt(Genetics.Mouse.MIN_MUTATION, Genetics.Mouse.MAX_MUTATION));
} else {
// Mouse is a first generation mouse.
Expand Down
2 changes: 1 addition & 1 deletion build-app.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def run(self):
try:
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
except:
print("Failed to Popen: %s" % cmd)
print("Failed to Popen: %s" % ' '.join(cmd))
raise
files = readStdout(proc)

Expand Down

0 comments on commit c175717

Please sign in to comment.