mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 05:08:00 +00:00
Improve AI
This commit is contained in:
parent
51c6b5fb75
commit
a50f219e57
|
@ -127,85 +127,70 @@ class Session {
|
||||||
|
|
||||||
//#region 各マスの価値を計算しておく
|
//#region 各マスの価値を計算しておく
|
||||||
|
|
||||||
// 標準的な 8*8 のマップなら予め定義した価値マップを使用
|
//#region 隅
|
||||||
if (this.o.mapWidth == 8 && this.o.mapHeight == 8 && !this.o.map.some(p => p == 'null')) {
|
this.cellWeights = this.o.map.map((pix, i) => {
|
||||||
this.cellWeights = [
|
if (pix == 'null') return 0;
|
||||||
1 , -0.4, 0 , -0.1, -0.1, 0 , -0.4, 1 ,
|
const [x, y] = this.o.transformPosToXy(i);
|
||||||
-0.4, -0.5, -0.2, -0.2, -0.2, -0.2, -0.5, -0.4,
|
let count = 0;
|
||||||
0 , -0.2, 0 , -0.1, -0.1, 0 , -0.2, 0 ,
|
const get = (x, y) => {
|
||||||
-0.1, -0.2, -0.1, -0.1, -0.1, -0.1, -0.2, -0.1,
|
if (x < 0 || y < 0 || x >= this.o.mapWidth || y >= this.o.mapHeight) return 'null';
|
||||||
-0.1, -0.2, -0.1, -0.1, -0.1, -0.1, -0.2, -0.1,
|
return this.o.mapDataGet(this.o.transformXyToPos(x, y));
|
||||||
0 , -0.2, 0 , -0.1, -0.1, 0 , -0.2, 0 ,
|
};
|
||||||
-0.4, -0.5, -0.2, -0.2, -0.2, -0.2, -0.5, -0.4,
|
|
||||||
1 , -0.4, 0 , -0.1, -0.1, 0 , -0.4, 1
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
//#region 隅
|
|
||||||
this.cellWeights = this.o.map.map((pix, i) => {
|
|
||||||
if (pix == 'null') return 0;
|
|
||||||
const [x, y] = this.o.transformPosToXy(i);
|
|
||||||
let count = 0;
|
|
||||||
const get = (x, y) => {
|
|
||||||
if (x < 0 || y < 0 || x >= this.o.mapWidth || y >= this.o.mapHeight) return 'null';
|
|
||||||
return this.o.mapDataGet(this.o.transformXyToPos(x, y));
|
|
||||||
};
|
|
||||||
|
|
||||||
const isNotSumi = (
|
const isNotSumi = (
|
||||||
// -
|
// -
|
||||||
// +
|
// +
|
||||||
// -
|
// -
|
||||||
(get(x - 1, y - 1) == 'empty' && get(x + 1, y + 1) == 'empty') ||
|
(get(x - 1, y - 1) == 'empty' && get(x + 1, y + 1) == 'empty') ||
|
||||||
|
|
||||||
// -
|
// -
|
||||||
// +
|
// +
|
||||||
// -
|
// -
|
||||||
(get(x, y - 1) == 'empty' && get(x, y + 1) == 'empty') ||
|
(get(x, y - 1) == 'empty' && get(x, y + 1) == 'empty') ||
|
||||||
|
|
||||||
// -
|
// -
|
||||||
// +
|
// +
|
||||||
// -
|
// -
|
||||||
(get(x + 1, y - 1) == 'empty' && get(x - 1, y + 1) == 'empty') ||
|
(get(x + 1, y - 1) == 'empty' && get(x - 1, y + 1) == 'empty') ||
|
||||||
|
|
||||||
//
|
//
|
||||||
// -+-
|
// -+-
|
||||||
//
|
//
|
||||||
(get(x - 1, y) == 'empty' && get(x + 1, y) == 'empty')
|
(get(x - 1, y) == 'empty' && get(x + 1, y) == 'empty')
|
||||||
)
|
)
|
||||||
|
|
||||||
const isSumi = !isNotSumi;
|
const isSumi = !isNotSumi;
|
||||||
|
|
||||||
return isSumi ? 1 : 0;
|
return isSumi ? 1 : 0;
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region 隅の隣は危険
|
//#region 隅の隣は危険
|
||||||
this.cellWeights.forEach((cell, i) => {
|
this.cellWeights.forEach((cell, i) => {
|
||||||
const [x, y] = this.o.transformPosToXy(i);
|
const [x, y] = this.o.transformPosToXy(i);
|
||||||
|
|
||||||
if (cell === 1) return;
|
if (cell === 1) return;
|
||||||
if (this.o.mapDataGet(this.o.transformXyToPos(x, y)) == 'null') return;
|
if (this.o.mapDataGet(this.o.transformXyToPos(x, y)) == 'null') return;
|
||||||
|
|
||||||
const get = (x, y) => {
|
const get = (x, y) => {
|
||||||
if (x < 0 || y < 0 || x >= this.o.mapWidth || y >= this.o.mapHeight) return 0;
|
if (x < 0 || y < 0 || x >= this.o.mapWidth || y >= this.o.mapHeight) return 0;
|
||||||
return this.cellWeights[this.o.transformXyToPos(x, y)];
|
return this.cellWeights[this.o.transformXyToPos(x, y)];
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSumiNear = (
|
const isSumiNear = (
|
||||||
(get(x - 1, y - 1) === 1) || // 左上
|
(get(x - 1, y - 1) === 1) || // 左上
|
||||||
(get(x , y - 1) === 1) || // 上
|
(get(x , y - 1) === 1) || // 上
|
||||||
(get(x + 1, y - 1) === 1) || // 右上
|
(get(x + 1, y - 1) === 1) || // 右上
|
||||||
(get(x + 1, y ) === 1) || // 右
|
(get(x + 1, y ) === 1) || // 右
|
||||||
(get(x + 1, y + 1) === 1) || // 右下
|
(get(x + 1, y + 1) === 1) || // 右下
|
||||||
(get(x , y + 1) === 1) || // 下
|
(get(x , y + 1) === 1) || // 下
|
||||||
(get(x - 1, y + 1) === 1) || // 左下
|
(get(x - 1, y + 1) === 1) || // 左下
|
||||||
(get(x - 1, y ) === 1) // 左
|
(get(x - 1, y ) === 1) // 左
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isSumiNear) this.cellWeights[i] = -0.5;
|
if (isSumiNear) this.cellWeights[i] = -0.125;
|
||||||
});
|
});
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue