Module: Chess::BoardPos
- Included in:
- Board
- Defined in:
- lib/chess/board/board_pos.rb
Overview
Board
Instance Method Summary collapse
-
#east_pos(file, rank) ⇒ Object
the east pos from the given pos.
-
#north_east_pos(file, rank) ⇒ Object
the north_east_pos pos from the given pos.
-
#north_pos(file, rank) ⇒ Object
the north pos from the given pos.
-
#north_west_pos(file, rank) ⇒ Object
the north_west_pos pos from the given pos.
-
#pos_in_range?(file, rank) ⇒ Boolean
checks if a pos is in range.
-
#pos_nil?(file, rank) ⇒ Boolean
checks if a pos is nil value.
-
#south_east_pos(file, rank) ⇒ Object
the south_east_pos pos from the given pos.
-
#south_pos(file, rank) ⇒ Object
the south pos from the given pos.
-
#south_west_pos(file, rank) ⇒ Object
the south_west_pos pos from the given pos.
-
#west_pos(file, rank) ⇒ Object
the west pos from the given pos.
Instance Method Details
#east_pos(file, rank) ⇒ Object
the east pos from the given pos
18 19 20 |
# File 'lib/chess/board/board_pos.rb', line 18 def east_pos(file, rank) [(file.ord - 1).chr, rank] end |
#north_east_pos(file, rank) ⇒ Object
the north_east_pos pos from the given pos
28 29 30 |
# File 'lib/chess/board/board_pos.rb', line 28 def north_east_pos(file, rank) [(file.ord - 1).chr, rank + 1] end |
#north_pos(file, rank) ⇒ Object
the north pos from the given pos
8 9 10 |
# File 'lib/chess/board/board_pos.rb', line 8 def north_pos(file, rank) [file, rank + 1] end |
#north_west_pos(file, rank) ⇒ Object
the north_west_pos pos from the given pos
33 34 35 |
# File 'lib/chess/board/board_pos.rb', line 33 def north_west_pos(file, rank) [(file.ord + 1).chr, rank + 1] end |
#pos_in_range?(file, rank) ⇒ Boolean
checks if a pos is in range
57 58 59 60 61 62 63 |
# File 'lib/chess/board/board_pos.rb', line 57 def pos_in_range?((file, rank)) first_rank = 0 last_rank = 7 first_file_ord = 'a'.ord last_file_ord = 'h'.ord rank.between?(first_rank, last_rank) && file.ord.between?(first_file_ord, last_file_ord) end |
#pos_nil?(file, rank) ⇒ Boolean
checks if a pos is nil value
50 51 52 |
# File 'lib/chess/board/board_pos.rb', line 50 def pos_nil?((file, rank)) piece_at(file, rank).nil? end |
#south_east_pos(file, rank) ⇒ Object
the south_east_pos pos from the given pos
38 39 40 |
# File 'lib/chess/board/board_pos.rb', line 38 def south_east_pos(file, rank) [(file.ord - 1).chr, rank - 1] end |
#south_pos(file, rank) ⇒ Object
the south pos from the given pos
13 14 15 |
# File 'lib/chess/board/board_pos.rb', line 13 def south_pos(file, rank) [file, rank - 1] end |
#south_west_pos(file, rank) ⇒ Object
the south_west_pos pos from the given pos
43 44 45 |
# File 'lib/chess/board/board_pos.rb', line 43 def south_west_pos(file, rank) [(file.ord + 1).chr, rank - 1] end |
#west_pos(file, rank) ⇒ Object
the west pos from the given pos
23 24 25 |
# File 'lib/chess/board/board_pos.rb', line 23 def west_pos(file, rank) [(file.ord + 1).chr, rank] end |