Giter Club home page Giter Club logo

fightinggame-ftg4.50's Introduction

强化学习 格斗游戏 FightingICE game

国科大2022年春季学期强化学习大作业

Game Page: http://www.ice.ci.ritsumei.ac.jp/~ftgaic/index.htm

效果展示:bilibili (感谢队友的配音)

论文报告:Paper-fighting.pdf

PPT汇报:FightingGames.pptx

原始数据:original-data.xlsx

使用角色:

ZEN GARNET

1. Environment

This demo is based on Ubuntu 18 system.

Add java

sudo apt-get install openjdk-8-jre

If you have multi java:

sudo update-alternatives --config java

Add python

python = 3.8
pip install gym
pip install py4j
pip install port_for
pip install opencv-python

Close the screen in Linux

apt install -y xvfb

Run

Xvfb :2 -screen 0 1024x768x16 &
export DISPLAY=:2

Start the java server (modify the ftg.sh as Linux) and test. This is important on Linux

sh ftg.sh

注意,运行代码时候不要跑多个,即使修改端口4242也不行,虽然能运行,但很多指令传达不到,导致效果极差。

2. 基于SARSA的强化学习算法

标准赛道,对战双方初始血量都是400,1分钟限时情况下,剩余血量高者获胜。

由于状态是离散与连续共存,用$s$表示状态,其中$s \in \mathbb{R}^{144}$。 $s$主要包括自己的位置(连续信息),自己的动作(离散信息),对手的位置(连续信息),对手的动作(离散信息),以及双方能量条等。 通常可以通过离散连续变量的方法,或者使用神经网络的逼近器。这里我们使用$\mathcal{T}$对$s$进行变换,并通过贪心策略选择最佳动作

$$ a = \arg \max_a{\mathcal{T}(s)} $$

其中,$\mathcal{T}$为一个线性映射,通过权重$w \in \mathbb{R}^{40 \times 144}$,则

$$ \mathcal{T}(s) = w \cdot s $$

这样,通过线性映射的方式,可以间接表示Q值,则在SARSA的时序差分迭代中可以表示为

$$ w_{a_t} := w_{a_t} + \alpha \cdot (r + \gamma \cdot \mathcal{T}{a{t+1}}(s_{t+1}) - \mathcal{T}{a{t}}(s_{t})) \cdot s_t $$

其中$s$表示状态,$a$表示动作,$r$表示奖励值,$w$代表线性权重。

3. 基于DDD的强化学习

具体内容请见原文Paper-fighting.pdf

4. 训练代码

其中,fightingice_env.py文件被我修改,第40-43行,加入了变量character,这样可以自由从输入端选择ZENLUDGARNET了。

训练:

python train.py\ 
    --RL-method SARSA\
    --player ZEN

测试也是一样,通用了

python test.py\
    --CKPT checkpoint/SARSA/ZEN/weight.npy\
    --player ZEN\
    --Rounds 100

测试DDD:

python test_Dual.py\
		--CKPT checkpoint/Duel/GARNET/ckpt.pt\
		--player GARNET\
		--Rounds 100

5. 测试结果

我们在人物ZEN和GARNET上进行了测试。

5.1 训练曲线

5.2 限时60s 的测试结果

为了消融验证DDD 模型架构的可行性,另给定SARSA 算法作为baseline,它仅仅将Q 函数改为一层线性映射,训练过程保持不变。限定比赛时间60 秒,限制双方HP 上限,测试100 轮后得到结果下表所示:

角色ZEN:

算法 胜率 HP差 DPS
DDD 0.87 113.83 6.09
SARSA 0.52 0.81 3.48

角色GARNET:

算法 胜率 HP差 DPS
DDD 0.93 185.23 10.53
SARSA 0.77 115.16 9.79

5.3 HP 上限为100 的测试结果

为了验证DDD 算法在短期内的表现是否稳定,限定格斗过程中HP 上限为100,此时智能体只需8 次左右的有效攻击便可击败对方。1000 轮游戏中双方的游戏结果如下图所示。

fightinggame-ftg4.50's People

Contributors

ruoyuchen10 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fightinggame-ftg4.50's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.