Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » PHP checkers game

This thread is locked; no one can reply to it. rss feed Print
PHP checkers game
superstar4410
Member #926
January 2001
avatar

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 :)

Don't take yourself too seriously, but do take your responsibilities very seriously.

Matthew Leverton
Supreme Loser
January 1999
avatar

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

superstar4410
Member #926
January 2001
avatar

Yes

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

Not to different computer (good question)

Don't take yourself too seriously, but do take your responsibilities very seriously.

Matthew Leverton
Supreme Loser
January 1999
avatar

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

superstar4410
Member #926
January 2001
avatar

Just because those were the project specs.

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

Don't take yourself too seriously, but do take your responsibilities very seriously.

James Stanley
Member #7,275
May 2006
avatar

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

superstar4410
Member #926
January 2001
avatar

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 http://www.dimdigital.com/temp/checkers2.php

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
http://us.geocities.com/blurglecruncheon/projects/checkers.htm
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 :)

Don't take yourself too seriously, but do take your responsibilities very seriously.

LennyLen
Member #5,313
December 2004
avatar

I tried, but got this:

Warning: mysql_connect(): Access denied for user 'dimdigit'@'web.ahp01.lax.affinity.com' (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) 

superstar4410
Member #926
January 2001
avatar

Don't take yourself too seriously, but do take your responsibilities very seriously.

LennyLen
Member #5,313
December 2004
avatar

That gives me a 404.

superstar4410
Member #926
January 2001
avatar

I lost connection as I was uploading

Try this one, should work :)

http://www.dimdigital.com/checkers/checkers2.php

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

Don't take yourself too seriously, but do take your responsibilities very seriously.

Indeterminatus
Member #737
November 2000
avatar

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 ;)

{"name":"595752","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/9\/b92262480ca485fd678ace3f20ea5ad3.png","w":287,"h":269,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/9\/b92262480ca485fd678ace3f20ea5ad3"}595752

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

superstar4410
Member #926
January 2001
avatar

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

http://www.dimdigital.com/chat.php

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.

Don't take yourself too seriously, but do take your responsibilities very seriously.

Tobias Dammers
Member #2,604
August 2002
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

superstar4410
Member #926
January 2001
avatar

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.

LOooLLL ;D

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

Don't take yourself too seriously, but do take your responsibilities very seriously.

Tobias Dammers
Member #2,604
August 2002
avatar

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.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Wilson Saunders
Member #5,872
May 2005
avatar

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
player2UID
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.

________________________________________________
Play my games at http://monkeydev.com

Jonatan Hedborg
Member #4,886
July 2004
avatar

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
Member #2,604
August 2002
avatar

Quote:

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).

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: