1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Screeps:Arena]敵味方の戦力を計算してみる

Last updated at Posted at 2022-04-24

今はCapture The Flagをやっているため、戦力評価の対象はCreepだけとする。(正確を期すにはタワーも考慮すべきではある。)

以下のように定義してみた。

  • 1機のCreepの戦力 = 各パーツの (コスト * 残HP) の合計
  • 敵または味方の戦力 = 手持ちCreepの戦力の合計

この計算式だと、CTF(Basic)開始時の自分の戦力は1,352,000となる。

また、戦況判断の指標として戦力比も定義してみた。

  • 戦力比 = log2(味方の戦力/敵の戦力)

こちらの戦力が敵の2倍なら1、半分なら-1、同じなら0になる。
1.4142倍であれば0.5。0.70710倍であれば-0.5。

以下、ソースコード。

import { utils } from 'game';
import * as C from 'game/constants'

// クリープの戦力計算
const evaluateCreep = (creep) => {
    return creep.body.reduce(
        (accumulator, bodyPart) => {
            return accumulator + C.BODYPART_COST[bodyPart.type] * bodyPart.hits
        }
        , 0 //accumulatorの初期値
    )
}
// 戦力比
export const calcForceRatio = () => {
    const enemyCreeps = utils.getObjectsByPrototype(Creep).filter(c => !c.my);
    const myCreeps = utils.getObjectsByPrototype(Creep).filter(c => c.my);
    const enemyForce = enemyCreeps.map(evaluateCreep).reduce((a, b) => a + b, 0);
    if (enemyForce === 0) return Infinity;
    const myForce = myCreeps.map(evaluateCreep).reduce((a, b) => a + b, 0);
    return Math.log2(myForce / enemyForce);
}

おわり。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?