Class: LengthToXY
- Inherits:
-
Object
- Object
- LengthToXY
- Defined in:
- lib/codenjoy/games/battlecity/board.rb
Instance Method Summary collapse
- #getLength(x, y) ⇒ Object
- #getXY(length) ⇒ Object
-
#initialize(board_size) ⇒ LengthToXY
constructor
A new instance of LengthToXY.
- #inversionX(x) ⇒ Object
- #inversionY(y) ⇒ Object
Constructor Details
#initialize(board_size) ⇒ LengthToXY
Returns a new instance of LengthToXY.
27 28 29 |
# File 'lib/codenjoy/games/battlecity/board.rb', line 27 def initialize(board_size) @board_size = board_size end |
Instance Method Details
#getLength(x, y) ⇒ Object
46 47 48 49 50 |
# File 'lib/codenjoy/games/battlecity/board.rb', line 46 def getLength(x, y) xx = inversionX(x); yy = inversionY(y); yy * @board_size + xx; end |
#getXY(length) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/codenjoy/games/battlecity/board.rb', line 39 def getXY(length) return nil if (length == -1) x = inversionX(length % @board_size); y = inversionY((length / @board_size).floor); return Point.new(x, y); end |
#inversionX(x) ⇒ Object
35 36 37 |
# File 'lib/codenjoy/games/battlecity/board.rb', line 35 def inversionX(x) x; end |
#inversionY(y) ⇒ Object
31 32 33 |
# File 'lib/codenjoy/games/battlecity/board.rb', line 31 def inversionY(y) @board_size - 1 - y; end |