Answers.Body: <p>Yes. You can use the package to play against yourself and an engine. While I don't think there is one function that can do everything for you, but I can give you hints:</p>
  
  <p>To setup up a game against an AI:</p>
  
  <ul>
  <li>Read UCI documentation (you can find on Google)</li>
  <li>Read the UCI functions for python-chess <a href="https://python-chess.readthedocs.io/en/v0.14.1/uci.html" rel="nofollow">here</a></li>
  <li>Spawn an engine thread by <code>engine = chess.uci.popen_engine("/usr/games/stockfish")</code></li>
  <li>Start a new game by <code>engine.uci()</code></li>
  <li>Send a move by <code>engine.position</code></li>
  <li>Start analysis by <code>engine.go</code></li>
  <li>Get engine results by <code>command.result()</code></li>
  </ul>
  
  <p>You will need to read the documentation carefully.</p>
  
  <p>To setup a game against yourself (copied from the package documentation)</p>
  
  <pre><code>&gt;&gt;&gt; import chess
  
  &gt;&gt;&gt; board = chess.Board()
  
  &gt;&gt;&gt; board.push_san("e4")
  Move.from_uci('e2e4')
  &gt;&gt;&gt; board.push_san("e5")
  Move.from_uci('e7e5')
  &gt;&gt;&gt; board.push_san("Qh5")
  Move.from_uci('d1h5')
  &gt;&gt;&gt; board.push_san("Nc6")
  Move.from_uci('b8c6')
  &gt;&gt;&gt; board.push_san("Bc4")
  Move.from_uci('f1c4')
  &gt;&gt;&gt; board.push_san("Nf6")
  Move.from_uci('g8f6')
  &gt;&gt;&gt; board.push_san("Qxf7")
  Move.from_uci('h5f7')
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-25T14:48:59.690Z
Answers.Text: Apart from python-chess, is there anything else which not requires to build the above by yourself? (Thanks though!)
Answers.UserDisplayName: theshepherd
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-25T15:39:44.060Z
Answers.Text: @theshepherd A GUI like Chessbase, Arena?
Answers.UserDisplayName: SmallChess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T15:59:52.423Z
Answers.Text: Yes but with a CLI interface, so I can parse the results in a Python script.
Answers.UserDisplayName: theshepherd
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-27T17:54:24.023Z
Answers.Text: see http://wiki.bitplan.com/index.php/Python-chess
Answers.UserDisplayName: Wolfgang Fahl
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-25T12:29:07.740Z
Answers.LastActivityDate: 2016-07-25T12:29:07.740Z
Answers.UserDisplayName: SmallChess
Answers.Body: <p>You mentioned an AI. It might not be very strong, but <a href="https://github.com/thomasahle/sunfish" rel="nofollow">sunfish</a> is an example of a Python-based chess program, should you decide to go down that route.</p>
  
  <p>Do also bear in mind that XBoard protocol is a valid option, using Polyglot by Fabien Letouzey to convert from UCI to XBoard. It is much harder to convert from XBoard to UCI, through something like WB2UCI by Odd Gunnar Malin, as XBoard is much more lax about things like thinking output.</p>
  
  <p>I would recommend creating an account on the <a href="http://talkchess.com" rel="nofollow">Computer Chess Club</a> if you are going to create a GUI.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-27T08:10:38.143Z
