mastermind_adeybee 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04c513edae19bfedb3803d37e0f51b5962eb3d9b
4
- data.tar.gz: 9b386735c76317f7b540f996012a42b163daddf7
3
+ metadata.gz: 6eb4747b042aa4dc8c689562c2c716b21ed75ccf
4
+ data.tar.gz: a10b302eda7f628d8e60c8798f8fdd8c1eebd319
5
5
  SHA512:
6
- metadata.gz: 8bf73548e9b7d6a466efdd150f896810ca2575fba7fa2302c91d029fc9f4bce798852714813d9c4f1f131512176992d4ad3f998a78c7edf0a1a9d7fbf4d146dc
7
- data.tar.gz: 7f76fb62c18cbc4c71ae33dff0d5409e7e9df5218574918a436b4e9c4ff177c1161e46513bfaeaf92a593a42b6025ef0b345eb939ecd00693405fc78e8b12461
6
+ metadata.gz: abf9a2d50e254385dfe50679d76c98fa45df3ee70722ff160da92981c9d880abe4c95ac74ac67533d3422ee2969371ee1f763daaeb10a7cdddbddcef5a93ab0c
7
+ data.tar.gz: bdfbe1ac1d762d759ff73d5550170b421370b5804f3cfc2f7302f56d3864eed33dd8702e624477a88be28613a6a2e74d70ef1585ef1d076b3913fcfb0698ac23
data/.coveralls.yml CHANGED
@@ -1,2 +1,2 @@
1
- service_name: travis-pro
1
+ service_name: travis-ci
2
2
  repo_token: TXgIca5SMDkP8jLXJ8Tuha4QLQhcQxWyk
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ game_results.txt
11
+ *.txt
data/.travis.yml CHANGED
@@ -2,3 +2,5 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.3
4
4
  before_install: gem install bundler -v 1.10.6
5
+ after_success:
6
+ - coveralls
data/README.md CHANGED
@@ -4,7 +4,9 @@ Lets a see how good you are at guessing. You are required to guess or figure out
4
4
 
5
5
  You have twelve rounds to figure out the computer's mind. If you do not guess right in twelve rounds, you loose. ): You can use 'h' to get hints. This is limited by your difficulty level.
6
6
  Enjoy! :)
7
- <img src="https://coveralls.io/repos/andela-aadepoju/Mastermind/badge.svg?branch=master&service=github" alt="Coverage Status" />
7
+
8
+ [![Coverage Status](https://coveralls.io/repos/andela-aadepoju/Mastermind/badge.svg?branch=master&service=github)](https://coveralls.io/github/andela-aadepoju/Mastermind?branch=master)
9
+
8
10
  ## Installation
9
11
 
10
12
  Add this line to your application's Gemfile:
@@ -34,7 +36,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
36
 
35
37
  ## Contributing
36
38
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mastermind. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andela-aadepoju/mastermind. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
38
40
 
39
41
 
40
42
  ## License
data/bin/game_results.txt CHANGED
@@ -1,8 +1,52 @@
1
- bayo finished the game with ["y", "y", "y", "b"] within 7 rounds in 22 seconds
2
- bayo finished the game with ["g", "b", "g", "g"] within 8 rounds in 42 seconds
3
- adeybee finished the game with ["r", "y", "r", "r"] within 5 rounds in 22 seconds
4
- adeybee finished the game with ["r", "g", "g", "r"] within 5 rounds in 13 seconds
5
- bayo finished the game with ["y", "y", "g", "y"] within 5 rounds in seconds
6
- bayo finished the game with ["g", "y", "r", "g"] within 7 rounds in seconds
7
- bayo finished the game with ["y", "y", "r", "r"] within 3 rounds in 15 seconds
8
- adebayo finished the game with ["r", "g", "g", "b"] within 10 rounds in 61 seconds
1
+ ****************************Top 10***************************
2
+ adebayo guessed the sequence ["y", "b", "b", "b"] in 8 rounds within 46 seconds
3
+ ade guessed the sequence ["g", "b", "g", "y"] in 7 rounds within 40 seconds
4
+ adebayo guessed the sequence ["g", "g", "r", "r"] in 8 rounds within 38 seconds
5
+ lawrence guessed the sequence ["y", "b", "b", "y"] in 6 rounds within 41 seconds
6
+ lawrence guessed the sequence ["b", "g", "r", "g"] in 11 rounds within 153 seconds
7
+ adebayo guessed the sequence ["r", "r", "r", "y"] in 4 rounds within 20 seconds
8
+ adebayo guessed the sequence ["r", "r", "g", "b"] in 6 rounds within 37 seconds
9
+ adebayo guessed the sequence ["b", "g", "g", "r"] in 1 rounds within 4 seconds
10
+ ade guessed the sequence ["b", "r", "b", "b"] in 6 rounds within 27 seconds
11
+ ade guessed the sequence ["b", "b", "y", "b"] in 5 rounds within 20 seconds
12
+ ade guessed the sequence ["y", "g", "r", "g"] in 5 rounds within 20 seconds
13
+ ade guessed the sequence ["b", "b", "b", "r"] in 4 rounds within 14 seconds
14
+ ade guessed the sequence ["b", "r", "b", "y"] in 9 rounds within 36 seconds
15
+ ade guessed the sequence ["y", "g", "b", "b"] in 6 rounds within 23 seconds
16
+ ade guessed the sequence ["g", "r", "g", "g"] in 3 rounds within 13 seconds
17
+ ade guessed the sequence ["y", "b", "r", "y"] in 4 rounds within 14 seconds
18
+ ade guessed the sequence ["g", "y", "b", "g"] in 6 rounds within 42 seconds
19
+ ade guessed the sequence ["y", "b", "r", "y"] in 5 rounds within 19 seconds
20
+ ade guessed the sequence ["r", "y", "b", "y"] in 9 rounds within 51 seconds
21
+ ade guessed the sequence ["g", "g", "r", "g"] in 4 rounds within 17 seconds
22
+ ade guessed the sequence ["y", "g", "b", "y"] in 5 rounds within 19 seconds
23
+ ade guessed the sequence ["y", "r", "b", "y"] in 5 rounds within 23 seconds
24
+ ade guessed the sequence ["g", "b", "r", "g"] in 4 rounds within 13 seconds
25
+ ade guessed the sequence ["g", "y", "r", "g"] in 5 rounds within 18 seconds
26
+ adebee guessed the sequence ["g", "b", "g", "r"] in 7 rounds within 41 seconds
27
+ ade guessed the sequence ["g", "r", "y", "y"] in 5 rounds within 21 seconds
28
+ ade guessed the sequence ["y", "g", "r", "r"] in 6 rounds within 24 seconds
29
+ ade guessed the sequence ["g", "y", "r", "y"] in 5 rounds within 14 seconds
30
+ ade guessed the sequence ["y", "y", "g", "y"] in 6 rounds within 27 seconds
31
+ ade guessed the sequence ["g", "g", "b", "g"] in 4 rounds within 17 seconds
32
+ ade guessed the sequence ["r", "g", "g", "g"] in 6 rounds within 17 seconds
33
+ ade guessed the sequence ["g", "g", "r", "b"] in 4 rounds within 13 seconds
34
+ ade guessed the sequence ["r", "r", "b", "y"] in 4 rounds within 12 seconds
35
+ ade guessed the sequence ["r", "b", "y", "g"] in 7 rounds within 27 seconds
36
+ ade guessed the sequence ["b", "b", "b", "r"] in 4 rounds within 12 seconds
37
+ ade guessed the sequence ["g", "y", "b", "g"] in 6 rounds within 23 seconds
38
+ ade guessed the sequence ["g", "y", "b", "r"] in 8 rounds within 30 seconds
39
+ ade guessed the sequence ["g", "y", "b", "b"] in 10 rounds within 68 seconds
40
+ ade guessed the sequence ["b", "b", "y", "r"] in 9 rounds within 46 seconds
41
+ adebayo guessed the sequence ["b", "y", "b", "r"] in 6 rounds within 36 seconds
42
+ ade guessed the sequence ["b", "g", "y", "r"] in 7 rounds within 26 seconds
43
+ ade guessed the sequence ["r", "g", "g", "r"] in 5 rounds within 19 seconds
44
+ bayo guessed the sequence ["b", "b", "g", "y"] in 4 rounds within 18 seconds
45
+ adebayo guessed the sequence ["b", "g", "b", "y"] in 11 rounds within 84 seconds
46
+ bayo guessed the sequence ["g", "y", "g", "y"] in 5 rounds within 31 seconds
47
+ ade guessed the sequence ["b", "b", "g", "g"] in 4 rounds within 34 seconds
48
+ ade guessed the sequence ["y", "b", "g", "b"] in 8 rounds within 37 seconds
49
+ ade guessed the sequence ["y", "b", "r", "g"] in 8 rounds within 47 seconds
50
+ adebayo guessed the sequence ["g", "b", "g", "g"] in 3 rounds within 19 seconds
51
+ ade guessed the sequence ["b", "y", "y", "r"] in 8 rounds within 32 seconds
52
+ adebayo guessed the sequence ["b", "m", "g", "b", "m", "b"] in 8 rounds within 73 seconds
data/bin/mastermind CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
3
+ require "bundler/setup"
4
4
  require "mastermind"
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
@@ -14,7 +14,7 @@ require "mastermind"
14
14
  #IRB.start
15
15
 
16
16
  module Mastermind
17
- starter = Starter.new
18
- starter.welcome
19
- starter.ask
17
+ game = Game_Engine.new
18
+ game.welcome
19
+ game.ask
20
20
  end
@@ -1,5 +1,4 @@
1
1
  require "colorize"
2
- require_relative "main"
3
2
  module Mastermind
4
3
 
5
4
  class Code_generator
@@ -0,0 +1,30 @@
1
+ require "colorize"
2
+ require_relative 'input'
3
+
4
+ module Mastermind
5
+ module Difficulty
6
+
7
+ def difficulty(msg)
8
+ puts "#{msg.difficulty_select}"
9
+ input = user_input
10
+ case
11
+ when input == "b"
12
+ puts "#{msg.beginer_msg}"
13
+ return col = 0
14
+ when input == "m"
15
+ puts "#{msg.intermidiate_msg}"
16
+ return col = 2
17
+ when input == "a"
18
+ puts "#{msg.advance_msg}"
19
+ return col = 4
20
+ else
21
+ puts "#{msg.invalid_entry_msg}"
22
+ non_valid(msg)
23
+ end
24
+ end
25
+
26
+ def non_valid(msg)
27
+ difficulty(msg)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,141 @@
1
+ require_relative 'input'
2
+ require_relative 'difficulty'
3
+
4
+ module Mastermind
5
+ class Game_Engine
6
+ include Input
7
+ include Difficulty
8
+ attr_reader :status, :player, :counter, :final_time,
9
+ :start_time ,:computer_code, :leaderboard
10
+
11
+ attr_writer :counter
12
+
13
+ def initialize
14
+ @player = Player.new
15
+ @msg = Message.new
16
+ @start_time = 0
17
+ @counter = 0
18
+ end
19
+
20
+ def welcome
21
+ puts "#{@msg.logo}"
22
+ puts "#{@msg.welcome_msg}"
23
+ end
24
+
25
+ def instructions
26
+ puts "#{@msg.instruction_msg}"
27
+ ask
28
+ end
29
+
30
+ def ask
31
+ puts "#{@msg.play_msg}"
32
+ input = user_input
33
+ case
34
+ when input == "l"
35
+ leaderboard
36
+ when input == "p"
37
+ game
38
+ when input == "q"
39
+ puts "#{@msg.quit_msg}"
40
+ exit
41
+ when input == "i"
42
+ instructions
43
+ else
44
+ invalid
45
+ end
46
+ end
47
+
48
+ def invalid
49
+ puts "#{@msg.invalid_entry_msg}"
50
+ ask
51
+ end
52
+
53
+ def exact_match(ccode, player_input)
54
+ exact = 0 ; i = 0 ; comp_copy = ccode.dup
55
+ while i < comp_copy.length
56
+ if comp_copy[i] == player_input[i]
57
+ exact += 1 ; comp_copy[i] = 0
58
+ end
59
+ i += 1
60
+ end
61
+ [comp_copy, exact]
62
+ end
63
+
64
+ def partial_match(comp_copy, player_input)
65
+ sec_copy = comp_copy.dup ; i = 0 ; partial = 0
66
+ while i < sec_copy.length
67
+ part = sec_copy.index(player_input[i])
68
+ if !!sec_copy[i] != 0 && !! part
69
+ partial += 1 ; sec_copy[part] = 0
70
+ end
71
+ i += 1
72
+ end
73
+ partial
74
+ end
75
+
76
+ def game
77
+ @player.h_num = 0
78
+ col = difficulty(@msg)
79
+ @computer_code = Code_generator.new.computer_choice(col)
80
+ @start_time = Time.now
81
+ loop do
82
+ @player_input = @player.player_entry(col, @computer_code)
83
+ exact = exact_match(@computer_code, @player_input)
84
+ partial = partial_match(exact[0], @player_input)
85
+ @counter += 1
86
+ analysis(@player_input, exact[1], partial)
87
+ break if exact[1] == exact[0].length
88
+ end
89
+ winner
90
+ end
91
+
92
+
93
+ def analysis(player_input, exact, partial)
94
+ puts "#{@msg.rounds(player_input, @counter)}"
95
+ puts "#{@msg.result(exact,partial)}"
96
+ try_again(exact, partial) if @counter >= 12
97
+ end
98
+
99
+
100
+ def winner
101
+ @final_time = (Time.now - @start_time).to_i
102
+ puts "#{@msg.win_msg(@final_time, @counter, @computer_code)}"
103
+ namer ; save_file; @counter = 0
104
+ ask
105
+ end
106
+
107
+
108
+ def try_again(exact, partial)
109
+ @final_time = (Time.now - @start_time).to_i
110
+ puts "#{@msg.game_over_msg(@computer_code, @final_time)}"
111
+ @counter = 0
112
+ ask
113
+ end
114
+
115
+
116
+ def namer
117
+ puts "#{@msg.namer_msg}"
118
+ @name = user_input
119
+ end
120
+
121
+
122
+ def save_file(filename = "game_results.txt")
123
+ File.open(filename, "a+") do | line |
124
+ line.puts "#{@msg.leader_msg(@name, @computer_code, @counter, @final_time)}"
125
+ end
126
+ end
127
+
128
+ def leaderboard(filename = "game_results.txt" )
129
+ lead_arr = []
130
+ File.open(filename, "r") do | lines |
131
+ lines.each_line do |text|
132
+ lead_arr << text
133
+ @leader = lead_arr.sort_by { |line| Result.new(line)}
134
+ end
135
+ end
136
+ puts "#{@leader.first(10).join.to_s}"
137
+ ask
138
+ end
139
+
140
+ end #end class
141
+ end #end module
@@ -0,0 +1,8 @@
1
+
2
+ module Mastermind
3
+ module Input
4
+ def user_input
5
+ gets.chomp.downcase
6
+ end
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  module Mastermind
2
2
  class Message
3
- # attribute readers
3
+
4
4
  def initialize
5
5
  @red = "(r)ed".colorize(:color =>:red)
6
6
  @green = "(g)reen".colorize(:color =>:green)
@@ -18,6 +18,22 @@ module Mastermind
18
18
  "Your input is too short"
19
19
  end
20
20
 
21
+ def result(exact, partial)
22
+ "You have #{exact} exact match(es) and #{partial} partial match(es)"
23
+ end
24
+
25
+ def leader_msg(name, computer_code, counter, final_time)
26
+ "#{name} guessed the sequence #{computer_code} in #{counter} rounds within #{final_time} seconds"
27
+ end
28
+
29
+ def rounds(player_input, counter)
30
+ "You played #{player_input}. Round #{counter} 0f 12"
31
+ end
32
+
33
+ def comp_choice_msg(computer_code)
34
+ "The computer chose #{computer_code}"
35
+ end
36
+
21
37
  def difficulty_select
22
38
  "Select difficulty level, (b)eginner, (m)medium or (a)dvance"
23
39
  end
@@ -27,7 +43,7 @@ module Mastermind
27
43
  end
28
44
 
29
45
  def play_msg
30
- "Would you like to(p)lay, read the (i)nstructions or (q)uit?"
46
+ "Press (p) to play, (i) to read the instructions, (l) to view leaderboard or (q) to quit?"
31
47
  end
32
48
 
33
49
  def beginer_msg
@@ -42,30 +58,24 @@ module Mastermind
42
58
  "I have generated an advance sequence with eight elements made up of: #{@red}, #{@green}, #{@blue}, #{@yellow}, #{@cyan}, and #{@magenta}. Use (h) to get hints, you have 5 hint. Use (q)uit at any time to end the game."
43
59
  end
44
60
 
45
- def continue_msg
46
- "Press 'p' to play or 'q' to quit."
61
+ def hint_msg(h, computer_code)
62
+ "#{computer_code[h - 1]} is at position #{h} in the computer's choice"
47
63
  end
48
64
 
49
- def win_msg
50
- "********** You Win!!! **********"
65
+ def win_msg(final_time, counter, computer_code)
66
+ "********** You Win!!! **********
67
+ You won in #{final_time} seconds within #{counter} rounds
68
+ The computer chose #{computer_code}"
51
69
  end
52
70
 
53
71
  def bye
54
72
  "Thanks for playing! :)"
55
73
  end
56
74
 
57
- def loose_msg
58
- ":( You Loose ):"
59
- end
60
-
61
75
  def hint_exceeded_msg
62
76
  "You have exceeded your hint limit"
63
77
  end
64
78
 
65
- def play_again
66
- "Would you like to (p)lay again? or (q)uit"
67
- end
68
-
69
79
  def name_msg
70
80
  "Enter your Name!"
71
81
  end
@@ -82,8 +92,11 @@ module Mastermind
82
92
  "Invalid entry, try again"
83
93
  end
84
94
 
85
- def game_over_msg
86
- "Game Over!"
95
+ def game_over_msg(computer_code, final_time)
96
+ "Game Over!
97
+ :( You Loose ):
98
+ The computer chose #{computer_code}
99
+ You played the game for #{final_time} seconds"
87
100
  end
88
101
 
89
102
  def instruction_msg
@@ -105,6 +118,6 @@ module Mastermind
105
118
  | |___ ___| |_ ___ ___| |_|___ _| |
106
119
  | | | | .'|_ -| _| -_| _| | | | | | . |
107
120
  |_|_|_|__,|___|_| |___|_| |_|_|_|_|_|_|___|"
121
+ end
108
122
  end
109
- end
110
- end
123
+ end
@@ -0,0 +1,70 @@
1
+ require_relative 'input'
2
+
3
+ module Mastermind
4
+
5
+ class Player
6
+
7
+ include Input
8
+ attr_writer :h_num
9
+ attr_reader :input
10
+
11
+ def initialize
12
+ @h_num = 0
13
+ @msg = Message.new
14
+ @code = ["r","g","b","y","c","m"]
15
+ end
16
+
17
+
18
+ def is_valid?(incode)
19
+ arr = []
20
+ for i in incode
21
+ arr << i if @code.include?(i)
22
+ end
23
+ arr
24
+ true if arr == incode
25
+ end
26
+
27
+
28
+ def player_entry(col, computer_code)
29
+ input = user_input
30
+ case
31
+ when input == "q"
32
+ puts "#{@msg.quit_msg}"
33
+ exit
34
+ when input == "h"
35
+ if @h_num < col + 1
36
+ @h_num += 1
37
+ hint(col, computer_code)
38
+ else
39
+ puts "#{@msg.hint_exceeded_msg}"
40
+ invalid(col, computer_code)
41
+ end
42
+ when input.length > 4 + col
43
+ puts "#{@msg.too_long}"
44
+ invalid(col, computer_code)
45
+ when input.length < 4 + col
46
+ puts "#{@msg.too_short}"
47
+ invalid(col, computer_code)
48
+ when is_valid?(input.split(//))
49
+ input = input.split(//)
50
+ else
51
+ puts "#{@msg.invalid_entry_msg}"
52
+ invalid(col,computer_code)
53
+ end
54
+ end
55
+
56
+ def invalid(col,computer_code)
57
+ player_entry(col,computer_code)
58
+ end
59
+
60
+
61
+
62
+ def hint(col, computer_code)
63
+ h = rand(1..4)
64
+ puts "#{@msg.hint_msg(h, computer_code)}"
65
+ h = rand(1..4)
66
+ player_entry(col,computer_code)
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ module Mastermind
2
+ class Result
3
+ attr_accessor :line
4
+ def initialize(line)
5
+ @line = line
6
+ end
7
+
8
+ def <=>(other)
9
+ score <=> other.score
10
+ end
11
+
12
+ def score
13
+ [rounds, seconds]
14
+ end
15
+
16
+ def rounds
17
+ @line[/\d+ rounds/].to_i
18
+ end
19
+
20
+ def seconds
21
+ @line[/\d+ seconds/].to_i
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Mastermind
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/mastermind.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require_relative "mastermind/version"
2
2
  require "colorize"
3
- require_relative "input"
4
- require_relative "messages"
5
- require_relative "main"
6
- require_relative "player"
7
- require_relative "computer"
8
- require_relative "game_engine"
3
+ require_relative "mastermind/input"
4
+ require_relative "mastermind/messages"
5
+ require_relative "mastermind/player"
6
+ require_relative "mastermind/computer"
7
+ require_relative "mastermind/game_engine"
8
+ require_relative "mastermind/result"
9
+ require_relative "mastermind/difficulty"
9
10
 
10
11
 
11
12
  module Mastermind
data/mastermind.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Mastermind is a game where you will guess the the colours the computer has in mind.}
13
13
  spec.description = %q{Mastermind is a game where you will guess the the colours the computer has in mind. You will be told if you guess correctly or not. You will have too guess in the same order as the computer to win. Enjoy! :)}
14
- spec.homepage = "http://www.mradeybee.com/mastermind"
14
+ spec.homepage = "https://github.com/andela-aadepoju/Mastermind"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastermind_adeybee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adepoju Adebayo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2015-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -172,22 +172,16 @@ files:
172
172
  - bin/game_results.txt
173
173
  - bin/mastermind
174
174
  - bin/setup
175
- - game_results.txt
176
- - lib/computer.rb
177
- - lib/game_engine.rb
178
- - lib/game_results.txt
179
- - lib/game_results.txt~
180
- - lib/input.rb
181
- - lib/main.rb
182
175
  - lib/mastermind.rb
176
+ - lib/mastermind/computer.rb
177
+ - lib/mastermind/difficulty.rb
178
+ - lib/mastermind/game_engine.rb
179
+ - lib/mastermind/input.rb
180
+ - lib/mastermind/messages.rb
181
+ - lib/mastermind/player.rb
182
+ - lib/mastermind/result.rb
183
183
  - lib/mastermind/version.rb
184
- - lib/messages.rb
185
- - lib/player.rb
186
- - mastermind-0.1.0.gem
187
- - mastermind-0.1.1.gem
188
184
  - mastermind.gemspec
189
- - mastermind_adeybee-0.1.1.gem
190
- - mastermind_adeybee-0.1.2.gem
191
185
  - vendor/bundle/ruby/2.2.0/bin/_guard-core
192
186
  - vendor/bundle/ruby/2.2.0/bin/cdiff
193
187
  - vendor/bundle/ruby/2.2.0/bin/coderay
@@ -2545,7 +2539,7 @@ files:
2545
2539
  - vendor/bundle/ruby/2.2.0/specifications/tins-1.6.0.gemspec
2546
2540
  - vendor/bundle/ruby/2.2.0/specifications/unf-0.1.4.gemspec
2547
2541
  - vendor/bundle/ruby/2.2.0/specifications/unf_ext-0.0.7.1.gemspec
2548
- homepage: http://www.mradeybee.com/mastermind
2542
+ homepage: https://github.com/andela-aadepoju/Mastermind
2549
2543
  licenses:
2550
2544
  - MIT
2551
2545
  metadata:
data/game_results.txt DELETED
@@ -1 +0,0 @@
1
- bayo finished the game with ["g", "g", "r", "r", "m", "y"] within 11 rounds in 130 seconds
data/lib/game_engine.rb DELETED
@@ -1,128 +0,0 @@
1
- require 'pry'
2
- module Mastermind
3
-
4
- class Game_Engine
5
- attr_reader :status, :player, :counter, :final_time, :start_time ,:computer_code
6
- def initialize(col)
7
- starter = Starter.new
8
- @computer_code = Code_generator.new.computer_choice(col)
9
- @player = Player.new
10
- @msg = Message.new
11
- @status = :started
12
- @start_time = 0
13
- end
14
-
15
- def exact_match(ccode, player_input)
16
- exact = 0
17
- i = 0
18
- comp_copy = ccode.dup
19
- while i < comp_copy.length
20
- if comp_copy[i] == player_input[i]
21
- exact += 1
22
- comp_copy[i] = 0
23
- end
24
- i += 1
25
- end
26
- [comp_copy, exact]
27
- end
28
-
29
-
30
-
31
- def partial_match(comp_copy, player_input)
32
- sec_copy = comp_copy.dup
33
- i = 0
34
- partial = 0
35
- while i < sec_copy.length
36
- part = sec_copy.index(player_input[i])
37
- if !!sec_copy[i] != 0 && !! part
38
- partial += 1
39
- sec_copy[part] = 0
40
- end
41
- i += 1
42
- end
43
- partial
44
- end
45
-
46
-
47
-
48
- def replay
49
- puts "#{@msg.play_again}"
50
- player_input = Input.new.user_input
51
- if player_input == "p"
52
- Starter.new.difficulty
53
- elsif player_input =="q"
54
- puts "#{@msg.bye}"
55
- exit
56
- else
57
- puts "#{@msg.invalid_entry_msg}"
58
- replay
59
- end
60
- end
61
-
62
-
63
-
64
- def game(col)
65
- @counter = 0
66
- @start_time = Time.now
67
- loop do
68
- @player_input = @player.player_entry(col, @computer_code)
69
- exact = exact_match(@computer_code, @player_input)
70
- partial = partial_match(exact[0], @player_input)
71
- @counter += 1
72
- analysis(@player_input, exact[1], partial)
73
- break if exact[1] == exact[0].length
74
- end
75
- winner(col)
76
- end
77
-
78
-
79
- def analysis(player_input, exact, partial)
80
- puts "You played #{player_input}. Round #{@counter} 0f 12"
81
- try_again(exact, partial)
82
- end
83
-
84
-
85
- def winner(col)
86
- @final_time = (Time.now - @start_time).to_i
87
- puts "#{@msg.win_msg}
88
- You won in #{@final_time} seconds within #{@counter} rounds
89
- The computer chose #{@computer_code}"
90
- @status = :winner
91
- namer ; save_file ;leaderboard ; replay
92
- end
93
-
94
-
95
- def try_again(exact, partial)
96
- @final_time = (Time.now - @start_time).to_i
97
- puts "
98
- You have #{exact} exact match(es) and #{partial} partial match(es)"
99
- if @counter >= 12
100
- puts "#{@msg.game_over_msg} #{@msg.loose_msg}
101
- The computer chose #{@computer_code}
102
- You played the game for #{@final_time} seconds"
103
- replay
104
- end
105
- end
106
-
107
- def namer
108
- puts "#{@msg.namer_msg}"
109
- @name = Input.new.user_input
110
- end
111
-
112
- def save_file
113
- File.open("game_results.txt", "a+") do | line |
114
- line.puts "#{@name} finished the game with #{@player_input} within #{@counter} rounds in #{@final_time} seconds"
115
- end
116
- end
117
-
118
- def leaderboard
119
- File.open("game_results.txt", "r+") do | line |
120
- line.each_line do |text|
121
- puts text
122
- end
123
- end
124
- end
125
-
126
-
127
- end #end class
128
- end #end module
data/lib/game_results.txt DELETED
@@ -1 +0,0 @@
1
- adebayo finished the game with ["g", "y", "b", "b"] in 14 seconds
@@ -1,6 +0,0 @@
1
- bayo finiished the game with ["g", "g", "g", "b"] in 44 seconds
2
- oscar finiished the game with ["y", "y", "g", "g"] in 17 seconds
3
- bayo finiished the game with ["b", "g", "r", "g"] in 40 seconds
4
- baayo finiished the game with ["g", "b", "y", "y"] in 18 seconds
5
- bayo finiished the game with ["b", "r", "g", "g"] in 35 seconds
6
- adeybee finiished the game with ["r", "b", "b", "r"] in 22 seconds
data/lib/input.rb DELETED
@@ -1,13 +0,0 @@
1
- module Mastermind
2
-
3
- ####################################
4
- #This is the user input class. All
5
- # inputs from the user is generated
6
- # by this class
7
- #####################################
8
- class Input
9
- def user_input
10
- input = gets.chomp.downcase
11
- end
12
- end
13
- end
data/lib/main.rb DELETED
@@ -1,69 +0,0 @@
1
- require "colorize"
2
- module Mastermind
3
- ##########################################
4
- # This is the starter class. The promps at
5
- # the begining of the game are being called
6
- # here
7
- ##########################################
8
- class Starter
9
- def initialize
10
- @msg = Message.new
11
- @input = Input.new
12
- end
13
-
14
- def welcome
15
- puts "#{@msg.logo}"
16
- puts "#{@msg.welcome_msg}"
17
- puts "#{@msg.play_msg}"
18
- end
19
-
20
- def instructions
21
- puts "#{@msg.instruction_msg}"
22
- puts "#{@msg.continue_msg}"
23
- ask
24
- end
25
-
26
- def ask
27
- user_input = @input.user_input
28
- if user_input == "p"
29
- difficulty
30
- elsif user_input == "q"
31
- puts "#{@msg.quit_msg}"
32
- exit
33
- elsif user_input == "i"
34
- instructions
35
- else
36
- puts "#{@msg.invalid_entry_msg}"
37
- ask
38
- end
39
- end
40
-
41
- def difficulty
42
- puts "#{@msg.difficulty_select}"
43
- user_input = @input.user_input
44
- if user_input == "b"
45
- puts "#{@msg.beginer_msg}"
46
- col = 0
47
- begin_game(col)
48
-
49
- elsif user_input == "m"
50
- puts "#{@msg.intermidiate_msg}"
51
- col = 2
52
- begin_game(col)
53
- elsif user_input == "a"
54
- puts "#{@msg.advance_msg}"
55
- col = 4
56
- begin_game(col)
57
- else
58
- puts "#{@msg.invalid_entry_msg}"
59
- difficulty
60
- end
61
- end
62
-
63
- def begin_game(col)
64
- @game_starter = Game_Engine.new(col)
65
- @game_starter.game(col)
66
- end
67
-
68
- end # end class Starter
69
- end # end module
data/lib/player.rb DELETED
@@ -1,61 +0,0 @@
1
- module Mastermind
2
- class Player
3
- attr_reader :input
4
- def initialize
5
- @h_num = 0
6
- @msg = Message.new
7
- @input = Input.new
8
- end
9
- # This Validates user input
10
- def is_valid?(input)
11
- code = ["r","g","b","y","c","m"]
12
- arr = []
13
- for i in input
14
- arr << i if code.include?(i)
15
- end
16
- arr
17
- if arr == input
18
- true
19
- else
20
- false
21
- end
22
- end
23
-
24
- # This evaluates the user entry
25
- def player_entry(col, computer_code)
26
- user_input = @input.user_input
27
- if user_input == "q"
28
- puts "#{@msg.quit_msg}"
29
- exit
30
- elsif user_input == "h"
31
- if @h_num < col + 1
32
- @h_num += 1
33
- hint(col, computer_code)
34
- else
35
- puts "#{@msg.hint_exceeded_msg}"
36
- player_entry(col, computer_code)
37
- end
38
- elsif user_input.length > 4 + col
39
- puts "#{@msg.too_long}"
40
- player_entry(col, computer_code)
41
- elsif user_input.length < 4 + col
42
- puts "#{@msg.too_short}"
43
- player_entry(col, computer_code)
44
- elsif is_valid?(user_input.split(//))
45
- user_input = user_input.split(//)
46
- else
47
- puts "#{@msg.invalid_entry_msg}"
48
- player_entry(col,computer_code)
49
- end
50
- end
51
-
52
- # This gives the player a clue to computer's choice
53
- def hint(col, computer_code)
54
- h = rand(1..4)
55
- puts "#{computer_code[h - 1]} is at position #{h} in the computer's choice"
56
- h = rand(1..4)
57
- player_entry(col,computer_code)
58
- end #end hint
59
-
60
- end #end class Player
61
- end # end module
data/mastermind-0.1.0.gem DELETED
Binary file
data/mastermind-0.1.1.gem DELETED
Binary file
Binary file
Binary file