PHP checkers game

Ok, I'm pretty good at php and I need some advice.

If I were to make a checkers game in php (probably using as well for data storage)
how would I go about making a checkers game.

I'm not talking about coding samples, just the concept as to determining legitimate moves and the format I would use to store piece locations and capturing pieces, etc.

As I said I don't need any code examples just the a sound structural idea which if I understand I can easily translate that to code.

Thanks a billion :)

Matthew Leverton

Are we to assume this is a multiplayer client-server program played within a web browser?



Two human players playing on the same pc, turn based.

Not to different computer (good question)

Matthew Leverton

Why use PHP at all? It sounds like all you need is some HTML and Javascript.


Just because those were the project specs.

But yea I was thinking javascript myself because of it
client-side capabilities

James Stanley

This sounds like you're asking for your homework to be done for you.


Nah not homework.

Actually I just got finished.
It was a job for someone. I was trying to get ideas, but I figured it out.

You can view it here

How it works is both players meet at that site and can play aganist each other
over the net. Ajax AND PHP/SQL

You can test it by opening up the link in two different browsers click on start game on both and pretend one window is red and the other is white, and play accordingly.

Yea I got the basic checkers javascript code online from here
I added the graphics the chat interface and I had to modified the code to
make it two players over the internet instead of two players on one computer.

Yeaa,I'm proud of myself on that one :)


I tried, but got this:

Warning: mysql_connect(): Access denied for user 'dimdigit'@'' (using password: YES) in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 2

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 3

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 6

Warning: mysql_query(): A link to the server could not be established in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 6

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 8

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 20

Warning: mysql_query(): A link to the server could not be established in /nfs/cust/4/68/37/573864/web/temp/checkers2.php on line 20
Error inserting table row
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 


That gives me a 404.


I lost connection as I was uploading

Try this one, should work :)

Type in some names and click start game, (open up link in two browsers or play with your friend on another computer


Seems to be some broken logic. I made two turns as player red, as shown in the attached screenshot. With the last state, a dialog box came up that said "There is a jump available", and now it won't let me do anything else but jump ... only where? :P

Also, I never made a move as player white, apparently the system didn't give a sh*t about my cheating attempt ;)



More like incomplete logic than broken.

I didn't put in all the limit testers and controls.

Good learning project, that was my second AJAX project. My first
is this

But I'll probably not be online to respond when you send a message to the link above.
Or I might, but mostly likely not.

Tobias Dammers

A checkers game that doesn't check all the rules of checkers isn't anywhere near 'finished'. It doesn't even really count as a checkers game.


Ever heard of the honor system, just dont cheat. Since if you do the computer wont tell on you or stop you from doing it.


J/K I"m just being silly. What can I say I get lazy at times

Tobias Dammers

Yeah, but then, why bother writing the game when you could just play checkers in MS Paint: draw a board, draw some pieces, mail crappy .bmp to opponent. There, I just coded my first checkers.

Wilson Saunders

As an intellectual exercise making a browser based checkers game seems like a fun idea. However I have my doubts as why anyone would give you money to make one. Especially one that does not enforce the rules of the game. I know a little about php and don't think is is a very good language for making some thing complex like checkers.

Flash's action script, which I am just starting to learn, seems more robust especially since it can listen for mouse events without having to swap screens. It also has a interval call back so you can have the program query the database every few seconds.

As for coding concepts for a multilayer program:
Since the internet is a vast place you will probably need some sort of match making service to connect two players and then make sure nobody else accidentally butts in on their game. Microsoft's internet gaming zone did this by having a lobby with 200 game tables. Each table had three states empty, one person waiting for a game, and two people in a game. This lobby could be represented by in a database table containing the following fields:

player1Name // some text so friends could identify each other.
player1UID // unique ID randomly generated at game start and stored in
// player's browser. The game will only accept moves from a player
// if the plaer UID matches the UID of the board.
player2Name // same description as player1
isPlayer1turn // boolean value where if false indcates player2's turn
boardState // could be a string where
// ' ' indicates an empty space,
// 'w' indicates unkinged white pieces,
// 'W' indicates kinged white pieces,
// 'b' indicates unkinged black pieces,
// 'B' indicates kinged black pieces,

If you insist on doing this in php you probably also need to remember which piece the user selected in a separate field so you know which piece to move on the user's second click. However Actions script can remember this for you so the database only needs to remember stuff that should be communicated to the other user.

Jonatan Hedborg

You would probably do the interface with Javascript, otherwise you would be in for a pretty horrible coding experience.

I'd say making it in flash is easier (the gui) in some aspects, and harder in some. It could not be made solely in flash for example, since flash can not connect to a database (unless you write a whole db interface using it's tcp/ip sockets... have fun with that ;) - and if it is possible you would have to store database passwords etc in a flash file, which is easily decompiled...). You would need a server-side layer (php or whatever) to process moves and return a correctly formated xml-file (or whatever you want to use for communicating). All logic would probably need to be on the server to prevent cheating...

Tobias Dammers

I know a little about php and don't think is is a very good language for making some thing complex like checkers.

PHP is just fine, if you can handle it. However, for a browser-based game, client-side script is essential in avoiding unnecessary round-trips, so some javascript knowledge is a must.
The general idea would be a database that stores player information and game states; a php script that enforces the rules (not only of the checkers game itself, but also determining who plays against who, how the "league" is organized, etc.); and a DHTML front-end, probably duplicating a lot of the rules enforcement (e.g. filtering out illegal moves before sending them to the server).

Thread #596770. Printed from