Class: GamesAndRpgParadise::Board

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb

Constant Summary collapse

WINNING_PLACES =
#

WINNING_PLACES

Designate all winning places/locations.

#
[
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
  [1, 4, 7],
  [2, 5, 8],
  [3, 6, 9],
  [1, 5, 9],
  [3, 5, 7]
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBoard

#

initialize

#


33
34
35
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 33

def initialize
  reset
end

Instance Attribute Details

#infoObject

Returns the value of attribute info.



9
10
11
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 9

def info
  @info
end

#positions_with_valuesObject

Returns the value of attribute positions_with_values.



10
11
12
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 10

def positions_with_values
  @positions_with_values
end

Instance Method Details

#displayObject

#

display

This method will display the game map, on the commandline.

#


78
79
80
81
82
83
84
85
86
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 78

def display
  e
  e " #{self.positions_with_values["1"]} | #{self.positions_with_values["2"]} | #{self.positions_with_values["3"]} "
  liner
  e " #{self.positions_with_values["4"]} | #{self.positions_with_values["5"]} | #{self.positions_with_values["6"]} "
  liner
  e " #{self.positions_with_values["7"]} | #{self.positions_with_values["8"]} | #{self.positions_with_values["9"]} "
  e
end

#display_positionsObject

#

display_positions

#


56
57
58
59
60
61
62
63
64
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 56

def display_positions # initial user friendly board display
  e
  e ' 1 | 2 | 3 '
  liner
  e ' 4 | 5 | 6 '
  liner
  e ' 7 | 8 | 9 '
  e
end

#linerObject

#

liner

#


69
70
71
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 69

def liner
  e '-----------'
end

#resetObject

#

reset

#


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/games_and_rpg_paradise/games/tic_tac_toe/tic_tac_toe_with_AI/board.rb', line 40

def reset
  # ======================================================================= #
  # === @positions_with_values
  #
  # Board position starts from 1 to 9
  # ======================================================================= #
  @positions_with_values = {
    '1' => ' ', '2' => ' ', '3' => ' ',
    '4' => ' ', '5' => ' ', '6' => ' ',
    '7' => ' ', '8' => ' ', '9' => ' '
  }
end