簡體   English   中英

優化戰斗機器人

[英]Optimizing fighting bots

想象一下,您應該為一個機器人編寫一個算法,該算法將與其他類似准備的機器人戰斗。 你的機器人整場戰斗有 200 點生命值,每輪獲得 12 個能量點的設定值(最多 100 輪)。 您的機器人必須每一輪都進行攻擊,並且可以但不必保護自己。 有4種攻擊類型和4種相應的防御。 當一個機器人失去所有生命值或您超過 100 輪時,戰斗結束,在這種情況下,獲勝者是戰斗結束后擁有更多 HP 的人。 每個防御值 4 能量點,並在一輪中阻止給定類型的所有攻擊。 有 4 種不同的攻擊方式 - 鈎踢,價值 4 能量點,造成 10 生命值,鈎拳,價值 3 能量點,造成 6 生命值,上勾拳,價值 2 能量點,造成 3 生命值,低踢,價值 1 交易 1。你能夠收集所有先前回合的所有數據(機器人的 hp 和能量點、機器人的攻擊集、機器人的防御、造成和接收的傷害)。 顯然,我不希望任何人提出一個完整的解決方案,但是我無法理解它,我也沒有真正看到解決這個問題的方法,所以任何要閱讀的建議或相關主題都是真的很有幫助。 請注意,這通常與 ML 或 AI 無關。 只是一個算法。

您可以模擬您的機器人的隨機動作,然后模擬另一個機器人的隨機動作,依此類推,向前轉幾圈並計算結果(以點為單位)。 重復它,比如說,一百萬次,select 是你的機器人在數百萬變體中的最佳選擇。 這種方法稱為蒙特卡羅模擬 這很簡單,但它確實有效。 它不會給你最好的移動,但它會給你足夠好的移動,一個合理的移動。 您可以通過提前幾圈將所有可能的動作存儲到樹中來改進它,然后使用蒙特卡洛樹搜索,但實現起來有點困難。 為了使蒙特卡羅模擬快速有效,請使用快速偽隨機生成器,而不是您的編程語言提供的生成器,例如“XorShift”偽隨機數生成器。 有關更多信息,請參閱Wikipedia 上的 XorShift或參閱佛羅里達 State 大學的 George Marsaglia 撰寫的論文“Xorshift RNGs”,該論文於 2003 年發表在 Journal of Statistical Software,DOI:10.18637/jss.v008.i14 或搜索“ Xorshift RNGs”在語義學者。 您可以通過蒙特卡洛模擬解決各種任務,例如謎題,甚至是 Hex 游戲的優秀計算機玩家。

以下是 XorShift 的代碼示例:

const uint64_t initial_seed = 88172645463325252LL; // the intial seed value from the paper above mentioned

uint64_t current_seed = initial_seed;

// a basic xorshift routiine, returns a value in range [0..2^64)
inline uint64_t xorshift64(uint64_t& seed)
{
    seed ^= (seed << 13);
    seed ^= (seed >> 7);
    return (seed ^= (seed << 17));
}

// use one xorshift call to return one pseudorandom byte, each in the given range from 0, but less than the given limit, i.e. [0..limit), but the limit is not larger than 255
inline uint8_t rand_byte_lim(uint64_t& seed, const uint8_t limit)
{
    uint64_t x = xorshift64(seed);
    x &= 0xffffffffffffff; // 7 bytes
    x *= limit;
    x >>= 56; // 7 bytes * 8 bits = 56 bits
    return x & 0xff;
}

// use one xorshift call to return 8 pseudorandom bytes each in own range [0..limN), but a limN is not larger than 255
inline void rand_8_bytes(uint64_t& seed, const uint8_t lim1, uint8_t& res1, const uint8_t lim2, uint8_t& res2, const uint8_t lim3, uint8_t& res3, const uint8_t lim4, uint8_t& res4, const uint8_t lim5, uint8_t& res5, const uint8_t lim6, uint8_t& res6, const uint8_t lim7, uint8_t& res7, const uint8_t lim8, uint8_t& res8
)
{
    uint64_t x = xorshift64(seed);
    uint32_t t1 = (x >> (0 * 8)) & 0xff;
    uint32_t t2 = (x >> (1 * 8)) & 0xff;
    uint32_t t3 = (x >> (2 * 8)) & 0xff;
    uint32_t t4 = (x >> (3 * 8)) & 0xff;
    uint32_t t5 = (x >> (4 * 8)) & 0xff;
    uint32_t t6 = (x >> (5 * 8)) & 0xff;
    uint32_t t7 = (x >> (6 * 8)) & 0xff;
    uint32_t t8 = (x >> (7 * 8)) & 0xff;
    t1 *= lim1;
    t2 *= lim2;
    t3 *= lim3;
    t4 *= lim4;
    t5 *= lim5;
    t6 *= lim6;
    t7 *= lim7;
    t8 *= lim8;
    res1 = (t1 >> 8) & 0xff;
    res2 = (t2 >> 8) & 0xff;
    res3 = (t3 >> 8) & 0xff;
    res4 = (t4 >> 8) & 0xff;
    res5 = (t5 >> 8) & 0xff;
    res6 = (t6 >> 8) & 0xff;
    res7 = (t7 >> 8) & 0xff;
    res8 = (t8 >> 8) & 0xff;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM