Sha256: 158a97e2e9763b750e3e6aeadb7d1e39622ddf786a759b946d5571d1b747ef81

Contents?: true

Size: 661 Bytes

Versions: 115

Compression:

Stored size: 661 Bytes

Contents

return function(pos)
  assert(pos.row >= 0, 'row must be positive')
  assert(pos.row < 8, 'row must be on the board')
  assert(pos.column >= 0, 'column must be positive')
  assert(pos.column < 8, 'column must be on the board')

  return {
    row = pos.row,
    column = pos.column,
    can_attack = function(other)
      local row_difference = math.abs(pos.row - other.row)
      local column_difference = math.abs(pos.column - other.column)

      local same_row = row_difference == 0
      local same_column = column_difference == 0
      local diagonal = row_difference == column_difference

      return same_row or same_column or diagonal
    end
  }
end

Version data entries

115 entries across 115 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.158 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.157 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.156 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.155 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.154 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.153 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.152 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.151 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.150 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.149 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.148 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.147 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.146 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.145 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.144 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.143 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.142 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.141 tracks/lua/exercises/queen-attack/example.lua
trackler-2.2.1.140 tracks/lua/exercises/queen-attack/example.lua