games_bfox 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -12
- data/config/application.yml +5 -0
- data/games.gemspec +2 -1
- data/lib/games/mastermind/board_builder.rb +6 -2
- data/lib/games/mastermind/computer_player_expert.rb +31 -0
- data/lib/games/mastermind/computer_player_novice.rb +18 -0
- data/lib/games/mastermind/game.rb +69 -15
- data/lib/games/mastermind/guess_evaluator.rb +105 -68
- data/lib/games/mastermind/guess_evaluator_result.rb +11 -0
- data/lib/games/mastermind/human_player.rb +9 -0
- data/lib/games/mastermind/io_helpers.rb +65 -0
- data/lib/games/mastermind/peg.rb +2 -4
- data/lib/games/mastermind/pegs.rb +1 -9
- data/lib/games/mastermind/pegs_factory.rb +3 -5
- data/lib/games/mastermind/players_factory.rb +32 -8
- data/lib/games/mastermind/secret_code.rb +19 -0
- data/lib/games/mastermind.rb +9 -2
- data/lib/games/shared/game.rb +56 -70
- data/lib/games/shared/{input_helper.rb → io_helpers.rb} +40 -32
- data/lib/games/shared/player.rb +1 -3
- data/lib/games/shared/player_factory.rb +9 -0
- data/lib/games/shared/players_factory.rb +9 -0
- data/lib/games/tictactoe/board.rb +3 -4
- data/lib/games/tictactoe/board_builder.rb +3 -3
- data/lib/games/tictactoe/board_presenter_terminal.rb +3 -3
- data/lib/games/tictactoe/computer_player_expert.rb +12 -0
- data/lib/games/tictactoe/computer_player_novice.rb +10 -0
- data/lib/games/tictactoe/game.rb +45 -12
- data/lib/games/tictactoe/human_player.rb +9 -0
- data/lib/games/tictactoe/io_helpers.rb +81 -0
- data/lib/games/tictactoe/player.rb +4 -0
- data/lib/games/tictactoe/players_factory.rb +49 -5
- data/lib/games/tictactoe/square.rb +0 -3
- data/lib/games/tictactoe/squares.rb +1 -1
- data/lib/games/tictactoe/squares_factory.rb +7 -11
- data/lib/games/tictactoe.rb +9 -2
- data/lib/games/version.rb +1 -1
- metadata +32 -17
- data/lib/games/mastermind/colors.rb +0 -14
- data/lib/games/mastermind/game_config.rb +0 -48
- data/lib/games/mastermind/game_resetter.rb +0 -19
- data/lib/games/mastermind/game_state_changer.rb +0 -41
- data/lib/games/mastermind/input_helper.rb +0 -67
- data/lib/games/mastermind/move_generator.rb +0 -46
- data/lib/games/shared/array_iterator.rb +0 -28
- data/lib/games/tictactoe/game_config.rb +0 -73
- data/lib/games/tictactoe/game_resetter.rb +0 -16
- data/lib/games/tictactoe/game_state_changer.rb +0 -17
- data/lib/games/tictactoe/input_helper.rb +0 -87
- data/lib/games/tictactoe/move_generator.rb +0 -68
@@ -1,87 +0,0 @@
|
|
1
|
-
require_relative '../shared/input_helper'
|
2
|
-
|
3
|
-
module TTT
|
4
|
-
class InputHelper < Shared::InputHelper
|
5
|
-
def get_number_of_rows_cols_max_3
|
6
|
-
get_user_input("Please choose how many squares you would like in each row.", "Please choose number between 2 and 3.") do |input|
|
7
|
-
input.to_i >=2 && input.to_i <=3
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def get_number_of_rows_cols_max_9
|
12
|
-
get_user_input("Please choose how many squares you would like in each row.", "Please choose number between 2 and 3.") do |input|
|
13
|
-
input.to_i >=2 && input.to_i <=9
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def get_player_1_value(player_name = "Player 1")
|
18
|
-
user_choice = get_user_input("#{player_name}, please enter a value of either X or O", "Must be X or O. Please re-enter.") do |input|
|
19
|
-
input == 'x' || input == 'X' || input == 'o' || input == 'O'
|
20
|
-
end
|
21
|
-
user_choice.upcase
|
22
|
-
end
|
23
|
-
|
24
|
-
def get_player_2_name
|
25
|
-
user_choice = get_user_input("Player 2, please enter your name", "Please re-enter your name, using only letters") do |input|
|
26
|
-
input =~ /^[a-zA-Z]+$/
|
27
|
-
end
|
28
|
-
user_choice.capitalize
|
29
|
-
end
|
30
|
-
|
31
|
-
def get_player_2_type
|
32
|
-
user_choice = get_user_input("Please enter \"C\" if you would like to play the Computer. Enter \"H\" if you would like to play the human sitting next to you.", "Invalid character. Please enter either C(Computer) or H(Human).") do |input|
|
33
|
-
input == 'c' || input == 'C' || input == 'h' || input == 'H'
|
34
|
-
end
|
35
|
-
user_choice = user_choice.upcase
|
36
|
-
if user_choice == "C"
|
37
|
-
:computer
|
38
|
-
elsif user_choice == "H"
|
39
|
-
:human
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def get_computer_difficulty_level
|
44
|
-
user_choice = get_user_input("Please enter \"E\" if you would like to play an easy Computer. Enter \"D\" if you would like to play an extremely difficult computer.", "Invalid character. Please enter either E (Easy) or D (Difficult).") do |input|
|
45
|
-
input == 'd' || input == 'D' || input == 'e' || input == 'E'
|
46
|
-
end
|
47
|
-
user_choice = user_choice.upcase
|
48
|
-
if user_choice == "D"
|
49
|
-
:difficult
|
50
|
-
elsif user_choice == "E"
|
51
|
-
:easy
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def get_player_2_value(taken_value)
|
56
|
-
user_choice = get_user_input("Player 2, please enter your value", "Must not be #{taken_value}, please re-enter") do |input|
|
57
|
-
input.upcase != taken_value.upcase
|
58
|
-
end
|
59
|
-
user_choice.upcase
|
60
|
-
end
|
61
|
-
|
62
|
-
def get_player_choice(game)
|
63
|
-
get_user_input("#{game.current_player_name}, please enter the number of the square that you would like to change.", "Invalid entry. Please try again.") do |input|
|
64
|
-
game.available_choices.include?(input)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def initial_instructions
|
69
|
-
io.present_with_new_line("TIC TAC TOE")
|
70
|
-
io.present_with_new_line("___________")
|
71
|
-
io.present_with_new_line("Type \"Exit\" to quit the game.")
|
72
|
-
io.present_with_new_line("___________")
|
73
|
-
end
|
74
|
-
|
75
|
-
def draw_prompt
|
76
|
-
io.present_with_new_line("Draw! Please try again.")
|
77
|
-
end
|
78
|
-
|
79
|
-
def winning_prompt(current_player_name)
|
80
|
-
io.present_with_new_line("#{current_player_name} wins!")
|
81
|
-
end
|
82
|
-
|
83
|
-
def no_winner_prompt
|
84
|
-
io.present_with_new_line("Draw!")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require_relative 'minimax'
|
2
|
-
|
3
|
-
module TTT
|
4
|
-
class MoveGenerator
|
5
|
-
|
6
|
-
attr_accessor :game
|
7
|
-
|
8
|
-
def get_player_choice(game)
|
9
|
-
@game = game
|
10
|
-
get_move
|
11
|
-
end
|
12
|
-
|
13
|
-
def get_move
|
14
|
-
if human?
|
15
|
-
input_helper.get_player_choice(game)
|
16
|
-
elsif computer?
|
17
|
-
input_helper.computer_choosing_graphic
|
18
|
-
if difficult?
|
19
|
-
perfect_move
|
20
|
-
elsif easy?
|
21
|
-
random_move
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def perfect_move
|
27
|
-
minimax = game_module::Minimax.new(game.board, game.number_of_turns_taken, game.player_1_value, game.player_2_value)
|
28
|
-
minimax.run_minimax
|
29
|
-
minimax.choice
|
30
|
-
end
|
31
|
-
|
32
|
-
def random_move
|
33
|
-
available_choices.sample
|
34
|
-
end
|
35
|
-
|
36
|
-
def available_choices
|
37
|
-
game.available_choices
|
38
|
-
end
|
39
|
-
|
40
|
-
def game_module
|
41
|
-
game.game_module
|
42
|
-
end
|
43
|
-
|
44
|
-
def current_player
|
45
|
-
game.current_player
|
46
|
-
end
|
47
|
-
|
48
|
-
def input_helper
|
49
|
-
game.input_helper
|
50
|
-
end
|
51
|
-
|
52
|
-
def human?
|
53
|
-
game.current_player_human?
|
54
|
-
end
|
55
|
-
|
56
|
-
def computer?
|
57
|
-
game.current_player_computer?
|
58
|
-
end
|
59
|
-
|
60
|
-
def difficult?
|
61
|
-
game.current_player_difficult_computer?
|
62
|
-
end
|
63
|
-
|
64
|
-
def easy?
|
65
|
-
game.current_player_easy_computer?
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|