ttt-core 1.0.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.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +2 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +61 -0
  9. data/README.md +29 -0
  10. data/Rakefile +8 -0
  11. data/bin/run.sh +21 -0
  12. data/lib/ai_player.rb +117 -0
  13. data/lib/board.rb +87 -0
  14. data/lib/board_factory.rb +8 -0
  15. data/lib/game.rb +27 -0
  16. data/lib/player.rb +16 -0
  17. data/lib/player_factory.rb +38 -0
  18. data/lib/player_options.rb +48 -0
  19. data/lib/player_symbols.rb +16 -0
  20. data/lib/replay_option.rb +3 -0
  21. data/lib/ttt-core/version.rb +3 -0
  22. data/spec/ai_player_spec.rb +143 -0
  23. data/spec/board_factory_spec.rb +10 -0
  24. data/spec/board_spec.rb +125 -0
  25. data/spec/game_spec.rb +58 -0
  26. data/spec/player_options_spec.rb +33 -0
  27. data/spec/player_symbols_spec.rb +32 -0
  28. data/spec/replay_option_spec.rb +8 -0
  29. data/spec/spec_helper.rb +107 -0
  30. data/ttt-core-0.0.1/.gitignore +36 -0
  31. data/ttt-core-0.0.1/.rspec +2 -0
  32. data/ttt-core-0.0.1/.ruby-gemset +1 -0
  33. data/ttt-core-0.0.1/.ruby-version +1 -0
  34. data/ttt-core-0.0.1/.travis.yml +2 -0
  35. data/ttt-core-0.0.1/Gemfile +10 -0
  36. data/ttt-core-0.0.1/README.md +21 -0
  37. data/ttt-core-0.0.1/Rakefile +7 -0
  38. data/ttt-core-0.0.1/bin/run.sh +21 -0
  39. data/ttt-core-0.0.1/lib/ai_player.rb +117 -0
  40. data/ttt-core-0.0.1/lib/board.rb +87 -0
  41. data/ttt-core-0.0.1/lib/board_factory.rb +8 -0
  42. data/ttt-core-0.0.1/lib/game.rb +27 -0
  43. data/ttt-core-0.0.1/lib/player.rb +16 -0
  44. data/ttt-core-0.0.1/lib/player_factory.rb +38 -0
  45. data/ttt-core-0.0.1/lib/player_options.rb +48 -0
  46. data/ttt-core-0.0.1/lib/player_symbols.rb +16 -0
  47. data/ttt-core-0.0.1/lib/replay_option.rb +3 -0
  48. data/ttt-core-0.0.1/spec/ai_player_spec.rb +143 -0
  49. data/ttt-core-0.0.1/spec/board_factory_spec.rb +10 -0
  50. data/ttt-core-0.0.1/spec/board_spec.rb +125 -0
  51. data/ttt-core-0.0.1/spec/game_spec.rb +58 -0
  52. data/ttt-core-0.0.1/spec/player_options_spec.rb +33 -0
  53. data/ttt-core-0.0.1/spec/player_symbols_spec.rb +32 -0
  54. data/ttt-core-0.0.1/spec/replay_option_spec.rb +8 -0
  55. data/ttt-core-0.0.1/spec/spec_helper.rb +107 -0
  56. data/ttt-core.gemspec +22 -0
  57. metadata +150 -0
