mastermind_cli 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9716e1fe50869ee4aa6920691aaad94f0a7eea3d
4
- data.tar.gz: 3f0d544d03a6d089d9ad88c53dba963b15a070ec
3
+ metadata.gz: c6a3e76719dfa755238b3ca483ca42240c6ec33f
4
+ data.tar.gz: 28646d787a143b95593ab56d8be4144c1b2c7e34
5
5
  SHA512:
6
- metadata.gz: 11c16308c6414c9182c4fb942045121da904ae2d83d96494c3c5475be38f81aae0d01a718de31ed3599b4a2fa88f279dded1e9903f169d91e614a758ed75cb12
7
- data.tar.gz: c2316594b65bb87c57b82b100335e0e4ad07618df5d7607909a5d918a932f992c54f02f6b81f775c1c765dd913f3b0fd40beca686aa6c8e60e5306d87ff06462
6
+ metadata.gz: fe9b66703cc839f24177aba3c5881db4eaaad29f451587638a951a168a43e4fe39a787eed2c624b7e86541e1ae926299c83a290f8d68722b6f500e68024c4ca2
7
+ data.tar.gz: 2b59fea5a9af717a27da4d41f12d76576215f015865b42073a49f0ca5b733c4c63307a07832a0ed1a40be73fe6ccbb90c16a848b5bc623ef05a8cbc6ce1442b4
@@ -15,7 +15,7 @@ class Board
15
15
  end
16
16
 
17
17
  def create_code
18
- @win_code = %w(r b g y)
18
+ @win_code = COLORS.sample(4)
19
19
  end
20
20
 
21
21
  def render
@@ -1,6 +1,3 @@
1
- require './board.rb'
2
- require './player.rb'
3
-
4
1
  class Mastermind
5
2
 
6
3
  def initialize
@@ -14,6 +14,7 @@ class Player
14
14
 
15
15
 
16
16
  def get_input
17
+ puts "Colors: #{@board.class::COLORS}"
17
18
  puts "Enter move: "
18
19
  arr = gets.chomp.split('')
19
20
  if input_valid?(arr)
@@ -1,3 +1,3 @@
1
1
  module MastermindCli
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastermind_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Lo
@@ -59,18 +59,6 @@ files:
59
59
  - lib/mastermind_cli/player.rb
60
60
  - lib/mastermind_cli/version.rb
61
61
  - mastermind_cli.gemspec
62
- - mastermind_cli/.gitignore
63
- - mastermind_cli/Gemfile
64
- - mastermind_cli/README.md
65
- - mastermind_cli/Rakefile
66
- - mastermind_cli/bin/console
67
- - mastermind_cli/bin/setup
68
- - mastermind_cli/lib/mastermind_cli.rb
69
- - mastermind_cli/lib/mastermind_cli/board.rb
70
- - mastermind_cli/lib/mastermind_cli/mastermind.rb
71
- - mastermind_cli/lib/mastermind_cli/player.rb
72
- - mastermind_cli/lib/mastermind_cli/version.rb
73
- - mastermind_cli/mastermind_cli.gemspec
74
62
  homepage: https://github.com/thomasjinlo/mastermind_cli.git
75
63
  licenses: []
