Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3361024
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:05:18+00:00 2026-05-18T03:05:18+00:00

I already have the pieces mapped out in the array and it prints just

  • 0

I already have the pieces mapped out in the array and it prints just fine

    $board = array(
             array('1','rs','1','rs','1','rs','1','rs'),
             array('rs','1','rs','1','rs','1','rs','1'),
             array('1','rs','1','rs','1','rs','1','rs'),
             array('rs','bs','rs','bs','rs','bs','rs','bs'),
             array('bs','rs','bs','rs','bs','rs','bs','rs'),
             array('2','bs','2','bs','2','bs','2','bs'),
             array('bs','2','bs','2','bs','2','bs','2'),
             array('2','bs','2','bs','2','bs','2','bs')
              );

1 = black pieces
2 = red pieces
rs = red square
bs = black square

this code parse the input of a player : example FROM F2 into (0,0) coordinates

function parseSquareFrom($square) {
    if (strlen($square) != 2) {
        return FALSE;
    }

    $coords = array(ord('A') - ord($square[0]), $square[1] - 1);

    // Perform bounds-checking.
    if ($coords[0] < 0 || $coords[0] > 7 || $coords[1] < 0 || $coords[1] > 7) {
        return FALSE;
    }

    return $coords;
}

I have repeated the same function for the TO input ( to where the player wants to move the piece

my question is this next code a valid way to move with the functions above

    $board[$coords1[0]-1][$coords1[1]+1] = $board[$coords[0]][$coords[1]];
    $board[$coords[0]][$coords[1]] = 0;

    //eating action
    $board[$coords1[0]][$coords1[1]] = 0;
    $board[$coords1[0]-2][$coords1[1]+2] = $board[$coords[0]][$coords[1]];

$way = ($_POST['way'] === 'up')? 1:-1;

$way = ($_POST['way'] === 'down')? -1:+1;



    //if player is 'up' then the value of $way is 1 so
      $board[$x+(-1*$way)][$y+(1*$way)] = $board[$coords[0]][$coords[1]]; // position 2,2 becomes 1,3
   //if player is not 'up' then the value of $way is -1 so
      $board[$x+(-1*$way)][$y+(1*$way)] = $board[$coords[0]][$coords[1]]; // position 2,2 becomes 3,1

I plan to have a function to update the tile movements in the screen so the piece moves as the it highlights the piece as is moving to the next square

this is using serialize into file to hold start positions, movements, kings and queens positions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:05:18+00:00Added an answer on May 18, 2026 at 3:05 am

    I’m going to assume that $coords is a $_POST variable like a suggested on the first part of this question. If that’s the case, the first part of your code is correct:

    $board[$coords1[0]-1][$coords1[1]+1] = $board[$coords[0]][$coords[1]];
    $board[$coords[0]][$coords[1]] = 0;
    

    This moves a piece diagonally one step up-right in the board.
    The second part on the other hand skips the actual ‘eating’ action. Unless, the location specified by the user is the one where the enemy piece is. In which case you code would work.


    As for the bound-checking you do, you’re not being bullet-proof since adding 2 in the eating move, while a piece is next to a border would result in your code trying to place the piece out of the board. So you could check bounds, depending on the move, so if the move is a standard diagonal one, you should check that the ending position is within the limits, not the starting one since you are assuming that piece is in a correct position before.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of Javascript and it just won't work. I allready checked
I have already googled for this I have a Table with following structure in
I already have a deploy.rb that can deploy my app on my production server.
We already have things like static analysis that tells us what's wrong with our
I want to assign a resource I already have a second name, similar to
What alternatives are there to GAE, given that I already have a good bit
Can anyone recommend monitoring software for a windows environment? We already have monitoring in
For statistical reasons, I want an extensive analysis from a dataset. I already have
I have already posted something similar here but I would like to ask the
I have already tried PreRenderComplete and unload is too late

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.