Skip to content

notowen333/Python-Chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Chess

Chess built out in python to be played in the terminal. Eventually a chess AI will be added. If I find the time ;) :O

This Chess game uses long-form algebraic chess notation (So you say e2-e4, instead of e4, or you say Kb1xc3 to say knight takes on c3).

Right now, it's missing en-passant, insufficient material checks, and 50 king move stalemates.

The structure of the code is Object Oriented. Each piece is an object that has a str method, a color, and a position. The board is an object that has a list of white pieces, a list of black pieces, most of the gameplay methods, and a str method. The board is re-rendered after each move using the str method to show all of the pieces which remain.

To show the background of the board, I use the colorama python library, and I use unicode characters to display the pieces.

I have a test_chess file which contains unit tests.

Before each move, all possible moves are generated and displayed. This includes double moves for pawns, kingside and queenside castles, checks to make sure a piece is not pinned, and captures. I check for illegal moves by creating a hypothetical board and checking to see if a player is in check.

After a move is played, the game checks for stalemates where a player has no available moves and for repitition stalemates by hashing the board and checking if any hash points to a value of 3. Then the game auto-queens any pawns in the their respective final row.

Of course, the game ends with checkmate when a player is in check and has no available moves.

Gameplay Images:

Gameplay Gameplay

Scholar's Mate Checkmate

Pawn Promotion Promote

Stalemate Stale

About

Chess built out in python to be played on the terminal.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages