Please help me to make my chess application with Java client-server

Sort:
ZanyZombie22

I'm trying to make a chess application with java swing and tcp socket for my school project. But I still have some problems. Please help me out.

1. Should I put the clock for each player on server side or client side?

2. What is effective way to detect a checkmate? I can detect a check by checking all the square on the king's column, row, etc. But I dont think this way can detect a checkmate.

3. One again, where shoud i put the checkmate detector? If a player clicks on a piece, the client side will find all legal moves and display it. Shoud I put the checkmate detector somewhere here?

Sorry for my bad english.

Eyal282
quangbuichess wrote:

I'm trying to make a chess application with java swing and tcp socket for my school project. But I still have some problems. Please help me out.

1. Should I put the clock for each player on server side or client side?

2. What is effective way to detect a checkmate? I can detect a check by checking all the square on the king's column, row, etc. But I dont think this way can detect a checkmate.

3. One again, where shoud i put the checkmate detector? If a player clicks on a piece, the client side will find all legal moves and display it. Shoud I put the checkmate detector somewhere here?

Sorry for my bad english.

 

Only way to detect checkmate in a program is if you simulated every move, concluded none are legal & the king is in check.

 

You run this once per move, and it detects checkmate and stalemate ( if the king is not in check and no legal moves then stale )

WhiteDrake

1. Put the clock on the server. The client should only tell the player about the information received from the server. Otherwise, each client would soon display a different time. Imagine that client1 is on a slow network and needs 2 seconds to send a move onto the sever (and perhaps another 2 seconds to receive the reply) and client2 is on a fast network and needs only 0.02 seconds to send or receive data to/from the server - without the server taking care of the clock, each client would think that the opponent is responsible for the lag and subtract it from their time.

2. There 2 good ways to determine a checkmate:

2a) Each piece "remebers" all the squares that it attacks. After each move, this information is updated. This has the benefit that it's easier to update the information after each move; the downside is that determining a checkmate is harder.

2b) Each square "remembers" all the pieces that attacks it. After each move, this information is updated. Now it's super easy to determine a checkmate (the square with a king is attacked by a piece of the opponent and all the adjacent squares are occupied by pieces of the same colour or attacked by the opponent's pieces) but updating the information may need a bit more work.

Whichever of these methods you choose, you can also determine a stalemate similarly.

3. The checkmate detector should be put on the server, too. If a checkmate is delivered, the server announces to both clients that the game ended. 

WhiteDrake

You will need to create a simple network protocol for communication between the server and the clients. Consider the following game is played:

1. e4 e5 2. Ke2 Ke7 3. Ke1 Ke8 4. Ke2 Ke7 5. Ke1 Ke8 6. Ke2 Ke7 (draw by threefold repetition)

Assume we have 3 applications to play the game (they may be on the same machine or on different machines) - Server, ClientW and ClientB. The communication might look similarly to the following:

ClientW -> Server: 1. e4

Server -> ClientW: Accepted. White's remaining time is 59 seconds.

Server -> ClientB: 1. e4. White's remaining time is 59 seconds.

ClientB -> Server: 1. ... e5

Server -> ClientB: Accepted. Black's remaining time is 57 seconds.

Server -> ClientW: 1. ... e5. Black's remaining time is 57 seconds.

...

ClientB -> Server: 6. ... Ke7

Server -> ClientB: Accepted. Black's remaining time is 52 seconds. Draw by threefold repetition.

Server -> ClientW: 6. ... Ke7. Black's remaining time is 52 seconds. Draw by threefold repetition.


Off course, the communication protocol does not need to be so verbose. The last 3 messages could, for example, be sent as follows:

ClientB -> Server: Ke7

Server -> ClientB: OK 52s =3fr

Server -> ClientW: Ke7 52s =3fr

ZanyZombie22

Thank you guys for helpful answers. I haven't finished the checkmate detector yet but now everything is clearer and going well.