PHP and Chess

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michel

    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


  • Matthias Esken

    #2
    Re: PHP and Chess

    "Michel" <MicheldeVathai re@wanadoo.fr> schrieb:
    [color=blue]
    > I am trying to display a position, on a chessboard, corresponding to a
    > sequence of moves recorded in a MySql database.[/color]



    Regards,
    Matthias

    Comment

    • Geoff Berrow

      #3
      Re: PHP and Chess

      I noticed that Message-ID: <bnpag4$ssq$1@n ews-reader3.wanadoo .fr> from
      Michel contained the following:
      [color=blue]
      >I am trying to display a position, on a chessboard, corresponding to a
      >sequence of moves recorded in a MySql database.
      >Any clue?[/color]

      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="<im g src=\"$image\" alt=\"\">";}
      else{
      $showpiece="emp ty";}
      return $showpiece;
      }
      //information from database
      $img=array();
      $img[1][1]="rook_black.jp g";
      $img[1][3]="rook_white.jp g";
      $img[1][6]="king_white.jp g";
      //etc, etc
      ?>

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

      Comment

      • Michel

        #4
        Re: PHP and Chess

        Thanks for this, not sure it's what I'm looking for but interesting anyway


        Comment

        • Michel

          #5
          Re: PHP and Chess

          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


          Comment

          • Geoff Berrow

            #6
            Re: PHP and Chess

            I noticed that Message-ID: <bnrrak$kef$1@n ews-reader2.wanadoo .fr> from
            Michel contained the following:
            [color=blue]
            >
            >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[/color]

            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/

            Comment

            • Justin Koivisto

              #7
              Re: PHP and Chess

              Geoff Berrow wrote:[color=blue]
              > I noticed that Message-ID: <bnrrak$kef$1@n ews-reader2.wanadoo .fr> from
              > Michel contained the following:
              >[color=green]
              >>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[/color]
              >
              > It was an interesting problem. I'm just a beginner myself and find that
              > working on problems like this helps me learn. :-)[/color]

              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 - spam@koivi.com
              PHP POSTERS: Please use comp.lang.php for PHP related questions,
              alt.php* groups are not recommended.

              Comment

              • Michel

                #8
                Re: PHP and Chess

                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="#CDCFD 3" align="center">
                <?php
                if ($img[3][1]!= "")
                {
                echo display($img[3][1]);
                }
                ?>
                <td width="40" bgcolor="#00339 9" align="center">
                <?php
                if ($img[3][2]!="")
                {
                echo display($img[3][2]);
                }
                ?>
                //

                bit il looks very cumbersome (at least not elegant)

                Michel




                Comment

                • Geoff Berrow

                  #9
                  Re: PHP and Chess

                  I noticed that Message-ID: <bo3m1t$v5c$1@n ews-reader1.wanadoo .fr> from
                  Michel contained the following:
                  [color=blue]
                  >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)[/color]

                  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.jp g";
                  $img[1][3]="rook_white.jp g";
                  $img[1][6]="king_white.jp g";
                  //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="<im g src=\"$image\" alt=\"\">";}
                  else{

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

                  $showpiece="emp ty";}
                  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/

                  Comment

                  • Michel

                    #10
                    Re: PHP and Chess

                    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" <blthecat@ckdog .co.uk> a écrit dans le message de
                    news:di4bqvc6c0 lb2u60amvov6m9e v5e008caa@4ax.c om...[color=blue]
                    > I noticed that Message-ID: <bo3m1t$v5c$1@n ews-reader1.wanadoo .fr> from
                    > Michel contained the following:
                    >[color=green]
                    > >An other thing: How to erase the content of a square (after a piece has[/color][/color]
                    left[color=blue][color=green]
                    > >this square) ?
                    > >
                    > >with your example, I tried this:
                    > >
                    > >$img[i][j]="" but then I get an x in the square (image not known)[/color]
                    >
                    > 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.jp g";
                    > $img[1][3]="rook_white.jp g";
                    > $img[1][6]="king_white.jp g";
                    > //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="<im g src=\"$image\" alt=\"\">";}
                    > else{
                    >
                    > //if it isn't set, we display the word 'empty'
                    >
                    > $showpiece="emp ty";}
                    > 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/[/color]


                    Comment

                    Working...