python象棋单机版_chess_py-Python象棋客户端-Aubhro Sengupta License Talk @Pygotham 2016 Introduction Installati...

作者:Aubhro Sengupta

### 作者邮箱:aubhrosengupta@gmail.com

### 首页:https://github.com/LordDarkula/chess_py

### 文档:None

### 下载链接

chess_py

.. figure:: http://i.stack.imgur.com/yQaOq.png :alt: Board

Board

|Build Status| |Code Climate| |PyPI version| |Python27| |Python35| |License| |Twitter|

License

chesspy is available under the MIT license. See the LICENSE _ file for more info. Copyright © 2016 Aubhro Sengupta. All rights reserved.

Talk @Pygotham 2016

I gave a talk at PyGotham 2016 on this library. Abstract can be found here __.

Introduction

Chess_py is an open source chess library written in Python designed to aid in the creation of chess engines. Handles the chess so you can focus on the engine.

Installation

To use as a immediately start up a game between two human players in the console, navigate inside the root directory of the package and run main.py.

.. code:: bash

python main.py

To install package

pip (Recommended) ~~~~~~~~~~~~~~~~~~~~~~~

.. code:: bash

pip install chess_py

Or manually ~~~~~~~~~~~

.. code:: bash

python setup.py install

Documentation

View complete technical documentation here __.

Great! How do you use it? (An Example)

Chess_py has the capability of creating games between players, either human, or AI

.. code:: python

import chess_py

from chess_py import Game, Human, color

""" Creates a Game with 2 humans.

When run, this will open the console,"""

new_game = Game(Human(color.white), Human(color.black))

""" After game is completed, outcome will be stored in result.

The integer result will be one of three values.

white wins - 0, black wins - 1, draw - 0.5 """

result = new_game.play()

To build a chess engine on with chesspy, inherit Player and implement generatemove()

.. code:: python

import chess_py

from chess_py import Game, Human, color

# Engine which plays the move with the highest immediate material advantage

class MyEngine(chess_py.Player):

def __init__(self, input_color):

# Creates piece value scheme to specify value of each piece.

self.piece_values = chess_py.PieceValues.init_manual(PAWN_VALUE=1,

KNIGHT_VALUE=3,

BISHOP_VALUE=3,

ROOK_VALUE=5,

QUEEN_VALUE=9)

# Super call to

super(chess_py.Player, self).__init__(input_color)

def generate_move(self, position):

# position parameter is an object of type Board

# Finds all possible moves I can play.

moves = position.all_possible_moves(self.color)

# Initalizes best move and advantage after it has been played to dummy values.

best_move = None

best_move_advantage = -99

# Loops through possible moves

for move in moves:

""" advantage_as_result(move, piece_values) finds numerical advantage

as specified by piece value scheme above. Returns negative values for

positions of disadvantage. Returns +/-99 for checkmate. """

advantage = position.advantage_as_result(move, self.piece_values)

# If this move is better than best move, it is the best move.

if advantage >= best_move_advantage:

best_move = move

best_move_advantage = advantage

return best_move

# If file is run as script, a Game is set up between My_engine and Human and result is printed.

if __name__ == "__main__":

new_game = Game(MyEngine(color.white), Human(color.black))

# white wins - 0, black wins - 1, draw - 0.5

print("Result: ", new_game.play())

.. |Build Status| image:: https://travis-ci.org/LordDarkula/chesspy.svg?branch=master :target: https://travis-ci.org/LordDarkula/chesspy .. |Code Climate| image:: https://codeclimate.com/github/LordDarkula/chesspy/badges/gpa.svg :target: https://codeclimate.com/github/LordDarkula/chesspy .. |PyPI version| image:: https://badge.fury.io/py/chesspy.svg :target: https://pypi.python.org/pypi/chesspy .. |Python27| image:: https://img.shields.io/badge/python-2.7-blue.svg :target: https://www.python.org/download/releases/2.7/ .. |Python35| image:: https://img.shields.io/badge/python-3.5-blue.svg :target: https://www.python.org/downloads/release/python-350/ .. |License| image:: https://img.shields.io/cocoapods/l/EasyQL.svg?style=flat :target: https://github.com/LordDarkula/chess_py/blob/master/LICENSE .. |Twitter| image:: https://img.shields.io/badge/twitter-@LordDarkula-blue.svg?style=flat :target: http://twitter.com/LordDarkula

Copy from pypi.org

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值