@@ -0,0 +1,58 @@
1
+ require 'board'
2
+ require 'game'
3
+ require 'player'
4
+ require 'player_symbols'
5
+
6
+ RSpec.describe Game do
7
+ let(:player_x_spy) { instance_double(FakePlayer).as_null_object }
8
+ let(:player_o_spy) { instance_double(FakePlayer).as_null_object }
9
+
10
+ it "continues until player is not ready" do
11
+ allow(player_x_spy).to receive(:ready?).and_return(true, false)
12
+ allow(player_o_spy).to receive(:ready?).and_return(true)
13
+
14
+ expect(player_x_spy).to receive(:choose_move).exactly(1).times.and_return(2)
15
+ expect(player_o_spy).to receive(:choose_move).exactly(1).times.and_return(8)
16
+
17
+ Game.new(Board.new, [player_x_spy, player_o_spy]).play
18
+ end
19
+
20
+ it "players take turn until there is no space on board" do
21
+ expect(player_x_spy).to receive(:choose_move).exactly(5).times.and_return(0, 1, 4, 5, 6)
22
+ expect(player_o_spy).to receive(:choose_move).exactly(4).times.and_return(2, 3, 7, 8)
23
+
24
+ Game.new(Board.new, [player_x_spy, player_o_spy]).play
25
+
26
+ end
27
+
28
+ it "game ends when a winning combination is formed" do
29
+ allow(player_x_spy).to receive(:choose_move).once.and_return(2)
30
+ allow(player_x_spy).to receive(:game_symbol).and_return(PlayerSymbols::X)
31
+
32
+ board = Board.new([PlayerSymbols::X, PlayerSymbols::X, nil, PlayerSymbols::O, nil, nil, nil, nil, nil])
33
+ updated_board = Game.new(board, [player_x_spy, player_o_spy]).play
34
+
35
+ expect(updated_board.get_symbol_at(2)).to be (PlayerSymbols::X)
36
+ expect(player_o_spy).to_not have_received(:choose_move)
37
+ end
38
+
39
+ it "game ends when there are no free spaces on the board" do
40
+ full_board = Board.new([PlayerSymbols::X, PlayerSymbols::X, PlayerSymbols::O, PlayerSymbols::O, PlayerSymbols::O, PlayerSymbols::X, PlayerSymbols::X, PlayerSymbols::O, PlayerSymbols::X])
41
+ game = Game.new(full_board, [player_x_spy, player_o_spy]).play
42
+
43
+ expect(player_o_spy).to_not have_received(:choose_move)
44
+ expect(player_x_spy).to_not have_received(:choose_move)
45
+ end
46
+ end
47
+
48
+ class FakePlayer
49
+
50
+ include Player
51
+
52
+ def choose_move(board)
53
+ end
54
+
55
+ def ready?
56
+ end
57
+ end
58
+
@@ -0,0 +1,33 @@
1
+ require 'player_options'
2
+
3
+ RSpec.describe PlayerOptions do
4
+
5
+ it "has player option Human vs Human" do
6
+ expect(PlayerOptions::HUMAN_VS_HUMAN).to eq ("Human vs Human")
7
+ end
8
+
9
+ it "has player option Human vs Ai" do
10
+ expect(PlayerOptions::HUMAN_VS_AI).to eq ("Human vs Ai")
11
+ end
12
+
13
+ it "has player option Ai vs Human" do
14
+ expect(PlayerOptions::AI_VS_HUMAN).to eq ("Ai vs Human")
15
+ end
16
+
17
+ it "has valid player option ids" do
18
+ expect(PlayerOptions::valid_ids).to eq ([1, 2, 3])
19
+ end
20
+
21
+ it "gets player type for id" do
22
+ expect(PlayerOptions::get_player_type_for_id(1)).to eq (PlayerOptions::HUMAN_VS_HUMAN)
23
+ end
24
+
25
+ it "gets player options for display" do
26
+ expect(PlayerOptions::display_player_options).to eq("(1) Human vs Human, (2) Human vs Ai, (3) Ai vs Human" )
27
+ end
28
+
29
+ it "gets all player options" do
30
+ all_expected_types = { 1 => "Human vs Human", 2=> "Human vs Ai", 3 => "Ai vs Human" }
31
+ expect(PlayerOptions::all).to eq(all_expected_types)
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'player_symbols'
2
+
3
+ RSpec.describe PlayerSymbols do
4
+
5
+ it "has player symbol X" do
6
+ expect(PlayerSymbols::X).to be :X
7
+ end
8
+
9
+ it "has player symbol O" do
10
+ expect(PlayerSymbols::O).to be :O
11
+ end
12
+
13
+ it "finds opponent of X" do
14
+ expect(PlayerSymbols::opponent(PlayerSymbols::X)).to be :O
15
+ end
16
+
17
+ it "finds opponent of O" do
18
+ expect(PlayerSymbols::opponent(PlayerSymbols::O)).to be :X
19
+ end
20
+
21
+ it "all player symbols as strings" do
22
+ expect(PlayerSymbols::all).to eq ["X", "O"]
23
+ end
24
+
25
+ it "converts X to player symbol" do
26
+ expect(PlayerSymbols::to_symbol("X")).to eq :X
27
+ end
28
+
29
+ it "converts O to player symbol" do
30
+ expect(PlayerSymbols::to_symbol("O")).to eq :O
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ require 'replay_option'
2
+
3
+ RSpec.describe ReplayOption do
4
+
5
+ it "has replay option of Y" do
6
+ expect(ReplayOption::Y.include?("Y")).to be true
7
+ end
8
+ end
@@ -0,0 +1,107 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'simplecov'
21
+ require 'coveralls'
22
+
23
+ Coveralls.wear!
24
+ SimpleCov.minimum_coverage 100
25
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
26
+ SimpleCov::Formatter::HTMLFormatter,
27
+ Coveralls::SimpleCov::Formatter
28
+ ])
29
+ RSpec.configure do |config|
30
+ # rspec-expectations config goes here. You can use an alternate
31
+ # assertion/expectation library such as wrong or the stdlib/minitest
32
+ # assertions if you prefer.
33
+ config.expect_with :rspec do |expectations|
34
+ # This option will default to `true` in RSpec 4. It makes the `description`
35
+ # and `failure_message` of custom matchers include text for helper methods
36
+ # defined using `chain`, e.g.:
37
+ # be_bigger_than(2).and_smaller_than(4).description
38
+ # # => "be bigger than 2 and smaller than 4"
39
+ # ...rather than:
40
+ # # => "be bigger than 2"
41
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
42
+ end
43
+
44
+ # rspec-mocks config goes here. You can use an alternate test double
45
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
46
+ config.mock_with :rspec do |mocks|
47
+ # Prevents you from mocking or stubbing a method that does not exist on
48
+ # a real object. This is generally recommended, and will default to
49
+ # `true` in RSpec 4.
50
+ mocks.verify_partial_doubles = true
51
+ mocks.verify_doubled_constant_names = true
52
+ end
53
+
54
+ # The settings below are suggested to provide a good initial experience
55
+ # with RSpec, but feel free to customize to your heart's content.
56
+ =begin
57
+ # These two settings work together to allow you to limit a spec run
58
+ # to individual examples or groups you care about by tagging them with
59
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
60
+ # get run.
61
+ config.filter_run :focus
62
+ config.run_all_when_everything_filtered = true
63
+
64
+ # Allows RSpec to persist some state between runs in order to support
65
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
66
+ # you configure your source control system to ignore this file.
67
+ config.example_status_persistence_file_path = "spec/examples.txt"
68
+
69
+ # Limits the available syntax to the non-monkey patched syntax that is
70
+ # recommended. For more details, see:
71
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
72
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
73
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
74
+ config.disable_monkey_patching!
75
+
76
+ # This setting enables warnings. It's recommended, but in some cases may
77
+ # be too noisy due to issues in dependencies.
78
+ config.warnings = true
79
+
80
+ # Many RSpec users commonly either run the entire suite or an individual
81
+ # file, and it's useful to allow more verbose output when running an
82
+ # individual spec file.
83
+ if config.files_to_run.one?
84
+ # Use the documentation formatter for detailed output,
85
+ # unless a formatter has already been configured
86
+ # (e.g. via a command-line flag).
87
+ config.default_formatter = 'doc'
88
+ end
89
+
90
+ # Print the 10 slowest examples and example groups at the
91
+ # end of the spec run, to help surface which specs are running
92
+ # particularly slow.
93
+ config.profile_examples = 10
94
+
95
+ # Run specs in random order to surface order dependencies. If you find an
96
+ # order dependency and want to debug it, you can fix the order by providing
97
+ # the seed, which is printed after each run.
98
+ # --seed 1234
99
+ config.order = :random
100
+
101
+ # Seed global randomization in this process using the `--seed` CLI option.
102
+ # Setting this allows you to use `--seed` to deterministically reproduce
103
+ # test failures related to randomization by passing the same `--seed` value
104
+ # as the one that triggered the failure.
105
+ Kernel.srand config.seed
106
+ =end
107
+ end
data/ttt-core.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $:.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ttt-core/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ttt-core"
7
+ spec.version = TTTCore::VERSION
8
+ spec.authors = ["Georgina McFadyen"]
9
+ spec.email = ["gemcfadyen@hotmail.com"]
10
+ spec.description = "Tic Tac Toe Rules to be used in conjunction with a front end"
11
+ spec.summary = "Tic Tac Toe Rules"
12
+ spec.homepage = "https://github.com/gemcfadyen/Apprenticeship-RubyTicTacToe"
13
+ spec.license = 'MIT'
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.11'
20
+ spec.add_development_dependency 'rake', '10.5'
21
+ spec.add_development_dependency 'rspec', '~> 3.4'
22
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ttt-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Georgina McFadyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: '10.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: Tic Tac Toe Rules to be used in conjunction with a front end
56
+ email:
57
+ - gemcfadyen@hotmail.com
58
+ executables:
59
+ - run.sh
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".ruby-version"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - README.md
71
+ - Rakefile
72
+ - bin/run.sh
73
+ - lib/ai_player.rb
74
+ - lib/board.rb
75
+ - lib/board_factory.rb
76
+ - lib/game.rb
77
+ - lib/player.rb
78
+ - lib/player_factory.rb
79
+ - lib/player_options.rb
80
+ - lib/player_symbols.rb
81
+ - lib/replay_option.rb
82
+ - lib/ttt-core/version.rb
83
+ - spec/ai_player_spec.rb
84
+ - spec/board_factory_spec.rb
85
+ - spec/board_spec.rb
86
+ - spec/game_spec.rb
87
+ - spec/player_options_spec.rb
88
+ - spec/player_symbols_spec.rb
89
+ - spec/replay_option_spec.rb
90
+ - spec/spec_helper.rb
91
+ - ttt-core-0.0.1/.gitignore
92
+ - ttt-core-0.0.1/.rspec
93
+ - ttt-core-0.0.1/.ruby-gemset
94
+ - ttt-core-0.0.1/.ruby-version
95
+ - ttt-core-0.0.1/.travis.yml
96
+ - ttt-core-0.0.1/Gemfile
97
+ - ttt-core-0.0.1/README.md
98
+ - ttt-core-0.0.1/Rakefile
99
+ - ttt-core-0.0.1/bin/run.sh
100
+ - ttt-core-0.0.1/lib/ai_player.rb
101
+ - ttt-core-0.0.1/lib/board.rb
102
+ - ttt-core-0.0.1/lib/board_factory.rb
103
+ - ttt-core-0.0.1/lib/game.rb
104
+ - ttt-core-0.0.1/lib/player.rb
105
+ - ttt-core-0.0.1/lib/player_factory.rb
106
+ - ttt-core-0.0.1/lib/player_options.rb
107
+ - ttt-core-0.0.1/lib/player_symbols.rb
108
+ - ttt-core-0.0.1/lib/replay_option.rb
109
+ - ttt-core-0.0.1/spec/ai_player_spec.rb
110
+ - ttt-core-0.0.1/spec/board_factory_spec.rb
111
+ - ttt-core-0.0.1/spec/board_spec.rb
112
+ - ttt-core-0.0.1/spec/game_spec.rb
113
+ - ttt-core-0.0.1/spec/player_options_spec.rb
114
+ - ttt-core-0.0.1/spec/player_symbols_spec.rb
115
+ - ttt-core-0.0.1/spec/replay_option_spec.rb
116
+ - ttt-core-0.0.1/spec/spec_helper.rb
117
+ - ttt-core.gemspec
118
+ homepage: https://github.com/gemcfadyen/Apprenticeship-RubyTicTacToe
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.6
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Tic Tac Toe Rules
142
+ test_files:
143
+ - spec/ai_player_spec.rb
144
+ - spec/board_factory_spec.rb
145
+ - spec/board_spec.rb
146
+ - spec/game_spec.rb
147
+ - spec/player_options_spec.rb
148
+ - spec/player_symbols_spec.rb
149
+ - spec/replay_option_spec.rb
150
+ - spec/spec_helper.rb