Have an account? Sign in
Login  Register  Facebook
checkers with PHP
i have this code:
 function drawBoard(){
 global $cBoard;
      $R = "<img src=rp.gif>"; //Red piece
      $B = "<img src=bp.gif>"; //black piece
      $ES = "<img src=blank.gif>"; // legal square image
      $IS = "<img src=blank1.gif>"; //illegal square image

      $cBoard = array(
            array($IS, $R, $IS, $R, $IS, $R, $IS, $R),
            array($R, $IS, $R, $IS, $R, $IS, $R, $IS),
            array($IS, $R, $IS, $R, $IS, $R, $IS, $R),
            array($ES, $IS, $ES, $IS, $ES, $IS, $ES, $IS),
            array($IS, $ES, $IS, $ES, $IS, $ES, $IS, $ES),
            array($B, $IS, $B, $IS, $B, $IS, $B, $IS),
            array($IS, $B, $IS, $B, $IS, $B, $IS, $B),
            array($B, $IS, $B, $IS, $B, $IS, $B, $IS)
      );

      echo "<table border='3' width='200'>n";
      
      foreach ($cBoard as $row){
          switch($row){
              case "8": $row = 0; break;
              case "7": $row = 1; break;
              case "6": $row = 2; break;
              case "5": $row = 3; break;
              case "4": $row = 4; break;
              case "3": $row = 5; break;
              case "2": $row = 6; break;
              case "1": $row = 7; break;
          }
      echo "<tr>n";
          foreach ($row as $piece){
                echo "<td>";
                echo "$piece ";
                echo "</td>n";
                  switch($Piece){
                      case "A": $piece = 0; break;
                      case "B": $piece = 1; break;
                      case "C": $piece = 2; break;
                      case "D": $piece = 3; break;
                      case "E": $piece = 4; break;
                      case "F": $piece = 5; break;
                      case "G": $piece = 6; break;
                      case "H": $piece = 7; break;
                  }
          }
      }
      echo "</tr>n";
      echo "</table>n";
}
now im trying to parse a file into the array with color codes here is the position
A B C D E F G H
0 =>A0|B0|C0|D0|E0|F0|G0|H0
1 =>A1|B1|C1|D1|E1|F1|G1|H1
2 =>A2|B2|C2|D2|E2|F2|G2|H2
3 =>A3|B3|C3|D3|E3|F3|G3|H3
4 =>A4|B4|C4|D4|E4|F4|G4|H4
5 =>A5|B5|C5|D5|E5|F5|G5|H5
6 =>A6|B5|C6|D6|E6|F6|G6|H6
7 =>A7|B7|C7|D7|E7|F7|G7|H7
will the array i have up there work in sorting this out
Started: September 17, 2011 Latest Activity: September 17, 2011 php array switch
2 Answers
here is the position
A B C D E F G H
0 =>A0|B0|C0|D0|E0|F0|G0|H0
1 =>A1|B1|C1|D1|E1|F1|G1|H1
2 =>A2|B2|C2|D2|E2|F2|G2|H2
3 =>A3|B3|C3|D3|E3|F3|G3|H3
4 =>A4|B4|C4|D4|E4|F4|G4|H4
5 =>A5|B5|C5|D5|E5|F5|G5|H5
6 =>A6|B5|C6|D6|E6|F6|G6|H6
7 =>A7|B7|C7|D7|E7|F7|G7|H7

will the array i have up there work in sorting this out

Posted: hgabe
In: September 17, 2011

I still don't get what you're trying to do. It looks like you're just trying to display the starting position of a checkers game. Is that it?
September 17, 2011

yes that is exactly it
September 17, 2011

I am trying to display the starting position so i can then create the functions for movement and what pieces need to be taken out of the board
September 17, 2011

Do you have an example of the file?

Posted: MacOS
In: September 17, 2011

nope the formatted the file wrong and have to do it again it a file to save mt game state so i can move my piece and then load the other pieces as they were but the piece that moved stays were it was moved
September 17, 2011

@hgbso, is this for storing chess games?
September 17, 2011

for a checkers game
September 17, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer