lib/tak/board.rb
# Does a DFS variant to locate a potential road.
#
# @param x         [Integer] Start X coordinate
# @param y         [Integer] Start Y coordinate
# @param direction [Symbol]  Direction the search completes on
#
# @param bit_board [Array[Array[Integer]]] Board to parse against
# @param traversed [Array[Array[Boolean]]] Traversal tracker
#
# @return [Boolean] Whether or not a road was round
Does a DFS variant to locate a potential road.
Does a DFS variant to locate a potential road .
def path_search(x, y, direction, bit_board, traversed = visited_board)
      return false if out_of_bounds?(x,y) || traversed[x][y]
      piece_value = bit_board[x][y]
      return false if piece_value == 0 
      return true  if road_end?(direction, x, y)
      traversed[x][y] = true
      path_search(x + 1, y,     direction, bit_board, traversed) ||
      path_search(x - 1, y,     direction, bit_board, traversed) ||
      path_search(x,     y + 1, direction, bit_board, traversed) ||
      path_search(x,     y - 1, direction, bit_board, traversed)
    end
def path_search ( x , y , direction , bit_board , traversed = visited_board ) return false if out_of_bounds? ( x , y ) || traversed [ x ] [ y ] piece_value = bit_board [ x ] [ y ] return false if piece_value == 0 return true if road_end? ( direction , x , y ) traversed [ x ] [ y ] = true path_search ( x + 1 , y , direction , bit_board , traversed ) || path_search ( x - 1 , y , direction , bit_board , traversed ) || path_search ( x , y + 1 , direction , bit_board , traversed ) || path_search ( x , y - 1 , direction , bit_board , traversed ) end
Does a DFS variant to locate a potential road.
Does a DFS variant to locate a potential road .
# Non-road piece # Recurse in all four directions. While this may retrace steps it is # necessary as roads in Tak can curve wildly.
Whether or not a road was round
Whether or not a road was round
Boolean
x
Start X coordinate
Start X coordinate
y
Start Y coordinate
Start Y coordinate
direction
Direction the search completes on
Direction the search completes on
bit_board
]] Board to parse against
]] Board to parse against
traversed
]] Traversal tracker
]] Traversal tracker
visited_board
<not_specific>