Ad
  • Default User Avatar

    Thanks for the feedback. I was running your code to test it... maybe I made a mistake and forgot to compile and it was somebody else's code :) I'll check again when I've got a moment.

  • Default User Avatar

    Are you sure? b7 to a8 return 4.
    If begin OR end position is a corner point (A1,A8,H1,H8) AND BOTH row and col are 1 step, we've a minimum of 4 moves.
    This covers the moves A1-->B2; B2-->A1; H1-->G2; G2-->H1; A8-->B7; B7-->A8; H8-->G7; G7-->H8
    For all other 1-1 moves, you will not fall in the second IF case and it returns 2 moves.

    I play with the ASCII value: 'a' = 65, 'b' = 66... 'h' = 72; '1' = 49, '2' = 50,... '9' = 57
    It doesn't matter if we move from a to b or b to a as ABS(66-65) == ABS(65-66) == 1; same for the digits.

  • Default User Avatar

    Sorry to say, it fails on 4 tests:
    Fail: b7 to a8 - returned 2 should be 4
    Fail: b8 to a7 - returned 4 should be 2
    Fail: g7 to h8 - returned 2 should be 4
    Fail: g8 to h7 - returned 4 should be 2