Skip to content

Commit

Permalink
rel 01
Browse files Browse the repository at this point in the history
  • Loading branch information
agentx-cgn committed Feb 1, 2015
1 parent e99e47d commit fceecc5
Show file tree
Hide file tree
Showing 14 changed files with 3,853 additions and 101 deletions.
3,635 changes: 3,635 additions & 0 deletions source/explorer/data/H1-C1-tree.export

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion source/simulation/ai/hannibal/_debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@ var HANNIBAL_DEBUG = {
"fil": 0
}
},
"counter": []
"counter": [],
"export": "/home/noiv/.local/share/0ad/mods/hannibal/explorer/data/"
};
48 changes: 47 additions & 1 deletion source/simulation/ai/hannibal/_hannibal.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var HANNIBAL = (function() {
release: function(){
if(!this.context.importer.delete(this)){
this.deb("WARN : Serializer.release: could not release: %s", this);
};
}
return this;
},
import: function(){
Expand All @@ -103,6 +103,52 @@ var HANNIBAL = (function() {
context.data[this.klass] = this.serialize();
return new H.LIB[H.noun(this.name)](context);
},
exportJSON: function(){

var
file, lines, count,
id = this.context.id,
prefix = id + "::";

function logg(){
print( arguments.length === 0 ?
prefix + "#! append 0 ://\n" :
prefix + "#! append 0 :" + H.format.apply(H, arguments) + "\n"
);
}

if (
HANNIBAL_DEBUG &&
HANNIBAL_DEBUG.export &&
HANNIBAL_DEBUG.bots[id].fil
){

this.deb("INFO : exporting: %s", this.name);

file = HANNIBAL_DEBUG.export + this.name + ".export";
file = file.split(":").join("-");
lines = JSON.stringify(this.serialize(), null, " ").split("\n");
count = lines.length;

this.deb();
this.deb("EXPORT: %s lines, %s", file, count);

print(H.format("%s#! open 0 %s\n", prefix, file));
logg("// EXPORTED %s at %s", this.name, new Date());
lines.forEach(line => logg(line));
logg("// Export end of %s", this.name);
print(H.format("%s#! close 0\n", prefix));
// print("#! close 0\n");

this.deb("EXPORT: Done");
this.deb();

} else {
this.deb("INFO : did not export %s", this.name);

}

}
};

return H;}());
94 changes: 47 additions & 47 deletions source/simulation/ai/hannibal/_logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,53 +75,53 @@ HANNIBAL = (function(H){
printf: function(){
print(H.format.apply(H, arguments) + "\n");
},
logStart: function(ss, gs, settings){

var H = HANNIBAL, id = settings.player;

H.deb("------: LAUNCHER.CustomInit: Players: %s, PID: %s, difficulty: %s", H.count(ss.playersData), id, settings.difficulty);
H.deb(" :");
H.deb(" A: map from DEBUG: %s / %s", H.Debug.map ? H.Debug.map : "unkown", ss.gameType);
H.deb(" A: map: w: %s, h: %s, c: %s, cells: %s", ss.passabilityMap.width, ss.passabilityMap.height, ss.circularMap, gs.cellSize);
H.deb(" A: _entities: %s [ ]", H.count(ss._entities));
H.deb(" A: _templates: %s [ ]", H.count(ss._templates));
H.deb(" A: _techTemplates: %s [ ]", H.count(ss._techTemplates));
H.deb(" H: _techModifications: %s [%s]", H.count(ss._techModifications[id]), H.attribs(ss._techModifications[id]));
H.deb(" H: researchQueued: %s [ ]", H.count(ss.playersData[id].researchQueued));
H.deb(" H: researchStarted: %s [ ]", H.count(ss.playersData[id].researchStarted));
H.deb(" H: researchedTechs: %s [%s]", H.count(ss.playersData[id].researchedTechs), H.attribs(ss.playersData[id].researchedTechs).join(", "));
H.deb(" A: barterPrices: %s", H.prettify(ss.barterPrices));

},
logPlayers: function(players){

var
H = HANNIBAL, tab = H.tab, msg = "", head, props, format, tabs,
fmtAEN = item => item.map(b => b ? "1" : "0").join("");

H.deb();

head = "name, team, civ, phase, pop, ally, enmy, neut, colour".split(", ");
props = "name, team, civ, phase, popCount, isAlly, isEnemy, isNeutral, colour".split(", ");
tabs = [ 10, 6, 8, 10, 5, 6, 6, 6, 20];
format = {
isAlly: fmtAEN,
isEnemy: fmtAEN,
isNeutral: fmtAEN
};

H.zip(head, tabs, function(h, t){msg += tab(h, t);});
H.deb("PLAYER: " + msg);

H.each(players, function(id, player){
msg = "";
H.zip(props, tabs, function(p, t){
msg += (format[p]) ? tab(format[p](player[p]), t) : tab(player[p], t);
});
H.deb(" %s: %s", id, msg);
});

},
// logStart: function(ss, gs, settings){

// var H = HANNIBAL, id = settings.player;

// H.deb("------: LAUNCHER.CustomInit: Players: %s, PID: %s, difficulty: %s", H.count(ss.playersData), id, settings.difficulty);
// H.deb(" :");
// H.deb(" A: map from DEBUG: %s / %s", H.Debug.map ? H.Debug.map : "unkown", ss.gameType);
// H.deb(" A: map: w: %s, h: %s, c: %s, cells: %s", ss.passabilityMap.width, ss.passabilityMap.height, ss.circularMap, gs.cellSize);
// H.deb(" A: _entities: %s [ ]", H.count(ss._entities));
// H.deb(" A: _templates: %s [ ]", H.count(ss._templates));
// H.deb(" A: _techTemplates: %s [ ]", H.count(ss._techTemplates));
// H.deb(" H: _techModifications: %s [%s]", H.count(ss._techModifications[id]), H.attribs(ss._techModifications[id]));
// H.deb(" H: researchQueued: %s [ ]", H.count(ss.playersData[id].researchQueued));
// H.deb(" H: researchStarted: %s [ ]", H.count(ss.playersData[id].researchStarted));
// H.deb(" H: researchedTechs: %s [%s]", H.count(ss.playersData[id].researchedTechs), H.attribs(ss.playersData[id].researchedTechs).join(", "));
// H.deb(" A: barterPrices: %s", H.prettify(ss.barterPrices));

// },
// logPlayers: function(players){

// var
// H = HANNIBAL, tab = H.tab, msg = "", head, props, format, tabs,
// fmtAEN = item => item.map(b => b ? "1" : "0").join("");

// H.deb();

// head = "name, team, civ, phase, pop, ally, enmy, neut, colour".split(", ");
// props = "name, team, civ, phase, popCount, isAlly, isEnemy, isNeutral, colour".split(", ");
// tabs = [ 10, 6, 8, 10, 5, 6, 6, 6, 20];
// format = {
// isAlly: fmtAEN,
// isEnemy: fmtAEN,
// isNeutral: fmtAEN
// };

// H.zip(head, tabs, function(h, t){msg += tab(h, t);});
// H.deb("PLAYER: " + msg);

// H.each(players, function(id, player){
// msg = "";
// H.zip(props, tabs, function(p, t){
// msg += (format[p]) ? tab(format[p](player[p]), t) : tab(player[p], t);
// });
// H.deb(" %s: %s", id, msg);
// });

// },
diffJSON: function (a, b) {

// https://github.com/paldepind/dffptch
Expand Down
17 changes: 14 additions & 3 deletions source/simulation/ai/hannibal/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ HANNIBAL = (function(H){
return new H.LIB.Query(ctxClone.culture.store, hcq, debug);
},
class2name: function(klass){
return new H.LIB.Query(ctxClone.culture.store, klass + " CONTAIN").first().name;
var res = new H.LIB.Query(this.culture.store, klass + " CONTAIN").filter(node => {
return klass === "civilcentre" ? true : node.name.contains(klass)
});
if(!res.length){
this.deb("WARN : class2name: civ: %s class: %s no result", this.culture.civ, klass);
} else {
// this.deb(" CTX: class2name: klass: %s, name: %s", klass, res[0].name);
}
return res.length ? res[0].name : null;
},
});

Expand Down Expand Up @@ -203,12 +211,15 @@ HANNIBAL = (function(H){
return new H.LIB.Query(this.culture.store, hcq, debug);
},
class2name: klass => {
var res = new H.LIB.Query(this.culture.store, klass + " CONTAIN").execute();
var res = new H.LIB.Query(this.culture.store, klass + " CONTAIN").filter(node => {
return klass === "civilcentre" ? true : node.name.contains(klass)
});
if(!res.length){
this.deb("WARN : class2name: civ: %s class: %s no result", this.culture.civ, klass);
} else {
// this.deb(" CTX: class2name: klass: %s, name: %s", klass, res[0].name);
}
return res.length ? res[0].name : null;
// return new H.LIB.Query(this.culture.store, klass + " CONTAIN").first().name;
},

operators: H.HTN.Economy.operators,
Expand Down
9 changes: 3 additions & 6 deletions source/simulation/ai/hannibal/culture.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,9 @@ HANNIBAL = (function(H){
// H.attribs(this.context)
// );

this.deb("ents: count: %s", H.count(this.entities));
// this.deb("ents: count: %s", H.count(this.entities));
// this.deb("ents: attribs: %s", H.attribs(this.entities));

this.deb("ents: instance map: %s", this.entities instanceof Map);
this.deb("ents: instance object: %s", this.entities instanceof Object);



H.each(this.entities, (id, entity) => {
if (entity.owner() === this.id){
templates.push(entity._templateName);
Expand Down Expand Up @@ -697,6 +692,8 @@ HANNIBAL = (function(H){
}
});

// this.tree.exportJSON();

},
initialize: function (){

Expand Down
11 changes: 8 additions & 3 deletions source/simulation/ai/hannibal/economy.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,9 @@ HANNIBAL = (function(H){
name: node.name,
key: node.key,
costs: node.costs,
qualifies: true,
producer: null,
info: ""
qualifies: true, // think positive
producer: null, // to be determined
info: "" // debug
};
});

Expand Down Expand Up @@ -627,13 +627,17 @@ HANNIBAL = (function(H){
req = this.culture.tree.nodes[node.name].requires,
phase = this.culture.tree.nodes[node.name].phase,
phases = this.culture.phases;

// this.deb(" ORD: eval: %s req: %s, phs: %s", node.name, req, phase);

if (!phases.achieved(phase)){
/*
units.athen.support.female.citizen.house
*/
node.qualifies = false;
node.info = "needs phase " + phase;
// this.deb(" ORD: eval: %s phase: %s, not achieved", node.name, phase);

// this.deb(" ORD: #%s needs phase %s | %s > %s | %s, %s",
// this.id,
// phase,
Expand All @@ -647,6 +651,7 @@ HANNIBAL = (function(H){

// req might be phase
if (req && phases.achieved(req)){
// this.deb(" ORD: eval: %s req: %s, achieved", node.name, req);
return;
}

Expand Down
50 changes: 48 additions & 2 deletions source/simulation/ai/hannibal/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ HANNIBAL = (function(H){

},

processValue: function(fn){

var t0 = Date.now(), i = this.length;

while(i--){
this.data[i] = fn(this.data[i]);
}
this.deb(" GRD: processValue: %s %s msec", this.label, Date.now() - t0);
return this;

},

debIndex: function(index){
// puts lines on index for debugging

Expand Down Expand Up @@ -269,8 +281,8 @@ HANNIBAL = (function(H){
// Function("s", "t", body)(this.data, target.data);

// },
maxIndex: function(maxValue){
maxIndex: function(maxValue=256){

var
index = 0,
value = -1e6,
Expand All @@ -287,6 +299,36 @@ HANNIBAL = (function(H){
return [index, value];

},

transform: function(data, x, y, w, min, max) {
// lifted
var g = data[x + y * w];
if (g > min){data[x + y * w] = min;}
else if (g < min){min = g;}
if (++min > max){min = max;}
return min;
},
distanceTransform: function() {

var
data = this.data,
transform = this.transform,
s = this.size,
x = 0, y = 0, min = 0, max = 255;

for ( y = 0; y < s; ++y) {
min = max;
for ( x = 0; x < s; ++x) {min = transform(data, x, y, s, min, max);}
for ( x = s - 2; x >= 0; --x) {min = transform(data, x, y, s, min, max);}
}
for ( x = 0; x < s; ++x) {
min = max;
for ( y = 0; y < s; ++y) {min = transform(data, x, y, s, min, max);}
for ( y = s - 2; y >= 0; --y) {min = transform(data, x, y, s, min, max);}
}

},

addInfluence: function(coords, strength, maxDist, type="linear") {

maxDist = maxDist || this.size;
Expand Down Expand Up @@ -324,6 +366,8 @@ HANNIBAL = (function(H){
}
}}

return this;

},
blur: function (radius){

Expand Down Expand Up @@ -393,6 +437,8 @@ HANNIBAL = (function(H){

}

return this;

},
});

Expand Down
2 changes: 1 addition & 1 deletion source/simulation/ai/hannibal/language.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ HANNIBAL = (function(H){

});

this.deb(" LANG: loaded corpus: %s", this.corpusname);
// this.deb(" LANG: loaded corpus: %s", this.corpusname);

};

Expand Down
14 changes: 7 additions & 7 deletions source/simulation/ai/hannibal/launcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ HANNIBAL = (function(H) {
H.Launcher.prototype.logPlayers = function(players){

var
deb = this.deb, tab = H.tab, msg = "", head, props, format, tabs,
tab = H.tab, msg = "", head, props, format, tabs,
fmtAEN = item => item.map(b => b ? "1" : "0").join("");

deb();
this.deb();

head = "name, team, civ, phase, pop, ally, enmy, neut, colour".split(", ");
props = "name, team, civ, phase, popCount, isAlly, isEnemy, isNeutral, colour".split(", ");
Expand All @@ -364,15 +364,15 @@ HANNIBAL = (function(H) {
isNeutral: fmtAEN
};

H.zip(head, tabs, function(h, t){msg += tab(h, t);});
deb("PLAYER: " + msg);
H.zip(head, tabs, (h, t) => msg += tab(h, t));
this.deb("PLAYER: " + msg);

H.each(players, function(id, player){
H.each(players, (id, player) => {
msg = "";
H.zip(props, tabs, function(p, t){
H.zip(props, tabs, (p, t) => {
msg += (format[p]) ? tab(format[p](player[p]), t) : tab(player[p], t);
});
deb(" %s: %s", id, msg);
this.deb(" %s: %s", id, msg);
});

};
Expand Down

0 comments on commit fceecc5

Please sign in to comment.