games_bfox 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +14 -14
- data/exe/games +5 -0
- data/exe/mastermind +2 -2
- data/exe/tictactoe +2 -2
- data/lib/games.rb +12 -3
- data/lib/games/mastermind.rb +9 -2
- data/lib/games/mastermind/board.rb +2 -2
- data/lib/games/mastermind/board_builder.rb +2 -2
- data/lib/games/mastermind/computer_player_expert.rb +6 -4
- data/lib/games/mastermind/computer_player_novice.rb +1 -1
- data/lib/games/mastermind/game.rb +6 -2
- data/lib/games/mastermind/guess_evaluator.rb +1 -1
- data/lib/games/mastermind/human_player.rb +1 -1
- data/lib/games/mastermind/io_helpers.rb +3 -3
- data/lib/games/mastermind/pegs.rb +2 -2
- data/lib/games/mastermind/pegs_factory.rb +2 -2
- data/lib/games/mastermind/players_factory.rb +4 -3
- data/lib/games/shared/game.rb +2 -6
- data/lib/games/shared/io_helpers.rb +13 -2
- data/lib/games/shared/io_terminal.rb +2 -2
- data/lib/games/tictactoe.rb +9 -2
- data/lib/games/tictactoe/board.rb +5 -5
- data/lib/games/tictactoe/board_builder.rb +2 -2
- data/lib/games/tictactoe/board_presenter_terminal.rb +1 -1
- data/lib/games/tictactoe/computer_player_expert.rb +2 -1
- data/lib/games/tictactoe/computer_player_novice.rb +1 -1
- data/lib/games/tictactoe/game.rb +2 -2
- data/lib/games/tictactoe/human_player.rb +1 -1
- data/lib/games/tictactoe/io_helpers.rb +1 -1
- data/lib/games/tictactoe/minimax.rb +3 -2
- data/lib/games/tictactoe/player.rb +1 -1
- data/lib/games/tictactoe/players_factory.rb +4 -3
- data/lib/games/tictactoe/square.rb +2 -2
- data/lib/games/tictactoe/squares.rb +3 -3
- data/lib/games/tictactoe/squares_factory.rb +2 -2
- data/lib/games/version.rb +1 -1
- metadata +5 -3
- data/lib/games/shared/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 702ed910d768c011c3ea9368619789ab36e9cb6c
|
4
|
+
data.tar.gz: 9c168b219534ae38b0f8c7c9257a4ec1da345672
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e54ceafc5ba6eca59d09e475428e359bbd8d5a3934fc4646728d8806d8fc01b445fbea2f094679827d08a65528f398a7ada54674dae27ab93249a5022e8cca2b
|
7
|
+
data.tar.gz: 25c0874c5fc1f1a36c5a6cc6e3a482ace6ac50c6bfe65fff0b1c7eed193bebc29bbd165115bfb3705b746fff07099446c07a3ab628ae3b4d38963c9d65ce1528
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
..starting at Version 0.5.0
|
2
|
+
##### Version 0.6.0 (01.15.2018)
|
3
|
+
* Update dependencies to latest versions
|
4
|
+
|
5
|
+
##### Version 0.5.0 (01.15.2018)
|
6
|
+
* Allow user to choose between tictactoe and mastermind at run time
|
7
|
+
* Reclassify game specs as integration tests
|
8
|
+
* Add CHANGELOG.md
|
9
|
+
* Add version test
|
data/README.md
CHANGED
@@ -2,25 +2,16 @@
|
|
2
2
|
|
3
3
|
Welcome to the games_bfox gem!
|
4
4
|
|
5
|
+
## Versions
|
6
|
+
Ruby 2.4.0, rbenv 1.1.1
|
5
7
|
|
6
|
-
##
|
8
|
+
## How to Run
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'games_bfox'
|
12
|
-
```
|
13
|
-
|
14
|
-
And then execute:
|
15
|
-
|
16
|
-
$ bundle
|
17
|
-
|
18
|
-
Or install it yourself as:
|
10
|
+
###...from the command line
|
11
|
+
To run from command line, you must install the gem on your machine:
|
19
12
|
|
20
13
|
$ gem install games_bfox
|
21
14
|
|
22
|
-
## Usage
|
23
|
-
|
24
15
|
To play Mastermind, type the following into your command line to run the game executable :
|
25
16
|
|
26
17
|
$ mastermind
|
@@ -29,4 +20,13 @@ To play Tic Tac Toe, type the following into your command line to run the game e
|
|
29
20
|
|
30
21
|
$ tictactoe
|
31
22
|
|
23
|
+
###...from inside the project
|
24
|
+
|
25
|
+
Clone the project, cd into the project directory, and then run the following command:
|
26
|
+
|
27
|
+
$ bundle exec ruby lib/games.rb
|
28
|
+
|
29
|
+
## How to Test
|
30
|
+
From inside the project directory, run the following command:
|
32
31
|
|
32
|
+
$ bundle exec rspec
|
data/exe/games
ADDED
data/exe/mastermind
CHANGED
data/exe/tictactoe
CHANGED
data/lib/games.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require File.join('games', 'version')
|
2
|
+
require File.join('games', 'mastermind')
|
3
|
+
require File.join('games', 'tictactoe')
|
4
|
+
require File.join('games', 'shared', 'io_helpers')
|
5
|
+
require File.join('games', 'shared', 'io_terminal')
|
2
6
|
|
3
|
-
|
4
|
-
|
7
|
+
io_helpers = Shared::IOHelpers.new(Shared::IOTerminal.new)
|
8
|
+
choice = io_helpers.choose_game
|
9
|
+
|
10
|
+
if choice == :tictactoe
|
11
|
+
TicTacToe.run
|
12
|
+
elsif choice == :mastermind
|
13
|
+
Mastermind.run
|
5
14
|
end
|
data/lib/games/mastermind.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'shared', '*.rb')].each {|file| require file }
|
2
|
-
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'mastermind', '*.rb')].each {|file| require file }
|
1
|
+
# Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'shared', '*.rb')].each {|file| require file }
|
2
|
+
# Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'mastermind', '*.rb')].each {|file| require file }
|
3
|
+
|
4
|
+
require File.join('games', 'shared', 'io_terminal')
|
5
|
+
require File.join('games', 'mastermind', 'io_helpers')
|
6
|
+
require File.join('games', 'mastermind', 'board_presenter_terminal')
|
7
|
+
require File.join('games', 'mastermind', 'board_builder')
|
8
|
+
require File.join('games', 'mastermind', 'players_factory')
|
9
|
+
require File.join('games', 'mastermind', 'game')
|
3
10
|
|
4
11
|
class Mastermind
|
5
12
|
def self.run
|
@@ -32,12 +32,12 @@ module MM
|
|
32
32
|
|
33
33
|
private
|
34
34
|
def retrieve_peg(row, col)
|
35
|
-
|
35
|
+
pegs.retrieve_peg(row, col)
|
36
36
|
end
|
37
37
|
|
38
38
|
#result_pegs is an instance of pegs
|
39
39
|
def retrieve_result_peg(row, col)
|
40
|
-
|
40
|
+
result_pegs.retrieve_peg(row,col)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
require File.join('games', 'shared', 'player')
|
2
2
|
|
3
3
|
module MM
|
4
4
|
class ComputerPlayerExpert < Shared::Player
|
5
|
+
attr_reader :game
|
6
|
+
|
5
7
|
def make_move(game)
|
6
8
|
@game = game
|
7
9
|
computer_choosing_graphic
|
@@ -17,15 +19,15 @@ module MM
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def computer_choosing_graphic
|
20
|
-
|
22
|
+
game.computer_choosing_graphic
|
21
23
|
end
|
22
24
|
|
23
25
|
def current_result_partial_match_values
|
24
|
-
|
26
|
+
game.current_result_partial_match_values
|
25
27
|
end
|
26
28
|
|
27
29
|
def current_result_exact_match_values
|
28
|
-
|
30
|
+
game.current_result_exact_match_values
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
@@ -1,4 +1,8 @@
|
|
1
|
-
|
1
|
+
require File.join('games', 'shared', 'game')
|
2
|
+
require File.join('games', 'mastermind', 'guess_evaluator')
|
3
|
+
require File.join('games', 'mastermind', 'guess_evaluator_result')
|
4
|
+
require File.join('games', 'mastermind', 'human_player')
|
5
|
+
require File.join('games', 'mastermind', 'secret_code')
|
2
6
|
require 'logger'
|
3
7
|
|
4
8
|
module MM
|
@@ -63,7 +67,7 @@ module MM
|
|
63
67
|
def won?
|
64
68
|
#depends on evaluate_guess returning an array of all "X"s for perfect guess
|
65
69
|
if won_flag
|
66
|
-
|
70
|
+
true
|
67
71
|
end
|
68
72
|
|
69
73
|
if self.current_result.is_won
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require File.join('games', 'shared', 'io_helpers')
|
2
2
|
require 'paint'
|
3
3
|
|
4
4
|
module MM
|
@@ -30,9 +30,9 @@ module MM
|
|
30
30
|
input == 1 || input == 2
|
31
31
|
end
|
32
32
|
if user_choice == 1
|
33
|
-
|
33
|
+
:human
|
34
34
|
elsif user_choice == 2
|
35
|
-
|
35
|
+
:computer
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require File.join('games', 'shared', 'players_factory')
|
2
|
+
require File.join('games', 'mastermind', 'human_player')
|
3
|
+
require File.join('games', 'mastermind', 'computer_player_expert')
|
4
|
+
require File.join('games', 'mastermind', 'computer_player_novice')
|
4
5
|
|
5
6
|
module MM
|
6
7
|
class PlayersFactory < Shared::PlayersFactory
|
data/lib/games/shared/game.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
# note the below exclude the game subclasses, because these classes inherit from this class, so if we require these before the parent class is read, an error will be generated.
|
3
|
-
Dir[File.join(File.expand_path("..", File.dirname(__FILE__)), 'tictactoe', '*.rb')].each {|file| require file unless file == File.join(File.expand_path("..", File.dirname(__FILE__)), 'tictactoe', 'game.rb')}
|
4
|
-
Dir[File.join(File.expand_path("..", File.dirname(__FILE__)), 'mastermind', '*.rb')].each {|file| require file unless file == File.join(File.expand_path("..", File.dirname(__FILE__)), 'mastermind', 'game.rb')}
|
1
|
+
require File.join('games', 'tictactoe', 'computer_player_expert')
|
5
2
|
|
6
3
|
module Shared
|
7
4
|
class Game
|
@@ -10,7 +7,6 @@ module Shared
|
|
10
7
|
attr_accessor :number_of_turns_taken, :won_flag
|
11
8
|
attr_reader :io_helpers
|
12
9
|
|
13
|
-
|
14
10
|
def initialize(args = {})
|
15
11
|
@board_presenter = args.fetch(:board_presenter)
|
16
12
|
|
@@ -62,7 +58,7 @@ module Shared
|
|
62
58
|
def winner
|
63
59
|
#each move is immediately proceeded by an increment to number_of_selections_made; therefore, need to rewind won to find winner
|
64
60
|
if !won?
|
65
|
-
|
61
|
+
nil
|
66
62
|
end
|
67
63
|
current_player
|
68
64
|
end
|
@@ -12,6 +12,17 @@ module Shared
|
|
12
12
|
raise 'Called abstract method: initial_instructions'
|
13
13
|
end
|
14
14
|
|
15
|
+
def choose_game
|
16
|
+
user_choice = get_user_input("Please enter " + Paint["\"1\" ", :blue, :bold] + "if you would like to play " + Paint["tictactoe. ", :blue, :bold] + "Enter " + Paint["\"2\" ", :red, :bold] + "if you would like to play " + Paint["mastermind.", :red, :bold], "Invalid entry. Please enter either 1(tictactoe) or 2 (mastermind)") do |input|
|
17
|
+
input == 1 || input == 2
|
18
|
+
end
|
19
|
+
if user_choice == 1
|
20
|
+
:tictactoe
|
21
|
+
elsif user_choice == 2
|
22
|
+
:mastermind
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
def get_player_1_name
|
16
27
|
user_choice = get_user_input("Player 1, please enter your name:", "Please re-enter your name, using only letters") do |input|
|
17
28
|
input =~ /^[a-zA-Z]+$/
|
@@ -56,8 +67,6 @@ module Shared
|
|
56
67
|
#hook
|
57
68
|
end
|
58
69
|
|
59
|
-
private
|
60
|
-
|
61
70
|
def get_user_input(prompt, reprompt, &block_validation)
|
62
71
|
io.present_with_new_line(prompt)
|
63
72
|
user_choice = nil
|
@@ -74,6 +83,8 @@ module Shared
|
|
74
83
|
user_choice
|
75
84
|
end
|
76
85
|
|
86
|
+
private
|
87
|
+
|
77
88
|
def marching_dots
|
78
89
|
sleep(0.2)
|
79
90
|
io.present(".")
|
data/lib/games/tictactoe.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
|
-
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'shared', '*.rb')].each {|file| require file }
|
2
|
-
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'tictactoe', '*.rb')].each {|file| require file }
|
1
|
+
# Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'shared', '*.rb')].each {|file| require file }
|
2
|
+
# Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'tictactoe', '*.rb')].each {|file| require file }
|
3
|
+
|
4
|
+
require File.join('games', 'shared', 'io_terminal')
|
5
|
+
require File.join('games', 'tictactoe', 'io_helpers')
|
6
|
+
require File.join('games', 'tictactoe', 'board_presenter_terminal')
|
7
|
+
require File.join('games', 'tictactoe', 'board_builder')
|
8
|
+
require File.join('games', 'tictactoe', 'players_factory')
|
9
|
+
require File.join('games', 'tictactoe', 'game')
|
3
10
|
|
4
11
|
class TicTacToe
|
5
12
|
def self.run
|
@@ -12,19 +12,19 @@ module TTT
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def full?
|
15
|
-
|
15
|
+
squares.full?
|
16
16
|
end
|
17
17
|
|
18
18
|
def won?
|
19
|
-
|
19
|
+
squares.any_combination_won?
|
20
20
|
end
|
21
21
|
|
22
22
|
def display_values
|
23
|
-
|
23
|
+
squares.display_values
|
24
24
|
end
|
25
25
|
|
26
26
|
def available_choices
|
27
|
-
|
27
|
+
squares.available_choices
|
28
28
|
end
|
29
29
|
|
30
30
|
def number_of_rows_cols
|
@@ -33,7 +33,7 @@ module TTT
|
|
33
33
|
|
34
34
|
private
|
35
35
|
def retrieve_square(display_value)
|
36
|
-
|
36
|
+
squares.retrieve_square(display_value)
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/games/tictactoe/game.rb
CHANGED
@@ -21,6 +21,7 @@ module TTT
|
|
21
21
|
if board_won || board_full
|
22
22
|
#rewind one player to see which player took last turn and therefore won the game
|
23
23
|
self.number_of_turns_taken -= 1
|
24
|
+
# note: need return statement here so that method stops here if board is won or full
|
24
25
|
return score(board_won)
|
25
26
|
end
|
26
27
|
|
@@ -38,12 +39,12 @@ module TTT
|
|
38
39
|
#https://stackoverflow.com/questions/2149802/in-ruby-what-is-the-cleanest-way-of-obtaining-the-index-of-the-largest-value-in
|
39
40
|
max_score_index = scores.each_with_index.max[1]
|
40
41
|
self.choice = choices[max_score_index]
|
41
|
-
|
42
|
+
scores[max_score_index]
|
42
43
|
else
|
43
44
|
# This is the min calculation
|
44
45
|
min_score_index = scores.each_with_index.min[1]
|
45
46
|
self.choice = choices[min_score_index]
|
46
|
-
|
47
|
+
scores[min_score_index]
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -1,6 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require File.join('games', 'shared', 'players_factory')
|
2
|
+
require File.join('games', 'tictactoe', 'human_player')
|
3
|
+
require File.join('games', 'tictactoe', 'computer_player_expert')
|
4
|
+
require File.join('games', 'tictactoe', 'computer_player_novice')
|
4
5
|
|
5
6
|
module TTT
|
6
7
|
class PlayersFactory < Shared::PlayersFactory
|
@@ -12,9 +12,9 @@ module TTT
|
|
12
12
|
row = (display_value - 1) / number_of_rows_cols
|
13
13
|
col = (display_value - 1) % number_of_rows_cols
|
14
14
|
if row >= number_of_rows_cols || col >= number_of_rows_cols
|
15
|
-
|
15
|
+
nil
|
16
16
|
else
|
17
|
-
|
17
|
+
collection_of_squares[row][col]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -42,7 +42,7 @@ module TTT
|
|
42
42
|
collection_of_squares.each do |row|
|
43
43
|
return false if !(row.all? { |square| square.full? })
|
44
44
|
end
|
45
|
-
|
45
|
+
true
|
46
46
|
end
|
47
47
|
|
48
48
|
def any_combination_won?
|
data/lib/games/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: games_bfox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Fox
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -105,6 +105,7 @@ description: In order to play, download the gem, and type "tictactoe" or "master
|
|
105
105
|
email:
|
106
106
|
- brettfox11@gmail.com
|
107
107
|
executables:
|
108
|
+
- games
|
108
109
|
- mastermind
|
109
110
|
- setup
|
110
111
|
- tictactoe
|
@@ -114,10 +115,12 @@ files:
|
|
114
115
|
- ".gitignore"
|
115
116
|
- ".rspec"
|
116
117
|
- ".travis.yml"
|
118
|
+
- CHANGELOG.md
|
117
119
|
- Gemfile
|
118
120
|
- README.md
|
119
121
|
- Rakefile
|
120
122
|
- config/application.yml
|
123
|
+
- exe/games
|
121
124
|
- exe/mastermind
|
122
125
|
- exe/setup
|
123
126
|
- exe/tictactoe
|
@@ -145,7 +148,6 @@ files:
|
|
145
148
|
- lib/games/shared/player.rb
|
146
149
|
- lib/games/shared/player_factory.rb
|
147
150
|
- lib/games/shared/players_factory.rb
|
148
|
-
- lib/games/shared/version.rb
|
149
151
|
- lib/games/tictactoe.rb
|
150
152
|
- lib/games/tictactoe/board.rb
|
151
153
|
- lib/games/tictactoe/board_builder.rb
|
data/lib/games/shared/version.rb
DELETED