Class: LengthToXY
- Inherits:
-
Object
- Object
- LengthToXY
- Defined in:
- lib/codenjoy/utils.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
50 51 52 |
# File 'lib/codenjoy/utils.rb', line 50 def initialize(board_size) @board_size = board_size end |
Instance Method Details
#getLength(x, y) ⇒ Object
69 70 71 72 73 |
# File 'lib/codenjoy/utils.rb', line 69 def getLength(x, y) xx = inversionX(x); yy = inversionY(y); yy * @board_size + xx; end |
#getXY(length) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/codenjoy/utils.rb', line 62 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
58 59 60 |
# File 'lib/codenjoy/utils.rb', line 58 def inversionX(x) x; end |
#inversionY(y) ⇒ Object
54 55 56 |
# File 'lib/codenjoy/utils.rb', line 54 def inversionY(y) @board_size - 1 - y; end |