marcusbuffett / command-line-chess Goto Github PK
View Code? Open in Web Editor NEWA python program to play chess against an AI in the terminal.
License: MIT License
A python program to play chess against an AI in the terminal.
License: MIT License
Some users are interested in command line support for lichess. Thought you may want to know. Lichess provides a public API that can be used to interact with lichess. lichess-org/lila#1853
I think that it would be really good if this Chess app had multiplayer capabilities so that one could play with someone else who has this app, or it could even just be people on the same network with the app installed, but whatever it is, some sort of multiplayer capabilities would be good.
In the process of adding the new CLI, @GauthamBellamkonda noticed that termcolor has a very limited color set which doesn't provide as much flexibility as we want to provide.
To fix this, we need to find another library which provides the following abilities:
Right now the CLI provides an option named --unicode
or -u
which uses unicode characters to display the pieces.
If the option isn't used, then it falls back to "normal", non-unicode characters.
In the process of switching out termcolor to colored We noticed that it is really hard to display a colored board with non-unicode characters.
To fix this, I decided to remove the non-unicode character support and make the --unicode
behaviour standard.
ToDo:
--unicode
option as it is the defaultmakeStringRep
method)When I run it like !pip install cl-chess it works fine but when instead I use:
git clone https://github.com/marcusbuffett/command-line-chess
like you suggested (so it has the most recent version), it shows a different graphical version of the chess board.
This is how it looks with pip install
and this is git clone:
I only play chess IRL, not online, so maybe I am not used to how it works, but the git clone way only shows me what the AI is doing, not my own moves.
I should note that I am using Google Colab, so maybe somehow that is changing it. In case you want to try it, the Google Colab code is:
!git clone https://github.com/marcusbuffett/command-line-chess
%cd /content/command-line-chess
!pip install .
!chess
This is more of a collecting tank for some "little" improvements.
Some of these are:
flake8
errorsCoordinate
and abstract classHi, not sure if this is the right place for this, but I noticed on PyPI that the current release is from July 31, 2020. I think this means that when 'pip3 install cl-chess' is run, the version from then will be installed.
I haven't done it myself, but I know there's a way to sync up github with PyPI releases. E.g: https://www.youtube.com/watch?v=U-aIPTS580s
Is it possible to print the list of moves already made while playing the game?
I know you don't officially support Google Colab, but I am not sure if this is a problem only with Colab or not (I don't run Python locally so I have not tried it without Colab). In Colab when I install via git clone like:
!pip install git+https://github.com/marcusbuffett/command-line-chess
and run it like:
!chess --white="red"
it does not correctly show the position of the pieces that were moved. It looks like this:
If I instead use your old version by installing it like:
!pip install cl-chess
it works fine, see below:
Just as an example, here is the board, player is white. As you can see, castling is not in the list of possible moves. There is a Board.getShortNotationOfMove() that should return '0-0-0' and '0-0', but move.kingsideCastle and move.queensideCastle are not getting recognized at that point.
It's your move. Type '?' for options. ? 0-0
command: 0-0
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? o-o
command: o-o
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? O-O
command: o-o
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? 0-0-0
command: 0-0-0
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? o-o-o
command: o-o-o
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? O-O-O
command: o-o-o
move None
Couldn't parse input, enter a valid command or move.
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ? l
command: l
a3
a4
b3
b4
c3
d3
d4
e5
g3
g4
h3
h4
Nc3
Na3
Qe2
Ke2
Kf1
Bd5
Be6
Bxf7
Bd3
Be2
Bf1
Bb5
Bxa6
Bb3
Nh4
Nd4
Nxg5
Ng1
Ne5
Rg1
Rf1
a b c d e f g h
8 R N B Q K B N R 8
7 x p x p p p x p 7
6 p x x x x x x x 6
5 x x p x x x p x 5
4 x x B x p x x x 4
3 x x x x x N x x 3
2 p p p p x p p p 2
1 R N B Q K x x R 1
a b c d e f g h
Currently, the point difference is : 0
It's your move. Type '?' for options. ?
For the information how the AI works right now, please look at this article.
It would be kinda interesting to research if there are other (faster, more efficient) ways.
And if there are such ways, then we could implement them.
For question or answers to this task, just leave a comment or create a new issue. If there are any other questions or so, please open an issue.
Currently, the point difference is : 3
It's your move, what do you want to do? Type '?' for options. dxe7
Making move : dxe7
R N x K Q B x R
p p x B p p p p
x x p x x x x x
x x x x x x x x
x x x p x x x x
x x x x x p x x
p p p x x x p R
R N B K Q B N x
AI thinking...
Traceback (most recent call last):
File "main.py", line 122, in
startGame(board, playerSide, opponentAI)
File "main.py", line 113, in startGame
move = ai.getBestMove()
File "/tmp/command-line-chess-master/AI.py", line 123, in getBestMove
moveTree = self.generateMoveTree()
File "/tmp/command-line-chess-master/AI.py", line 78, in generateMoveTree
self.populateNodeChildren(node)
File "/tmp/command-line-chess-master/AI.py", line 91, in populateNodeChildren
legalMoves = self.board.getAllMovesLegal(side)
File "/tmp/command-line-chess-master/Board.py", line 397, in getAllMovesLegal
if self.moveIsLegal(move) :
File "/tmp/command-line-chess-master/Board.py", line 388, in moveIsLegal
self.undoLastMove()
File "/tmp/command-line-chess-master/Board.py", line 89, in undoLastMove
self.pieces.remove(promotedPiece)
File "/tmp/command-line-chess-master/Piece.py", line 37, in eq
if self.board == other.board and self.side == other.side and self.position == other.position and self.class == other.class:
AttributeError: 'NoneType' object has no attribute 'board'
The code is untyped, what doesnn't cause problems, but type code would make it easier for people to work with the code.
(This is an feature what would be kinda cool if we provide something like an API in the future to make it more hackable)
Tasks which have to be done to accomplish this would be:
mypy
有沒有懂哥教一下
PGN (Portable Game Notation) https://en.wikipedia.org/wiki/Portable_Game_Notation
thanks
Tasks:
.pre-commit-config.yaml
with the following hooks:
pre-commit run --all-files
onceCONTRIBUTING.md
under Pull Request ProcessHooks that are listed can be discussed. When claiming this issue and you want to add additional hooks , please first comment these hooks here so they also can be discussed.
Was looking at the code i'm on a jupyter notebook though.
Could it be converted to it? ,
I've still not cracked the looking ahead for moves..
Though for your code.
There are not really tests in this repository which makes it a bit hard to ensure there are no bugs and/or unintentional behavior.
To fix this, unittests should be written.
When this is done, integration tests can be done too.
Right now there is only one (unnecessary) test.
All new tests should be created in a new directory called tests/
and because it is already in use, pytest
should be used as test-framework.
Hello, i am having problems installing this.
i tried pip3 install cl-chess
and i get the answer:
Could not find any downloads that satisfy the requirement cl-chess
Cleaning up...
No distributions at all found for cl-chess
do you know a solution to this?
thank you :-)
$ chess
What side would you like to play as [wB]? B
You will play as black
How deep should the AI look for moves?
Warning : values above 3 will be very slow. [2]? 3
8 R N B Q K B N R
7 ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
6 · · · · · · · ·
5 · · · · · · · ·
4 · · · · · · · ·
3 · · · · · · · ·
2 ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
1 R N B Q K B N R
a b c d e f g h
It's your move. Type '?' for options. ?
Here, I chose B (Black) for player's side. The AI should have made the first move as White. But it told me (the player) to make the first move - which is not possible, because the first move is always made by White.
will be great if:
Right now the CLI looks like this:
try:
if len(sys.argv) >= 2 and sys.argv[1] == "--two":
twoPlayerGame(board)
else:
playerSide = askForPlayerSide()
board.currentSide = playerSide
print()
aiDepth = askForDepthOfAI()
opponentAI = AI(board, not playerSide, aiDepth)
printBoard(board)
startGame(board, playerSide, opponentAI)
except KeyboardInterrupt:
sys.exit()
I think it would be a cool idea to switch to argparse.ArgumentParser
which would make it more readable and easier to add new features to it.
A few feature proposals:
If you want to propose other new features you would like to see, please leave a comment or create an issue.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.