3 kyu

Knight's Attack!

99 of 102rsdah13

Description:

Time to train your knights...

Considere an infinite chessboard... With obstacles on it... You're provided with a start point and an end point (as tuples (x,y)), and a tuple of all coordinates that are blocked by obstacles. Your goal is to find the number of minimal moves required to reach the destination, coming from the start.
If the destination isn't reachable, return None/nil.


DETAILS

  • A knight moves in an "L" shape: two positions in one direction, then one position in a perpendicular direction.
  • Be extremly careful about performances, there are some strict contraints to match (see below)
  • It may rarely happen that the random generator fails to generate starting or ending positions. If it happens, you'll get an error message about that. Just try again, and you should be fine.

Performances requirements

  • Your code will be tested in different situations and should be as fast as possible.
  • Moreover, its performances should be independant of the direction it searches in (meaning, they should stay the same when exchanging start and destination).
  • Your code will be compared to the reference implementation and you'll have to be at most 3 to 6 times slower in the timed tests (the actual factor value depends on the kind of test).



You are provided with 2 functions (in the preloaded section) to be able to display some inputs if needed (it's already done in the fixed tests):

def display(start, dest, obst, limit=((0,20),(0,20))):
    """ Display function... (how surprizing!)
          start: start
          dest:  destination
          obst:  data about obstacles
          limit: area of the chessboard that will be printed, as ((xmin,xmax),(ymin,ymax))
                (note: axis are like indexing: x>0 is vertical descendant, 
                                               y>0 is horizontal going right)
          return: None
    """  

def data_builder(s,print_it=True):
    """ Convert a string representation of a chessboard to the set of 
        corresponding inputs for your "attack" function
          s:       string representation of the board
          printIt: display the input
          return:  start, dest, obst
    """
# Display function... (how surprizing!)
#    start: start
#    dest:  destination
#    obst:  data about obstacles
#    limit: area of the chessboard that will be printed, as ((xmin,xmax),(ymin,ymax))
#          (note: axis are like indexing: x>0 is vertical descendant, 
#                                         y>0 is horizontal going right)
#    return: nil
def display(s,e,o,xi=0,xf=20,yi=0,yf=20) ... end

# Convert a string representation of a chessboard to the set of 
# corresponding inputs for your "attack" function
#    s:       string representation of the board
#    printIt: display the input
#    return:  [start, dest, obst]
def data_builder(s,print_it=true) ... end
Algorithms
Graph Theory

More By Author:

Check out these other kata created by rsdah13

Stats:

CreatedApr 7, 2017
PublishedApr 7, 2017
Warriors Trained1694
Total Skips526
Total Code Submissions3957
Total Times Completed102
Python Completions99
Ruby Completions5
Total Stars104
% of votes with a positive feedback rating83% of 41
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes2
Total Rank Assessments6
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • rsdah13 Avatar
  • Blind4Basics Avatar
Ad