私は実際にゲームの「地上メトリック エンジン」に取り組んでいます。私が基本的に行っていることは、実際のマップ データを別の連想配列にコピーし、それを肥沃度や湿度などのメトリック属性でマップすることです。サンプル コードを次に示します。
this.metricsMap = {};
this.generatedFertilities = {};
for (var i = 0; i < this.groundMap.data.length; i++) {
this.generatedFertilities[i] = this.groundMap.data[i].map(function () {
// TODO
});
}
for (var i = 0; i < this.groundMap.data.length; i++) {
this.metricsMap[i] = this.generatedFertilities[i].map(function (res) {
return {
ownedBy: "",
fertility: res,
humidity: 50
}
});
}
地図データは連想配列 [32][32] です。一貫性と「数の波」を備えた対応する「生殖能力マトリックス」を生成したいのですが、これは、より小さな連想配列で作成したいものの全体像です。
[68, 69, 70, 71, 72, 73, 74, 75, 74, 73],
[69, 70, 71, 72, 73, 74, 75, 74, 73, 72],
[70, 71, 72, 73, 74, 75, 74, 73, 72, 71],
[71, 72, 73, 74, 75, 74, 73, 72, 71, 60],
[72, 73, 74, 75, 74, 73, 72, 71, 60, 59],
[73, 74, 75, 74, 73, 72, 71, 60, 59, 58],
[74, 75, 74, 73, 72, 71, 60, 59, 58; 57],
[75, 74, 73, 72, 71, 60, 59, 58; 57, 56],
[74, 73, 72, 71, 60, 59, 58; 57, 56, 55],
[73, 72, 71, 60, 59, 58; 57, 56, 55, 54]
たとえば、マトリックスの中央により多くの濃度がある場合、より多くの「パターン」を想像できます。
私はこのような多くのことを試しました:
var baseRand = Math.floor(Math.random() * 100) + 1;
for (var i = 0; i < this.groundMap.data.length; i++) {
var counter = 0;
this.generatedFertilities[i] = this.groundMap.data[i].map(function () {
counter++;
// think of i like the y axis and counter like the x axis
if(i % 8 == 0){
if(counter < 8){
return Math.abs(Math.floor(baseRand++));
} else {
return Math.abs(Math.floor(baseRand--));
}
} else {
if(counter > 8){
return Math.abs(Math.floor(baseRand--));
} else {
return Math.abs(Math.floor(baseRand++));
}
}
});
}
しかし、これは私をどこかに連れて行かず、その背後にある数学に問題があります. このようなアルゴリズムをどのように設計しますか?