Skip to content

Commit

Permalink
npm-watch
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghl-k committed Mar 12, 2018
1 parent 613e1ae commit 147d8dd
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 30 deletions.
18 changes: 9 additions & 9 deletions bundle-bare.js

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions bundle-main.js
@@ -0,0 +1,66 @@
(function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}return e})()({1:[function(require,module,exports){
var unique = require('uniq');

var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];

console.log(unique(data));
},{"uniq":2}],2:[function(require,module,exports){
"use strict"

function unique_pred(list, compare) {
var ptr = 1
, len = list.length
, a=list[0], b=list[0]
for(var i=1; i<len; ++i) {
b = a
a = list[i]
if(compare(a, b)) {
if(i === ptr) {
ptr++
continue
}
list[ptr++] = a
}
}
list.length = ptr
return list
}

function unique_eq(list) {
var ptr = 1
, len = list.length
, a=list[0], b = list[0]
for(var i=1; i<len; ++i, b=a) {
b = a
a = list[i]
if(a !== b) {
if(i === ptr) {
ptr++
continue
}
list[ptr++] = a
}
}
list.length = ptr
return list
}

function unique(list, compare, sorted) {
if(list.length === 0) {
return list
}
if(compare) {
if(!sorted) {
list.sort(compare)
}
return unique_pred(list, compare)
}
if(!sorted) {
list.sort()
}
return unique_eq(list)
}

module.exports = unique

},{}]},{},[1]);
18 changes: 9 additions & 9 deletions bundle.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions index-test.html
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<script src="bundle-main.js"></script>
</body>

</html>
5 changes: 5 additions & 0 deletions main.js
@@ -0,0 +1,5 @@
var unique = require('uniq');

var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];

console.log(unique(data));
14 changes: 9 additions & 5 deletions package.json
Expand Up @@ -3,8 +3,12 @@
"version": "1.0.0",
"description": "HTML5 Genetic Cars ==================",
"main": "cawro.js",
"watch": {
"build": "{src,test}/**/*.js"
},
"scripts": {
"watch": " npm run build && watch-run -p './src/**' npm run build",
"watch": "npm-watch",
"watch-wait": " npm run build && wait-run -p './src/**/*' npm run build-main",
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npm run build-main && npm run build-graph",
"build-main": "browserify --debug ./src/index.js -o ./bundle.js",
Expand All @@ -21,10 +25,10 @@
},
"homepage": "https://github.com/formula1/HTML5_Genetic_Cars#readme",
"devDependencies": {
"browserify": "^14.3.0"
"browserify": "^14.3.0",
"npm-watch": "^0.3.0"
},
"dependencies": {
"mersenne-twister": "^1.1.0",
"watch-run": "^1.2.5"
"mersenne-twister": "^1.1.0"
}
}
}
14 changes: 7 additions & 7 deletions src/world/run.js
Expand Up @@ -4,7 +4,7 @@ var carRun = require("../car-schema/run");
var defToCar = require("../car-schema/def-to-car");

module.exports = runDefs;
function runDefs(world_def, defs, listeners){
function runDefs(world_def, defs, listeners) {
if (world_def.mutable_floor) {
// GHOST DISABLED
world_def.floorseed = btoa(Math.seedrandom());
Expand All @@ -13,7 +13,7 @@ function runDefs(world_def, defs, listeners){
var scene = setupScene(world_def);
scene.world.Step(1 / world_def.box2dfps, 20, 20);
console.log("about to build cars");
var cars = defs.map((def, i)=> {
var cars = defs.map((def, i) => {
return {
index: i,
def: def,
Expand All @@ -25,19 +25,19 @@ function runDefs(world_def, defs, listeners){
return {
scene: scene,
cars: cars,
step: function(){
if(alivecars.length === 0){
step: function () {
if (alivecars.length === 0) {
throw new Error("no more cars");
}
scene.world.Step(1 / world_def.box2dfps, 20, 20);
listeners.preCarStep();
alivecars = alivecars.filter(function(car){
alivecars = alivecars.filter(function (car) {
car.state = carRun.updateState(
world_def, car.car, car.state
);
var status = carRun.getStatus(car.state, world_def);
listeners.carStep(car);
if(status === 0){
if (status === 0) {
return true;
}
car.score = carRun.calculateScore(car.state, world_def);
Expand All @@ -53,7 +53,7 @@ function runDefs(world_def, defs, listeners){

return false;
})
if(alivecars.length === 0){
if (alivecars.length === 0) {
listeners.generationEnd(cars);
}
}
Expand Down

0 comments on commit 147d8dd

Please sign in to comment.