ro_sham_bo 0.1.0 → 0.1.1
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/README.md +31 -3
- data/lib/ro_sham_bo.rb +3 -1
- data/lib/ro_sham_bo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3336e5189ae0b7bc49c4c2f9c6c6fc86744344386eb88ad483aadc48aca2aaed
|
4
|
+
data.tar.gz: 9d454268bb69d507d916b5a5c69defa46501bc37e122d2007dc95a9466c2ac75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cf0b5e881f2a0fe2ad59a7d85c4ede8a315457a9cd41c1933927e290e09bfb50d2cdff218bee644055ca4af47ad6dd104107d0609638757460c04815f4d4bb2
|
7
|
+
data.tar.gz: 7b80a054800c6daa814485f38e8d1feeee4a5ca0fd747ca6d2e2f1d2ac97004971369d3965c0a5f863c1d6e73bcf10208ad735123e2c2c9308cf77cd71093d00
|
data/README.md
CHANGED
@@ -18,6 +18,7 @@ rake install
|
|
18
18
|
```
|
19
19
|
|
20
20
|
## Usage
|
21
|
+
### Command Line
|
21
22
|
Just call the `ro_sham_bo` executable, which should now be in your `$PATH`.
|
22
23
|
The default number of rounds is best-of `3`. This can be altered with the
|
23
24
|
`-r [NUMBER OF ROUNDS]` option. The number passed must be an odd number. To see
|
@@ -34,9 +35,36 @@ game.
|
|
34
35
|
|
35
36
|
Cheating is possible, both for the user and the computer. Pass `-c` (or `-c
|
36
37
|
user`) for the user to always win. Pass `-c computer` to make the computer win.
|
37
|
-
It will still look real; cheating only actually happens when the non-cheater
|
38
|
-
one
|
39
|
-
|
38
|
+
It will still look real; cheating only actually happens when the non-cheater
|
39
|
+
only needs one more point to win. Even then, it can still return a draw for that
|
40
|
+
round.
|
41
|
+
|
42
|
+
### Console
|
43
|
+
You can play via an IRB/Pry console via the gem's API.
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'ro_sham_bo'
|
47
|
+
|
48
|
+
game = RoShamBo.new
|
49
|
+
game.play(:rock)
|
50
|
+
# => #<RoShamBo:0x00007fe3011a2070
|
51
|
+
# @cheater=nil,
|
52
|
+
# @points_to_win=2,
|
53
|
+
# @rounds=3,
|
54
|
+
# @score={:user=>0, :computer=>0}>
|
55
|
+
|
56
|
+
game.play(%i[rock paper scissors].sample) until game.over?
|
57
|
+
game
|
58
|
+
# => #<RoShamBo:0x00007fe3011a2070
|
59
|
+
# @cheater=nil,
|
60
|
+
# @computer_choice=:paper,
|
61
|
+
# @points_to_win=2,
|
62
|
+
# @round_winner=:user,
|
63
|
+
# @rounds=3,
|
64
|
+
# @score={:user=>2, :computer=>1},
|
65
|
+
# @user_choice=:scissors,
|
66
|
+
# @winner=:user>
|
67
|
+
```
|
40
68
|
|
41
69
|
### Rules
|
42
70
|
The rules are standard rock, paper, scissors rules.
|
data/lib/ro_sham_bo.rb
CHANGED
@@ -10,6 +10,7 @@ class RoShamBo
|
|
10
10
|
attr_reader :cheater
|
11
11
|
attr_reader :rounds
|
12
12
|
attr_reader :score
|
13
|
+
attr_reader :draws
|
13
14
|
attr_reader :points_to_win
|
14
15
|
attr_reader :user_choice
|
15
16
|
attr_reader :computer_choice
|
@@ -26,6 +27,7 @@ class RoShamBo
|
|
26
27
|
@cheater = cheater
|
27
28
|
@rounds = rounds
|
28
29
|
@score = {user: 0, computer: 0}
|
30
|
+
@draws = 0
|
29
31
|
@points_to_win = (rounds.to_f / 2).ceil
|
30
32
|
end
|
31
33
|
|
@@ -53,7 +55,7 @@ class RoShamBo
|
|
53
55
|
when :lose then :computer
|
54
56
|
else :draw
|
55
57
|
end
|
56
|
-
|
58
|
+
winner == :draw ? @draws += 1 : score[winner] += 1
|
57
59
|
winner
|
58
60
|
end
|
59
61
|
|
data/lib/ro_sham_bo/version.rb
CHANGED