I'm contemplating attempting a PHP chess board.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

I'm contemplating attempting a PHP chess board.

Post by impulse() »

How difficult do you all believe this to be? It wouldn't contain any images as I've never touched image manipulation, but I think an ASCII chess board would work with 2 text boxes (coordinates), 1 dropdown (piece) and a submit button.


I'm thinking at the moment it would work best with 64 functions, one for each square on the board, which are run on every move where move legality is calculated or attack is compared.


In my head at the moment it seems like it's going to be a doddle. Has anybody else attempted PHP chess before and could they tell me if it's a hard game to write.


Regards,
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

making it is not very difficult. There are a million chess algorithms out there to help you on your way. it's all up to you.

-Jon
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I'm hoping to create it from a blank document. I like writing as much as I can myself as long as it doesn't take forever. And I'd say I'm a beginner/intermediate at PHP so I like a good challenge that makes me think of lots of ways to get around situations so I can try unfamiliar things on the way.

If I manage to finish it you will see it appear in the coding critique in the next few days :)
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I'd put it together using PHP with JavaScript, and allow the pieces to be draggable. Every time a piece is moved (not just clicked, but moved), it'd trigger a form submission at which point PHP would handle the rest (whether it's a valid move, storing the movement, making attacks, etc.).
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Validation of chess moves is harder than it first looks. Finding out whether a player is in check, or checkmate, or stalemate is even harder still. Fortunately it's a problem lots of people have tackled before, so there's plenty of information out there. For most moves you can use a "bit board" idea ... a bit board is a 64 bit int where the 1s and 0s in the number represent a square each. You can validate moves by using bit operations to check if a move is valid. It's very clever, and it's how most modern chess applications work.

http://www.fzibi.com/cchess/bitboards.htm
Post Reply