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 7180795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:25:24+00:00 2026-05-28T17:25:24+00:00

I have a 2D array that acts as a board for a chess game.

  • 0

I have a 2D array that acts as a board for a chess game. I expect user input to be in the Smith Notation. The way my array is set up is if the user says they want a piece to move to or from the 8th row (the top one from the user’s point of view), they are interacting with row[0] in the array. So to handle this I wrote a function that converts the user’s input into the correct row for the array. However, it seems a little clunky and I was wondering how programmers with more experience would solve this problem.

int convertToCorrectRow(int row)
{
    int newRow;
    switch (row) {
        case 1:
            newRow = 7;
            break;
        case 2:
            newRow = 6;
            break;
        case 3:
            newRow = 5;
            break;
        case 4:
            newRow = 4;
            break;
        case 5:
            newRow = 3;
            break;
        case 6:
            newRow = 2;
            break;
        case 7:
            newRow = 1;
            break;
        case 8:
            newRow = 0;
            break;            
        default:
            assert(false);
            break;
    }
    return newRow;
}

I did think of having flipping the array and displaying it in reverse to the user so that when the user interacts with row 8 they are actually interact with row[7] in the array and that would eliminate the need for this function. However, I would still like to know other ways to solve this problem.
Thanks in advance for your response.

  • 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-28T17:25:25+00:00Added an answer on May 28, 2026 at 5:25 pm

    It looks like this simplifies to:

    int convertToCorrectRow(int row) {
        assert(row > 0 && row <= 8);
        return 8 - row;
    }
    

    If row comes from user input without further validation, I wouldn’t use an assert, though.

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

Sidebar

Related Questions

I have a C array like: char byte_array[10]; And another one that acts as
I have some Javascript code that acts on an pixel array defined like so:
I have an array that contains a list of vertices which I copy to
I have an array that looks like: $fields = array( f1 => array(test), f2
I have an array that has keys and values. For eg: Array ( [name]
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
I have an array that is a member of a structure: $self->{myArray} = [value1,
I have a array that looks like this Array ( [provider] => Array (
I have an array that contains the RGB colour values for each pixel in
I have an array that I want to sort based on the value of

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.