Answers.LastActivityDate: 2016-07-27T08:10:38.143Z
Answers.UserDisplayName: ZirconiumX
Answers.Body: <p>Cutechess cli ( <a href="https://chessprogramming.wikispaces.com/Cutechess-cli" rel="nofollow">https://chessprogramming.wikispaces.com/Cutechess-cli</a> ) by Ilari Pihlajisto, is often used to run automated engine-engine matches. There is also work on a python port. ( <a href="http://www.talkchess.com/forum/viewtopic.php?t=60504" rel="nofollow">http://www.talkchess.com/forum/viewtopic.php?t=60504</a> ) Github: <a href="https://github.com/lucasart/zinc" rel="nofollow">https://github.com/lucasart/zinc</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-14T07:31:41.770Z
Answers.Text: ZINC isn't a python port of cutechess-cli.
Answers.UserDisplayName: ZirconiumX
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-13T18:51:08.110Z
Answers.LastActivityDate: 2016-08-13T18:51:08.110Z
Answers.UserDisplayName: Thomas Ahle
Body: <p>I am searching for a program/library in Python which will let two users or a user and an AI play chess with each other.</p>
  
  <p>PS: I have found <a href="https://pypi.python.org/pypi/python-chess" rel="nofollow">python-chess</a>. Can this be used for the above along with a chess engine?</p>
  
Tags: <engines><software><python>
Title: Play chess in Python programming language?
ThreadText: # Play chess in Python programming language?
  
  (Asked by: username_0 on 2016-07-25)
  
  I am searching for a program/library in Python which will let two users or a user and an AI play chess with each other.
  
  PS: I have found [python-chess](https://pypi.python.org/pypi/python-chess). Can this be used for the above along with a chess engine?
  
  **Tags:** engines, software, python
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2016-07-25. Score: 2
  
  Yes. You can use the package to play against yourself and an engine. While I don't think there is one function that can do everything for you, but I can give you hints:
  To setup up a game against an AI:
  
  Read UCI documentation (you can find on Google)
  Read the UCI functions for python-chess here
  Spawn an engine thread by engine = chess.uci.popen_engine("/usr/games/stockfish")
  Start a new game by engine.uci()
  Send a move by engine.position
  Start analysis by engine.go
  Get engine results by command.result()
  
  You will need to read the documentation carefully.
  To setup a game against yourself (copied from the package documentation)
  >>> import chess
  
  >>> board = chess.Board()
  
  >>> board.push_san("e4")
  Move.from_uci('e2e4')
  >>> board.push_san("e5")
  Move.from_uci('e7e5')
  >>> board.push_san("Qh5")
  Move.from_uci('d1h5')
  >>> board.push_san("Nc6")
  Move.from_uci('b8c6')
  >>> board.push_san("Bc4")
  Move.from_uci('f1c4')
  >>> board.push_san("Nf6")
  Move.from_uci('g8f6')
  >>> board.push_san("Qxf7")
  Move.from_uci('h5f7')
  
  > **Comments:**
  > **username_0**: Apart from python-chess, is there anything else which not requires to build the above by yourself? (Thanks though!)  
  > **username_1**: @username_0 A GUI like Chessbase, Arena?  
  > **username_0**: Yes but with a CLI interface, so I can parse the results in a Python script.  
  > **username_2**: see http://wiki.bitplan.com/index.php/Python-chess  
  
  ---
  
  ### Answer by username_3 on 2016-07-27. Score: 1
  
  You mentioned an AI. It might not be very strong, but [sunfish](https://github.com/thomasahle/sunfish) is an example of a Python-based chess program, should you decide to go down that route.
  
  Do also bear in mind that XBoard protocol is a valid option, using Polyglot by Fabien Letouzey to convert from UCI to XBoard. It is much harder to convert from XBoard to UCI, through something like WB2UCI by Odd Gunnar Malin, as XBoard is much more lax about things like thinking output.
  
  I would recommend creating an account on the [Computer Chess Club](http://talkchess.com) if you are going to create a GUI.
  
  
  ---
  
  ### Answer by username_4 on 2016-08-13. Score: 0
  
  Cutechess cli ( <https://chessprogramming.wikispaces.com/Cutechess-cli> ) by Ilari Pihlajisto, is often used to run automated engine-engine matches. There is also work on a python port. ( <http://www.talkchess.com/forum/viewtopic.php?t=60504> ) Github: <https://github.com/lucasart/zinc>
  
  > **Comments:**
  > **username_3**: ZINC isn't a python port of cutechess-cli.  
  
  ---
  
  