Class: DeepBeige::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/deepbeige/main.rb

Class Method Summary collapse

Class Method Details

.game_choiceObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/deepbeige/main.rb', line 63

def game_choice
  puts
  puts "Which Game?"
  puts "  1. Noughts and Crosses"
  puts "  2. Pick A Number"
  game = nil
  case gets.chop
  when "1"
    game = NoughtsAndCrosses.new
  when "2"
    game = PickANumber.new  
  else 
    puts "Sorry, didn't understand you there."
  end
  game
end

.optionsObject



53
54
55
56
57
58
59
60
61
# File 'lib/deepbeige/main.rb', line 53

def options
  puts
  puts "What would you like to do?"
  puts "  1. Player vs DeepBeige"
  puts "  2. Train DeepBeige"
  puts "  3. Reset DeepBeige"
  puts "  4. Player vs Player"
  puts "  5. Exit Application"
end

.play_game(game, p1, p2, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/deepbeige/main.rb', line 14

def play_game game, p1, p2, options
  players = [p1,p2]
  table = Table.new game, players

  options.each do |option|
    if option == "verbose"
      game.verbose = true
    elsif option == "quiet"
      game.quiet = true
      table.quiet = true
    end
  end

  table.play_game
end

.player_vs_deepbeige(db, game) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/deepbeige/main.rb', line 30

def player_vs_deepbeige db, game
  #ok so now I'm interested in playing my best creation
  db.start_game game.name
  me = Human.new game
  if which_player == "1"
    play_game game, me, db, []
  else
    play_game game, db, me, []
  end
end

.player_vs_player(game) ⇒ Object



41
42
43
44
45
# File 'lib/deepbeige/main.rb', line 41

def player_vs_player game
  p1 = Human.new game
  p2 = Human.new game
  play_game game, p1,p2, []
end

.run!(*arguments) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/deepbeige/main.rb', line 80

def run!(*arguments)

 #       begin
    db = DeepBeige.new

    version = "0.2.2"
    puts
    puts "Welcome to DeepBeige v#{version}"

    exit = false
    until exit do
      options
      case input = gets.chop
      when "1"
        game =  game_choice
        player_vs_deepbeige db, game
      when "2"
        game = game_choice
        puts "How Many Generations?"
        generations = gets.chop.to_i
        db.train generations, game
      when "3"
        game = game_choice
        db.learn game
        puts "DeepBeige Reset sucessfully"
      when "4"
        game = game_choice
        player_vs_player game
      when "5"
        puts "Bye Bye"
        exit = true
      else 
        puts "Sorry I didn't understand you"
      end
    end
    return 0
#        rescue 
#          $stderr.puts "Something Went Wrong With Deep Beige - Sorry"
#          return 1
#        end
end

.which_playerObject



47
48
49
50
51
# File 'lib/deepbeige/main.rb', line 47

def which_player
  puts
  puts "Would you like to be player 1 or 2?"
  gets.chop
end