Skip to content

abdalrahmanshaban0/ChessOverSockets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChessOverSockets

image

image

image_2024-05-12_22-37-31

1. Wanna play?

  1. Invite a friend using his IP and port number
    (shoud be open and the friend accept your invitation)
  2. Listen to a friend (bind socket to an interface with IP, specify a port number)
    (Who listens will play first with white color)
  3. History (Not implemented yet)
    (view past mathches results)
    option: play the match

2. Init pieces and board

There are 2x16 pieces on the board, init there types and locations

3. Check status of the game

In the start of each play check the king status:

  • other player lose?

    • I win and break
  • Other player draw?

    • I draw and break
  • try for each of your pieces every available move
    and check if the king will be safe or not.

    • King is not safe?
      • A move found to disable check ?
        • YES ? -> checkmate
        • NO ? -> send lose and break
    • king is safe?
      • Any valid move found?
        • YES ? -> good
        • NO ? -> send draw (stalemate) and break

4. Is it my turn?

  • YES? do(A)
  • NO? do (B)

(A) Make a move
How to check a move if it's valid?

  1. Not out of bound of the chess board.
  2. Not an empty spot.
  3. Not moving enemy's piece
  4. Castling
    • valid ?
      • do castling and update board
    • not valid ?
      • print "not valid"
  5. Not attacking allied piece.
  6. Valid piece range

valid ?

  • try to make the move
  • is king safe ?
    • No ?
      • roll back the move and print "not valid"
      • goto(4)
    • Yes ?
      • update the board with the valid move, send the move and change the turn.
      • goto(3)

(B) recive other player's reply
recive move

  • move is -1 ?
    • other player lose (I win)
  • move is -2 ?
    • other player draw (I draw)
  • else
    • update the board and change the turn
    • goto(3)

History feature (not implemented yet)

How to contribute:

  1. This game doesn't detect all draw cases (just stalemate)
    Any PR handling a game draw case will be reviewed and accepted
  2. Any special moves (rather than pawn promotion and castling)
    -Any Chess rules not coverd-
    inclue the rule reference in your PR

Possible comming features (Not accepting PRs):

  • History
  • GUI
  • chat (Threading)
  • Timer (Threading)
  • Chess agent (API)
  • Chess engine (AI)

About

Simple 2 player Chess console game connecting over sockets.

Topics

Resources

License

Stars

Watchers

Forks