76
64
  metadata:
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in mastermind_cli.gemspec
4
- gemspec
@@ -1,36 +0,0 @@
1
- # MastermindCli
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/mastermind_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'mastermind_cli'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install mastermind_cli
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mastermind_cli.
36
-
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "mastermind_cli"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,5 +0,0 @@
1
- require "mastermind_cli/version"
2
-
3
- module MastermindCli
4
- # Your code goes here...
5
- end
@@ -1,72 +0,0 @@
1
- class Board
2
-
3
- COLORS = %w(r b g y p o)
4
- attr_reader :win_code
5
- def initialize
6
- @board = []
7
- setup
8
- create_code
9
- end
10
-
11
- def setup
12
- 12.times do |row|
13
- @board[row] = %w(_)*4, []
14
- end
15
- end
16
-
17
- def create_code
18
- @win_code = %w(r b g y)
19
- end
20
-
21
- def render
22
- puts "~"*40
23
- (1..12).each do |row|
24
- puts "#{@board[-row][0]}#{@board[-row][1]}"
25
- puts ""
26
- end
27
- puts "~"*40
28
- end
29
-
30
- def full?(turn)
31
- turn > 11
32
- end
33
-
34
- def winning_combination?(turn)
35
- row = turn - 1
36
- @board[row][0] == @win_code
37
- end
38
-
39
- def add_move(move, row)
40
- check_feedbacks(move)
41
- @board[row] = move, @feedback
42
- end
43
-
44
- def red_feedbacks(move)
45
- 4.times do |idx|
46
- if move[idx] == @win_code[idx]
47
- @hash[idx] = "R"
48
- end
49
- end
50
- end
51
-
52
-
53
- def white_feedbacks(move)
54
- move.each do |color|
55
- 4.times do |idx|
56
- if color == @win_code[idx]
57
- @hash[idx] = "W" unless @hash.has_key?(idx)
58
- end
59
- end
60
- end
61
- end
62
-
63
- def check_feedbacks(move)
64
- @feedback = []
65
- @hash = {}
66
- red_feedbacks(move)
67
- white_feedbacks(move)
68
- @hash.each do |key, val|
69
- @feedback << val
70
- end
71
- end
72
- end
@@ -1,59 +0,0 @@
1
- require './board.rb'
2
- require './player.rb'
3
-
4
- class Mastermind
5
-
6
- def initialize
7
- @turn = 0
8
- @board = Board.new
9
- @player = Player.new(@board)
10
- end
11
-
12
- def greetings
13
- puts "="*40
14
- puts "Welcome to CLI Mastermind".center(40)
15
- puts "Made by FrenchToast".center(40)
16
- puts "Available Colors [r b g y p o]".center(40)
17
- puts "To make move, enter 4 colors".center(40)
18
- puts "For example: rbyg".center(40)
19
- puts "="*40
20
- end
21
-
22
- def play
23
- greetings
24
- until game_over?
25
- @board.render
26
- @player.make_move(@turn)
27
- @turn +=1
28
- end
29
- end
30
-
31
-
32
- def game_over?
33
- victory || lose
34
- end
35
-
36
- def victory
37
- if @board.winning_combination?(@turn)
38
- @board.render
39
- puts "Congratulations, you win!"
40
- puts "Your code was: #{@board.win_code}"
41
- return true
42
- end
43
- false
44
- end
45
-
46
- def lose
47
- if @board.full?(@turn)
48
- @board.render
49
- puts "I'm Sorry, you lose."
50
- puts "Winning combination was: #{@board.win_code}"
51
- return true
52
- end
53
- false
54
- end
55
- end
56
-
57
-
58
- game = Mastermind.new
59
- game.play
@@ -1,36 +0,0 @@
1
- class Player
2
-
3
- def initialize(board)
4
- @board = board
5
- @move = nil
6
- end
7
-
8
-
9
- def make_move(turn)
10
- row = turn
11
- get_input
12
- @board.add_move(@move, row)
13
- end
14
-
15
-
16
- def get_input
17
- puts "Enter move: "
18
- arr = gets.chomp.split('')
19
- if input_valid?(arr)
20
- @move = arr
21
- else
22
- get_input
23
- end
24
- end
25
-
26
-
27
- def input_valid?(arr)
28
- if arr.length != 4
29
- puts "Please input four letters"
30
- return false
31
- else
32
- arr.all? {|chr| @board.class::COLORS.include?(chr)}
33
- end
34
- end
35
-
36
- end
@@ -1,3 +0,0 @@
1
- module MastermindCli
2
- VERSION = "0.1.0"
3
- end
@@ -1,31 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mastermind_cli/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "mastermind_cli"
8
- spec.version = MastermindCli::VERSION
9
- spec.authors = ["Thomas Lo"]
10
- spec.email = ["thomasjinlo@gmail.com"]
11
-
12
- spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
13
- spec.description = %q{TODO: Write a longer description or delete this line.}
14
- spec.homepage = "TODO: Put your gem's website or public repo URL here."
15
-
16
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
- # delete this section to allow pushing this gem to any host.
18
- if spec.respond_to?(:metadata)
19
- spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
- else
21
- raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
- end
23
-
24
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- spec.bindir = "exe"
26
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ["lib"]
28
-
29
- spec.add_development_dependency "bundler", "~> 1.11"
30
- spec.add_development_dependency "rake", "~> 10.0"
31
- end