0

I am trying to implement the knights tour problem on a 3x4 grid display. My grid is displayed as follows:

   A B C D
1: 1 - - -
2: - - - -
3: - - - -

The user starts on A1, which is [0][0] on the 2D array. How would I associate my user input with other positions on the grid. For example, if the user was to type A2 (I'm aware this isn't a valid knight move) - how would I let the program know this is position [0][1] on the array (I think)?

Any help would be much appreciated.

4
  • split it.A and 2.then A is 0 and 2 is 2-1=1 Commented May 3, 2016 at 13:03
  • Any idea how I could implement this in code? The letters A B C D are a char called 'file' and my number 1, 2 and 3 are an int called 'rank'. Commented May 3, 2016 at 13:05
  • you can use if else ,switch case to check a or b or ..etc. you can do it also using character code but if else should be fine.and can you share the codes Commented May 3, 2016 at 13:13
  • Thanks a lot for your help! Commented May 3, 2016 at 13:14

1 Answer 1

1

Let's say you have index i, j for 2DArray[i][j]: then you can use i = rank - 1, and j = file - 65 exploiting char autocasting to int and ASCII int values to obtain the correct 2D array position.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.