A knight fill is a flood fill using the connectivity of the knight chess piece. Specifically:
1 1
1 1
0
1 1
1 1
(0 is the initial point, 1s show the connected cells)
Challenge
Given a 2D grid of spaces and walls, and an initial location, perform a knight-fill on the grid. Shortest code wins.
Rules
You may take input and produce output in any format you like (image, string, array, whatever). You may take the initial location as part of the input grid or as a separate coordinate. For the purpose of this explanation, the following format will be used:
######## # = wall ######## x = initial location ## x ## ## ## ######## ## ## ######## ########
Output is a copy of the input grid with the knight-fill result added
Your fill must not be in the same "colour" as the space or walls, but can be the same as the initial location marker. For example given the image above, a valid output would be:
######## # = wall ######## @ = fill (could also have been x) ## @ @## ## @ @## ######## ##@ @ ## ######## ########
You may assume that the input grid will always contain a 2-cell wall on all sides
- You may assume that the initial location will never be inside a wall
- You may assume that the grid will never be larger than 1000x1000
- Builtins are fine
- Shortest code (in bytes) wins
Test Cases
In all test cases, #
denotes a wall, denotes empty space, and
x
denotes the initial location of the fill. @
denotes the output fill.
Input 1:
########
########
## x ##
## ##
########
## ##
########
########
Output 1:
########
########
## @ @##
## @ @##
########
##@ @ ##
########
########
Input 2:
############
############
## ## x##
## ## ##
##### ##
## ##
############
############
Output 2:
############
############
## ##@@@@@##
##@##@@@@@##
#####@@@@@##
## @@@@@@@##
############
############
Input 3:
####################
####################
## ## ##
## ## ##
## ## ######## ##
## ## ######## ##
## ## ## ## ##
## ## ## ## ##
## ## ## ## ##
## ## ## ## ##
## ## ######## ##
## ## ######## ##
## ## ## ##
## ## x## ##
## ############ ##
## ############ ##
## ##
## ##
####################
####################
Output 3:
####################
####################
##@@##@@@@@@@@@@@@##
##@@##@@@@@@@@@@@@##
##@@##@@########@@##
##@@##@@########@@##
##@@##@@## ##@@##
##@@##@@## ##@@##
##@@##@@## ##@@##
##@@##@@## ##@@##
##@@##@@########@@##
##@@##@@########@@##
##@@##@@@@@@@@##@@##
##@@##@@@@@@@@##@@##
##@@############@@##
##@@############@@##
##@@@@@@@@@@@@@@@@##
##@@@@@@@@@@@@@@@@##
####################
####################
Input 4:
################
################
## ###
## x ###
## ####### ###
## ####### ###
## ## ## ###
## ## ## ###
## ## ## ###
## ######## ##
## ######## ##
## ## ##
## ## ##
################
################
Output 4:
################
################
## @ @ ###
## @ @ @ ###
## ####### ###
##@ ####### @###
## ## ## ###
## @## ##@ ###
## ## ## ###
##@ ########@ ##
## ######## ##
## @ @ ## @##
## @ @## ##
################
################
Input 5:
##############
##############
## ###
## ###
## ###
## ### ###
## #x# ###
## ### ###
## ###
## ###
## ###
##############
##############
Output 5:
##############
##############
##@@@@@@@@@###
##@@@@@@@@@###
##@@@@@@@@@###
##@@@###@@@###
##@@@#@#@@@###
##@@@###@@@###
##@@@@@@@@@###
##@@@@@@@@@###
##@@@@@@@@@###
##############
##############