473,383 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

PHP and Chess

I am trying to display a position, on a chessboard, corresponding to a
sequence of moves recorded in a MySql database.
Any clue?
Michel
Jul 17 '05 #1
9 2910
"Michel" <Mi**************@wanadoo.fr> schrieb:
I am trying to display a position, on a chessboard, corresponding to a
sequence of moves recorded in a MySql database.


http://www.php.net/manual/en/function.imagecopy.php

Regards,
Matthias
Jul 17 '05 #2
I noticed that Message-ID: <bn**********@news-reader3.wanadoo.fr> from
Michel contained the following:
I am trying to display a position, on a chessboard, corresponding to a
sequence of moves recorded in a MySql database.
Any clue?


Not sure If I understand the question but here goes.

If you have images of the pieces and an 8 by 8 table
<?php

function display($image){
if(isset($image)){
$showpiece="<img src=\"$image\" alt=\"\">";}
else{
$showpiece="empty";}
return $showpiece;
}
//information from database
$img=array();
$img[1][1]="rook_black.jpg";
$img[1][3]="rook_white.jpg";
$img[1][6]="king_white.jpg";
//etc, etc
?>

<table border="1" cellspacing="0" cellpadding="0">
<tr align="center" valign="middle">
<td width="50" height="50"><?php echo display($img[1][1]);
?></td>
<td width="50" height="50"><?php echo
display($img[1][2]);?></td>
<td width="50" height="50"><?php echo
display($img[1][3]);?></td>
<td width="50" height="50"><?php echo
display($img[1][4]);?></td>
<td width="50" height="50"><?php echo display($img[1][5]);
?></td>
<td width="50" height="50"><?php echo display($img[1][6]);
?></td>
<td width="50" height="50"><?php echo
display($img[1][7]);?></td>
<td width="50" height="50"><?php echo display($img[1][8]);
?></td>

</tr>
// and so on for another 7 rows
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
Thanks for this, not sure it's what I'm looking for but interesting anyway
Jul 17 '05 #4
Hi Geoff

Ouaouh ! You did all that for me ! That sounds exactly what I'm looking for!
No time right now to work on it but I'll tell you as soon as I have made
some progerss
Meantime to get an idea of wht I'm working on 5 (for fun when I've some free
time) you can go there: http://mdevat.phpnet.org/echecs/seqmove.php
Also my main page is there http://perso.wanadoo.fr/mdv/ (click on Chess
image to get some interesting content (if you like chess...)
Michel
Jul 17 '05 #5
I noticed that Message-ID: <bn**********@news-reader2.wanadoo.fr> from
Michel contained the following:

Ouaouh ! You did all that for me ! That sounds exactly what I'm looking for!
No time right now to work on it but I'll tell you as soon as I have made
some progerss


It was an interesting problem. I'm just a beginner myself and find that
working on problems like this helps me learn. :-)

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
Geoff Berrow wrote:
I noticed that Message-ID: <bn**********@news-reader2.wanadoo.fr> from
Michel contained the following:
Ouaouh ! You did all that for me ! That sounds exactly what I'm looking for!
No time right now to work on it but I'll tell you as soon as I have made
some progerss


It was an interesting problem. I'm just a beginner myself and find that
working on problems like this helps me learn. :-)


