Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ notes.txt
res/stockfish/build/stockfish.exe
res/stockfish/path.txt
res/savedGames/game*.txt
res/log_game/*
58 changes: 58 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"files.associations": {
"ratio": "cpp",
"iosfwd": "cpp",
"*.tcc": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"typeinfo": "cpp"
}
}
105 changes: 0 additions & 105 deletions CHANGELOG.md

This file was deleted.

21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

39 changes: 6 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Important Note

This project is not being maintained actively at the moment. I had started this
project back when I was still new to Python and pygame. While I enjoyed and
learnt a lot when I worked on this project, looking back at the codebase now
after over 2 years, I can't help but notice how bad the codebase is.
Please do not use this project as a base for any of your projects or for learning
python and/or pygame. There are many resources out there that are much better
than this project.

If I ever return to this project, it would mean doing full re-write of the
entire codebase, with the current codebase being archived in a 'legacy' branch.
The project still has some unfinished features, which will be added later.

## My-PyChess

Expand All @@ -25,12 +16,11 @@ Any bug-reports, suggestions or questions, you can leave it in the github issues
The My-PyChess project is available under MIT License. The MIT Licence applies to all the resources I have created in this project. This includes all the python files and text files. But some resources(images, sounds and font file) are not created by me, I have downloaded these from the internet. I have given credits to the authors of these resources in [this file](res/CREDITS.txt). All these resources maintain the original licenses that the authors have leased them under (These licenses permit my use of the respective resources in this project).

### Getting started

- `pip3 install -r requirement.txt`
- Make sure you have Python and `pygame` installed and working.
- Clone this repository (or download zip file and extract it).
- Then, run the `pychess.py` file. Trying to run any other file will not run the game.

There is also a [lite implementation](https://github.com/ankith26/My-PyChess-lite/) of My-PyChess, that focuses just on chess programming - free from all the code for menus, singleplayer, online etc.
- Run server if play online: `g++ server.cpp -o server && ./server`

### Features

Expand All @@ -40,30 +30,13 @@ There is also a [lite implementation](https://github.com/ankith26/My-PyChess-lit
- Supports things like castling, pawn promotion, enpassent etc.
- Supports saving and loading games.
- Has single player mode with two different types, levels and ability to play against the stockfish chess engine.
- Has online gamemode, play chess with anyone in the world.
- Has online gamemode, play chess with anyone in the world using login/ logout.
- Has a chess game timer.
- Has a preference menu where you can customize the app to meet your preferences.
- Has a chess howto, about menu and stockfish install/configure menu to make things easy for users.
- Use the Elo scoring mechanism according to world standards.
- There is a feature to find opponents based on elo point difference

## What's new in this Version 3.2
- Added a Back-Button, to go back to the previous menu. In older versions, the quit button was used for this purpose, but from now on a dedicated button to go back is there in the top-right corner. The quit button will now be used only to exit the app.
- Added a game timer to multiplayer mode, with a new menu to setup the timer.
- Fixed bugs and made many additions and improvements to the client-server in chess online gamemode.
- Made optimisations to core chess module and gui module.
- Added a chess hotwto.
- Minor improvements to game sounds and textbox.
- Upgraded preference menu and made the loadgame interface more robust.
- Several other minor changes and improvements made.

## Highlights of v3.x, the latest major release.
- The code was revamped and restructured, fixed bugs and made **major performance improvements**.
- **Online play** was added. This features a online lobby and support upto 10 people to play chess.
- Singleplayer saw big upgrades: Firstly, a decent **python chess engine** that playes chess was added.
- You can play against **stockfish chess engine** (see https://stockfishchess.org). My-PyChess will act as an interface to give you this singleplayer mode.
- En-Passant in chess, undo move, screenflip and sounds were added.
- Lots of changes made to GUI.

Click [here](CHANGELOG.md) to see full changelog.

### Online Gameplay

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

4 changes: 4 additions & 0 deletions account.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
hoan 1234 1
ky 1234 1
h 1 1
a 1 1
38 changes: 38 additions & 0 deletions chess/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,41 @@ def showScreen(win, side, board, flags, pos, load, player=None, online=False):

if not multi:
pygame.display.update()
def showScreen_view(win, side, board, flags, pos, player=None, online=False):
multi = False
if player is None:
multi = True
player = side
flip = False

drawBoard(win)
win.blit(BACK, (460, 0))

if not multi:
win.blit(CHESS.TURN[int(side == player)], (10, 460))

if not online:
win.blit(CHESS.SAVE, (350, 462))

if isEnd(side, board, flags):
if isChecked(side, board):
win.blit(CHESS.CHECKMATE, (100, 12))
win.blit(CHESS.LOST, (320, 12))
win.blit(CHESS.PIECES[side]["k"], (270, 0))
else:
win.blit(CHESS.STALEMATE, (160, 12))
else:
if online:
win.blit(CHESS.DRAW, (10, 12))
win.blit(CHESS.RESIGN, (400, 462))

if isChecked(side, board):
win.blit(CHESS.CHECK, (200, 12))
if isOccupied(side, board, pos) and side == player:
x = (9 - pos[0]) * 50 if flip else pos[0] * 50
y = (9 - pos[1]) * 50 if flip else pos[1] * 50
pygame.draw.rect(win, (255, 255, 0), (x, y, 50, 50))
drawPieces(win, board, flip)

if not multi:
pygame.display.update()
14 changes: 10 additions & 4 deletions chess/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def legalMoves(side, board, flags):

# This function returns wether a game has ended or not
def isEnd(side, board, flags):
for _ in legalMoves(side, board, flags):
return False
return True
# Check if the king of the given side is present in the board
king_present = any(piece[2] == "k" for piece in board[side])

# If the king is not present, the game has ended
return not king_present

# This function moves the piece from one coordinate to other while handling the
# capture of enemy, pawn promotion and en-passent.
Expand Down Expand Up @@ -80,7 +82,8 @@ def move(side, board, fro, to, promote="p"):

# This function returns wether a move puts ones own king at check
def moveTest(side, board, fro, to):
return not isChecked(side, move(side, copy(board), fro, to))
# return not isChecked(side, move(side, copy(board), fro, to))
return True

# This function returns wether a move is valid or not
def isValidMove(side, board, flags, fro, to):
Expand All @@ -94,6 +97,9 @@ def isValidMove(side, board, flags, fro, to):
def makeMove(side, board, fro, to, flags, promote="q"):
newboard = move(side, copy(board), fro, to, promote)
newflags = updateFlags(side, newboard, fro, to, flags)
if isEnd(side, newboard, newflags):
print("Game Over! The king has been captured.")
# You might want to handle the end of the game here
return not side, newboard, newflags

# Does a routine check to update all the flags required for castling and
Expand Down
2 changes: 1 addition & 1 deletion chess/lib/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def prompt(win, msg=None):
# optimising images for display - call only once per game
def start(win, load):
convertPieces(win)
sound.play_start(load)
# sound.play_start(load)
clk = pygame.time.Clock()
for i in range(101):
clk.tick_busy_loop(140)
Expand Down
Loading