[ prog / sol / mona ]

prog


Need programming help

1 2021-09-05 06:14

I'm trying to code a live chess game with no java script. My idea was to use php to handle most of the things js would usually, and have is update the sql data base. Is there any way i can just forego the sql data base and not have to us js, or is there anyway i can update the sql database using only php or html?

2 2021-09-05 07:18

Instead of a DB you can use plain files named after the games id and store the game state there as a json dump.
Turns are done via a post form, and players identified by their cookies.
After doing your turn you would have to refresh the site until it's your turn again, you need JS at least for that.
It would be easier with JS which periodically checks for game state changes and if it's your turn and updates the board.

3 2021-09-05 08:57

If it is a game against the computer you can just carry around the full state of the game, it's not that big.

4 2021-09-06 03:57

>>2
I would be perfectly fine for correspondence chess but quite impractical for a blitz game.

5 2021-09-07 12:37

>>2
Json is overkill, just store algebraic notation for each turn one per line. Then you can just have one parser that you use for both the UI and the save file.
>>1
I did this in C once. No you don't need JS, set the form submission URL to your "API" and when you get form data hold the socket open until the other player finishes their turn then send the updated chess board with a new form. Have them enter their moves in algebraic notation.

6 2021-09-08 10:59

>>5
What happens if the client disconnects? You can't call it back with HTTP.

7 2021-09-08 13:11

>>6
You'd notice (I had it send a "." every second so you knew it was still connected) and refresh and the server would ask what team you're on.
This way you can come back to games you're playing. I also wanted resume since it had a tty interface (it would check if argv[0] ended in "cgi" and present the html/tty interface accordingly.)

8


VIP:

do not edit these