Git Product home page Git Product logo

gym_chinese_chess's Introduction

gym-chinese-chess

一个简单的**象棋gym环境,可以产出类似Alpha zero算法需要的带有历史盘面的observation.

安装

运行如下指令安装**象棋gym环境

pip install -e .

**象棋gym 101

阅读 gym_101.ipynb 查看一些简单的使用例子.

在安装完gym-chinese-chess之后你可以简单的使用下面命令创建一个**象棋环境

import gym
chinese_chess_env = gym.make('gym_chinese_chess:cchess-v0')

并且可以通过

print(chinese_chess_env.render())

来展示当前盘面:

 9俥傌象士将士象傌俥
 8.........
 7.砲.....砲.
 6卒.卒.卒.卒.卒
 5.........
 4.........
 3兵.兵.兵.兵.兵
 2.炮.....炮.
 1.........
 0车马相仕帅仕相马车
  abcdefghi

可以通过

actions = chinese_chess_env.get_possible_actions()

获取action space中的所有当前局面下的可能action的integer list

也可以通过

moves = chinese_chess_env.get_possible_moves()

来取得局面下所有可能action的字符串形式

然后通过

state, reward, done, info = chinese_chess_enf.step(action)

的方式获得gym规范的state,reward,游戏是否结束标志done和一些调试信息info。

如果done为True,则游戏已经结束,

其他**象棋gym的用法在gym_101.ipynb中有列举,请参考其中列举的方法,相信你可以很快上手。

TODOs

  1. 本项目实现的规则与**象棋亚洲规则/**规则有一些区别,主要体现在长将/长捉的判断上,本项目出于方便考虑,并没有准确实现长将/长捉逻辑,本项目使用同局三现时若最后一个移动的子力非将军则判负这一简单逻辑来替代长将/长捉判断,这个逻辑在一些情况下仍然是很有问题的,之后如果有需求或者有时间会考虑更改替,也希望大家如果有兴趣可以提pr解决这个问题。

gym_chinese_chess's People

Contributors

bupticybee avatar

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.