You'll find that there a lot of people in here that do the same. In
fact, if I wasn't so busy, I'd have done the same. It's a very effective
way of learning different aspects of PHP and programming. (When it's
someone else's problem that is...) ;)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #7
An other thing: How to erase the content of a square (after a piece has left
this square) ?

with your example, I tried this:

$img[i][j]="" but then I get an x in the square (image not known)

I can also do something like:

//
<td width="40" bgcolor="#CDCFD3" align="center">
<?php
if ($img[3][1]!= "")
{
echo display($img[3][1]);
}
?>
<td width="40" bgcolor="#003399" align="center">
<?php
if ($img[3][2]!="")
{
echo display($img[3][2]);
}
?>
//

bit il looks very cumbersome (at least not elegant)

Michel


Jul 17 '05 #8
I noticed that Message-ID: <bo**********@news-reader1.wanadoo.fr> from
Michel contained the following:
An other thing: How to erase the content of a square (after a piece has left
this square) ?

with your example, I tried this:

$img[i][j]="" but then I get an x in the square (image not known)


It all depends on how you are storing the information about the moves.
In my example, I assumed that the information in the database would be
parsed in such a way as to returning all the information on where the
pieces were e.g,
$img=array();
$img[1][1]="rook_black.jpg";
$img[1][3]="rook_white.jpg";
$img[1][6]="king_white.jpg";
//etc, etc.

(It's possibly confusing to call this variable $img because it's really
a position corresponding to a square on the board.)

Then each square calls the function

<td width="50" height="50">
<?php echo display($img[1][1]); ?></td>
<td width="50" height="50">
<?php echo display($img[1][2]);?></td>
<td width="50" height="50">
<?php echo display($img[1][3]);?></td>

//etc. etc.

The function checks if the array position is set

function display($image){
if(isset($image)){

//if it is set, we display the chesspiece image

$showpiece="<img src=\"$image\" alt=\"\">";}
else{

//if it isn't set, we display the word 'empty'

$showpiece="empty";}
return $showpiece;
}
end of function.

If you just want blank square simply change this to
$showpiece="";

see www.ckdog.co.uk/php/test/chess.php (with more suitable images of
course)

To do any more on this I'll have to know how you are storing the moves
in the database.

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #9
In fact I retrieve 2 sequences of white and black moves from 2 (serialized)
fields of a row of a table, then I convert them (unserialize) into 2 arrays:
$tabwhite and $tablack
Note that these arrays do not contain all pieces positions but only a few
opening moves like:
$tabwhite[1][1] = "c2c4"
$tabwhite[1][2] = "Ng1f3"
$tabblack[1][1] = "Ng8f6"
$tabwhite[1][2] = "e7e6"

If I take first move (c2c4), I can find out that I must put a pawn in c4
i.e. $img[5][3]="pawn.gif" but I don't see how to remove this pawn from c2
That's why I tried with $img[7][3]="" but it does not work.
May be what you say now about $showpiece="" is the solution but I don't well
understand how it works.

Note that the link that you mentioned: www.ckdog.co.uk/php/test/chess.php
does not work, chess.php is not there...

Thanks again for your help



"Geoff Berrow" <bl******@ckdog.co.uk> a écrit dans le message de
news:di********************************@4ax.com...
I noticed that Message-ID: <bo**********@news-reader1.wanadoo.fr> from
Michel contained the following:
An other thing: How to erase the content of a square (after a piece has leftthis square) ?

with your example, I tried this:

$img[i][j]="" but then I get an x in the square (image not known)


It all depends on how you are storing the information about the moves.
In my example, I assumed that the information in the database would be
parsed in such a way as to returning all the information on where the
pieces were e.g,
$img=array();
$img[1][1]="rook_black.jpg";
$img[1][3]="rook_white.jpg";
$img[1][6]="king_white.jpg";
//etc, etc.

(It's possibly confusing to call this variable $img because it's really
a position corresponding to a square on the board.)

Then each square calls the function

<td width="50" height="50">
<?php echo display($img[1][1]); ?></td>
<td width="50" height="50">
<?php echo display($img[1][2]);?></td>
<td width="50" height="50">
<?php echo display($img[1][3]);?></td>

//etc. etc.

The function checks if the array position is set

function display($image){
if(isset($image)){

//if it is set, we display the chesspiece image

$showpiece="<img src=\"$image\" alt=\"\">";}
else{

//if it isn't set, we display the word 'empty'

$showpiece="empty";}
return $showpiece;
}
end of function.

If you just want blank square simply change this to
$showpiece="";

see www.ckdog.co.uk/php/test/chess.php (with more suitable images of
course)

To do any more on this I'll have to know how you are storing the moves
in the database.

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Will McGugan | last post by:
Hi folks, I've written a Python chess module that does the following. * Reads / Writes PGN files * Write FEN files * Validates moves * Lists legal moves * Detects check / mate / stalemate /...
5
by: derian | last post by:
Do you guys know if there is a program that can generate chess moves? I recently wrote a chess game but its only 2 player... I deceided it was too difficult to come up with the logic for the AI...
11
by: Gregc. | last post by:
G'day I am writing a chess program. Here is my code: #include <stdio.h> #include <stdlib.h> bool isInCheck (int krow, int kcol, int qrow, int qcol) { double check;
5
by: Paolo Pantaleo | last post by:
Well Python is not a good language for writing a chess engine (even if a chess engine exists: http://www.kolumbus.fi/jyrki.alakuijala/pychess.html), but it could be grat for chess interfaces, for...
1
by: Varun Hiremath | last post by:
Hello, I have written a chess client using python which is a graphic interface to play chess. It is at present a two player version, players move their peices by clicking two squares on the board...
13
by: asif929 | last post by:
I have been trying to create this chess program from many hours and still couldn't figure out how to complete it. After consume all these efforts i come to this google groups for the first time for...
63
by: biyubi | last post by:
Hi, a year ago I won the 2005 Best Game categoryof the International Obfuscated C Code Contestwith a chess program. http://www.ioccc.org/whowon2005.html...
2
by: CoreyWhite | last post by:
When playing games, perhaps the most simple is tic-tac-toe. The game has two simple strategies, one is defensive and the other offensive. It is not hard at first to learn how to tie games when...
10
by: sam_cit | last post by:
Hi Everyone, I'm working on developing a chess game and i decided to use c++ for its object oriented approach. I have a bass class unit and is inherited to distinct number of units (like king,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.