connect_n_game 0.0.2 → 0.0.4

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: 77cbc1def307ddafb436d4e17ee6771aa0ed6600
4
- data.tar.gz: e8223189e2a93f3c02f2e7fb7d447c4cf98cc462
3
+ metadata.gz: 13851d1ad1c10ceeccbfa2fbb9d2d809c402b5f0
4
+ data.tar.gz: cc31ac550cc1f48c86e3d8a5658693008a249dc7
5
5
  SHA512:
6
- metadata.gz: 7083511e82dc98d5ef961089aa3cabb3f439d01bdf533c88a76ec0e5c4e7b76883f70460578d354e4b862bd85ff5d4cba2bb48d14eb34cc77a076eded6b6184d
7
- data.tar.gz: 668e52a0da7d18a9472522a83f4dadcb3bf019697394949d4446cbdcc54bc35e5b8e59cbb7cc9d6225797344906c3739f9fa219a9dfd817745cbd2e399b8615c
6
+ metadata.gz: 54da2ed6be1edd0c0c4fe2dcc6390d1d936f4b3d966838b9bbbf8fe5608e48162dd2ddae0b9803474569ce55ecb8ffcc8b6fa1c6aea44ee300e067ba88e48fa5
7
+ data.tar.gz: 92432f988aad1058ee850fc3a5b2dc52c1f5d76031d3ec831d1d072c2d00c35404c85eb146bf9cdfbd223e30d87a46cdeefa1e7cdcb8ed1dc3c644cfa816f68b
data/README.md CHANGED
@@ -72,3 +72,14 @@ Player Selection:
72
72
  3. Commit your changes (`git commit -am 'Add some feature'`)
73
73
  4. Push to the branch (`git push origin my-new-feature`)
74
74
  5. Create a new Pull Request
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the
79
+ [MIT License](./LICENSE.txt).
80
+
81
+ ## Code of Conduct
82
+
83
+ Everyone interacting in the fully_freeze project’s codebases, issue trackers,
84
+ chat rooms and mailing lists is expected to follow the
85
+ [code of conduct](./CODE_OF_CONDUCT.md).
@@ -3,14 +3,7 @@
3
3
 
4
4
  #Run the Connect N Game from the command line.
5
5
 
6
- unless defined?(ConnectNGame)
7
- begin
8
- require 'connect_n_game'
9
- rescue LoadError
10
- require_relative '../lib/connect_n_game'
11
- end
12
- end
13
-
6
+ require_relative '../lib/connect_n_game'
14
7
  require_relative '../lib/cli/cli'
15
8
 
16
9
  ConnectNGame::CLI.new.main
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rake", ">= 12.3.3"
23
23
  spec.add_development_dependency 'minitest', "~> 5.5.1"
24
24
  spec.add_development_dependency 'rdoc', "~> 4.0.1"
25
25
 
@@ -32,11 +32,13 @@ module ConnectNGame
32
32
  when "--debug"
33
33
  puts "Debug mode is enabled."
34
34
  $game_debug = true
35
- else
35
+ when "--help"
36
36
  fail ""
37
37
  end
38
38
  end
39
39
 
40
+ fail "Invalid args #{ARGV.join(" ")}" unless ARGV.empty?
41
+
40
42
  rescue => err
41
43
  puts err.message
42
44
  show_help
@@ -21,7 +21,7 @@ module ConnectNGame
21
21
  begin
22
22
  show_players
23
23
  print "\nEnter player #{@players.length+1} name: "
24
- input = gets.strip
24
+ input = STDIN.gets.strip
25
25
  player = find_player(input)
26
26
  puts "invalid entry #{input.inspect}" unless player
27
27
  end until player
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ConnectNGame
4
4
 
5
- #The EchoMoves echoes moves when possible.
5
+ #The Basic bot just picks the move with the highest score.
6
6
  class BasicMoves < Player
7
7
 
8
8
  #Build the player
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ConnectNGame
4
4
 
5
- #The EchoMoves echoes moves when possible.
5
+ #The Middle bot prefers to play the middle.
6
6
  class MiddleMoves < Player
7
7
 
8
8
  #Build the player
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ConnectNGame
4
4
 
5
- #The EchoMoves echoes moves when possible.
5
+ #The Prudent bot picks the move with the highest score.
6
6
  class Prudent < Player
7
7
 
8
8
  #Build the player
@@ -1,5 +1,5 @@
1
1
 
2
2
  module ConnectNGame
3
3
  #The version of the Connect N \Game.
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.4".freeze
5
5
  end
@@ -1,222 +1,222 @@
1
- # coding: utf-8
2
-
3
- require_relative '../lib/connect_n_game'
4
- gem 'minitest'
5
- require 'minitest/autorun'
6
-
7
- #Test the standard fOOrth library.
8
- class RackTester < Minitest::Test
9
-
10
- #Test that this test was run!
11
- def test_dummy
12
- assert_equal(ConnectNGame::VERSION.class, String)
13
- end
14
-
15
- #Test that we can create racks.
16
- def test_creating_racks
17
- assert_raises { ConnectNGame::Rack.new(3) }
18
-
19
- tr = ConnectNGame::Rack.new(4)
20
- assert_equal(4, tr.order)
21
- assert_equal(6, tr.depth)
22
- assert_equal(7, tr.width)
23
- assert_equal([[],[],[],[],[],[],[]], tr.rack)
24
- assert_equal(%w(A B C D E F G), tr.channel_names)
25
- assert_equal([0.0078125, 0.03125, 0.125, 0.5, 0.25, 0.0625,
26
- 0.015625], tr.weights)
27
-
28
- tr = ConnectNGame::Rack.new(5)
29
- assert_equal(5, tr.order)
30
- assert_equal(7, tr.depth)
31
- assert_equal(9, tr.width)
32
- assert_equal([[],[],[],[],[],[],[],[],[]], tr.rack)
33
- assert_equal(%w(A B C D E F G H I), tr.channel_names)
34
- assert_equal([0.001953125, 0.0078125, 0.03125, 0.125, 0.5,
35
- 0.25, 0.0625, 0.015625, 0.00390625], tr.weights)
36
-
37
- tr = ConnectNGame::Rack.new(6)
38
- assert_equal(6, tr.order)
39
- assert_equal(9, tr.depth)
40
- assert_equal(11, tr.width)
41
- assert_equal([[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
42
- assert_equal(%w(A B C D E F G H I J K), tr.channel_names)
43
- assert_equal([0.00048828125, 0.001953125, 0.0078125, 0.03125,
44
- 0.125, 0.5, 0.25, 0.0625, 0.015625, 0.00390625,
45
- 0.0009765625], tr.weights)
46
-
47
- tr = ConnectNGame::Rack.new(7)
48
- assert_equal(7, tr.order)
49
- assert_equal(10, tr.depth)
50
- assert_equal(11, tr.width)
51
- assert_equal([[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
52
- assert_equal(%w(A B C D E F G H I J K), tr.channel_names)
53
- assert_equal([0.00048828125, 0.001953125, 0.0078125, 0.03125,
54
- 0.125, 0.5, 0.25, 0.0625, 0.015625, 0.00390625,
55
- 0.0009765625], tr.weights)
56
-
57
- tr = ConnectNGame::Rack.new(8)
58
- assert_equal(8, tr.order)
59
- assert_equal(12, tr.depth)
60
- assert_equal(13, tr.width)
61
- assert_equal([[],[],[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
62
- assert_equal(%w(A B C D E F G H I J K L M), tr.channel_names)
63
- assert_equal([0.0001220703125, 0.00048828125, 0.001953125,
64
- 0.0078125, 0.03125, 0.125, 0.5, 0.25, 0.0625,
65
- 0.015625, 0.00390625, 0.0009765625,
66
- 0.000244140625], tr.weights)
67
-
68
- assert_raises { ConnectNGame::Rack.new(9) }
69
- end
70
-
71
- #Test that it can retrieve channels
72
- def test_get_channel
73
- (4..8).each do |order|
74
- tr = ConnectNGame::Rack.new(order)
75
-
76
- (1..(tr.width)).each do |ch|
77
- assert_equal([], tr.get_channel(ch))
78
- end
79
- end
80
- end
81
-
82
- #Test that it knows when a channel is full
83
- def test_channel_and_rack_full
84
- (4..8).each do |order|
85
- tr = ConnectNGame::Rack.new(order)
86
-
87
- #The channels are being filled.
88
- (1..tr.depth).each do | _depth |
89
-
90
- refute(tr.rack_full?)
91
-
92
- (1..tr.width).each do | channel |
93
-
94
- refute(tr.channel_full?(channel))
95
-
96
- tr.get_channel(channel) << 1
97
- end
98
- end
99
-
100
- #Now all the channels should be full.
101
- (1..tr.width).each do | channel |
102
- assert(tr.channel_full?(channel))
103
- end
104
-
105
- assert(tr.rack_full?)
106
- end
107
- end
108
-
109
- #Test that we can query individual cells
110
- def test_get_cell
111
- tr = ConnectNGame::Rack.new(4)
112
- assert_equal(nil, tr.get_cell(1,1))
113
- assert_equal(nil, tr.get_cell(1,2))
114
- assert_equal(nil, tr.get_cell(1,3))
115
-
116
- tr.get_channel(1) << 1
117
- assert_equal(1, tr.get_cell(1,1))
118
- assert_equal(nil, tr.get_cell(1,2))
119
- assert_equal(nil, tr.get_cell(1,3))
120
-
121
- tr.get_channel(1) << 2
122
- assert_equal(1, tr.get_cell(1,1))
123
- assert_equal(2, tr.get_cell(1,2))
124
- assert_equal(nil, tr.get_cell(1,3))
125
-
126
- tr.get_channel(1) << 1
127
- assert_equal(1, tr.get_cell(1,1))
128
- assert_equal(2, tr.get_cell(1,2))
129
- assert_equal(1, tr.get_cell(1,3))
130
- end
131
-
132
- #Test that we can play a channel.
133
- def test_play_channel
134
- tr = ConnectNGame::Rack.new(4)
135
-
136
- assert_equal(1, tr.play_channel(1, 1))
137
- assert_equal(2, tr.play_channel(1, 1))
138
- assert_equal(3, tr.play_channel(1, 1))
139
- assert_equal(4, tr.play_channel(1, 1))
140
- assert_equal(5, tr.play_channel(1, 1))
141
- assert_equal(6, tr.play_channel(1, 1))
142
-
143
- #Playing a full channel has no effect or score.
144
- assert_equal(6, tr.get_channel(1).length)
145
- assert_equal(-9, tr.play_channel(1, 1))
146
- assert_equal(6, tr.get_channel(1).length)
147
- end
148
-
149
- #Test getting the free row for a channel
150
- def test_channel_to_row
151
- tr = ConnectNGame::Rack.new(4)
152
-
153
- assert_equal(1, tr.channel_to_row(1))
154
-
155
- tr.play_channel(1,1)
156
- assert_equal(2, tr.channel_to_row(1))
157
-
158
- tr.play_channel(1,1)
159
- assert_equal(3, tr.channel_to_row(1))
160
-
161
- tr.play_channel(1,1)
162
- assert_equal(4, tr.channel_to_row(1))
163
-
164
- tr.play_channel(1,1)
165
- assert_equal(5, tr.channel_to_row(1))
166
-
167
- tr.play_channel(1,1)
168
- assert_equal(6, tr.channel_to_row(1))
169
-
170
- tr.play_channel(1,1)
171
- assert_equal(nil, tr.channel_to_row(1))
172
- end
173
-
174
- #Test that we can count cells around a position.
175
- def test_score_move
176
- tr = ConnectNGame::Rack.new(4)
177
- #.......
178
- #.......
179
- #.......
180
- #.......
181
-
182
- assert_equal(1, tr.play_channel(3,1))
183
- #.......
184
- #.......
185
- #.......
186
- #..X....
187
-
188
- assert_equal(2, tr.play_channel(4,1))
189
- #.......
190
- #.......
191
- #.......
192
- #..XX...
193
-
194
- assert_equal(2, tr.play_channel(4,1))
195
- #.......
196
- #.......
197
- #...X...
198
- #..XX...
199
-
200
- assert_equal(2, tr.play_channel(3,1))
201
- #.......
202
- #.......
203
- #..XX...
204
- #..XX...
205
-
206
- assert_equal(3, tr.play_channel(3,1))
207
- #.......
208
- #..X....
209
- #..XX...
210
- #..XX...
211
-
212
- assert_equal(4, tr.play_channel(3,1))
213
- #..X....
214
- #..X....
215
- #..XX...
216
- #..XX...
217
-
218
- #It should not hang either!
219
- assert_raises { tr.score_move(3, nil) }
220
- end
221
-
222
- end
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/connect_n_game'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+
7
+ #Test the standard fOOrth library.
8
+ class RackTester < Minitest::Test
9
+
10
+ #Test that this test was run!
11
+ def test_dummy
12
+ assert_equal(ConnectNGame::VERSION.class, String)
13
+ end
14
+
15
+ #Test that we can create racks.
16
+ def test_creating_racks
17
+ assert_raises { ConnectNGame::Rack.new(3) }
18
+
19
+ tr = ConnectNGame::Rack.new(4)
20
+ assert_equal(4, tr.order)
21
+ assert_equal(6, tr.depth)
22
+ assert_equal(7, tr.width)
23
+ assert_equal([[],[],[],[],[],[],[]], tr.rack)
24
+ assert_equal(%w(A B C D E F G), tr.channel_names)
25
+ assert_equal([0.0078125, 0.03125, 0.125, 0.5, 0.25, 0.0625,
26
+ 0.015625], tr.weights)
27
+
28
+ tr = ConnectNGame::Rack.new(5)
29
+ assert_equal(5, tr.order)
30
+ assert_equal(7, tr.depth)
31
+ assert_equal(9, tr.width)
32
+ assert_equal([[],[],[],[],[],[],[],[],[]], tr.rack)
33
+ assert_equal(%w(A B C D E F G H I), tr.channel_names)
34
+ assert_equal([0.001953125, 0.0078125, 0.03125, 0.125, 0.5,
35
+ 0.25, 0.0625, 0.015625, 0.00390625], tr.weights)
36
+
37
+ tr = ConnectNGame::Rack.new(6)
38
+ assert_equal(6, tr.order)
39
+ assert_equal(9, tr.depth)
40
+ assert_equal(11, tr.width)
41
+ assert_equal([[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
42
+ assert_equal(%w(A B C D E F G H I J K), tr.channel_names)
43
+ assert_equal([0.00048828125, 0.001953125, 0.0078125, 0.03125,
44
+ 0.125, 0.5, 0.25, 0.0625, 0.015625, 0.00390625,
45
+ 0.0009765625], tr.weights)
46
+
47
+ tr = ConnectNGame::Rack.new(7)
48
+ assert_equal(7, tr.order)
49
+ assert_equal(10, tr.depth)
50
+ assert_equal(11, tr.width)
51
+ assert_equal([[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
52
+ assert_equal(%w(A B C D E F G H I J K), tr.channel_names)
53
+ assert_equal([0.00048828125, 0.001953125, 0.0078125, 0.03125,
54
+ 0.125, 0.5, 0.25, 0.0625, 0.015625, 0.00390625,
55
+ 0.0009765625], tr.weights)
56
+
57
+ tr = ConnectNGame::Rack.new(8)
58
+ assert_equal(8, tr.order)
59
+ assert_equal(12, tr.depth)
60
+ assert_equal(13, tr.width)
61
+ assert_equal([[],[],[],[],[],[],[],[],[],[],[],[],[]], tr.rack)
62
+ assert_equal(%w(A B C D E F G H I J K L M), tr.channel_names)
63
+ assert_equal([0.0001220703125, 0.00048828125, 0.001953125,
64
+ 0.0078125, 0.03125, 0.125, 0.5, 0.25, 0.0625,
65
+ 0.015625, 0.00390625, 0.0009765625,
66
+ 0.000244140625], tr.weights)
67
+
68
+ assert_raises { ConnectNGame::Rack.new(9) }
69
+ end
70
+
71
+ #Test that it can retrieve channels
72
+ def test_get_channel
73
+ (4..8).each do |order|
74
+ tr = ConnectNGame::Rack.new(order)
75
+
76
+ (1..(tr.width)).each do |ch|
77
+ assert_equal([], tr.get_channel(ch))
78
+ end
79
+ end
80
+ end
81
+
82
+ #Test that it knows when a channel is full
83
+ def test_channel_and_rack_full
84
+ (4..8).each do |order|
85
+ tr = ConnectNGame::Rack.new(order)
86
+
87
+ #The channels are being filled.
88
+ (1..tr.depth).each do | _depth |
89
+
90
+ refute(tr.rack_full?)
91
+
92
+ (1..tr.width).each do | channel |
93
+
94
+ refute(tr.channel_full?(channel))
95
+
96
+ tr.get_channel(channel) << 1
97
+ end
98
+ end
99
+
100
+ #Now all the channels should be full.
101
+ (1..tr.width).each do | channel |
102
+ assert(tr.channel_full?(channel))
103
+ end
104
+
105
+ assert(tr.rack_full?)
106
+ end
107
+ end
108
+
109
+ #Test that we can query individual cells
110
+ def test_get_cell
111
+ tr = ConnectNGame::Rack.new(4)
112
+ assert_nil(tr.get_cell(1,1))
113
+ assert_nil(tr.get_cell(1,2))
114
+ assert_nil(tr.get_cell(1,3))
115
+
116
+ tr.get_channel(1) << 1
117
+ assert_equal(1, tr.get_cell(1,1))
118
+ assert_nil(tr.get_cell(1,2))
119
+ assert_nil(tr.get_cell(1,3))
120
+
121
+ tr.get_channel(1) << 2
122
+ assert_equal(1, tr.get_cell(1,1))
123
+ assert_equal(2, tr.get_cell(1,2))
124
+ assert_nil(tr.get_cell(1,3))
125
+
126
+ tr.get_channel(1) << 1
127
+ assert_equal(1, tr.get_cell(1,1))
128
+ assert_equal(2, tr.get_cell(1,2))
129
+ assert_equal(1, tr.get_cell(1,3))
130
+ end
131
+
132
+ #Test that we can play a channel.
133
+ def test_play_channel
134
+ tr = ConnectNGame::Rack.new(4)
135
+
136
+ assert_equal(1, tr.play_channel(1, 1))
137
+ assert_equal(2, tr.play_channel(1, 1))
138
+ assert_equal(3, tr.play_channel(1, 1))
139
+ assert_equal(4, tr.play_channel(1, 1))
140
+ assert_equal(5, tr.play_channel(1, 1))
141
+ assert_equal(6, tr.play_channel(1, 1))
142
+
143
+ #Playing a full channel has no effect or score.
144
+ assert_equal(6, tr.get_channel(1).length)
145
+ assert_equal(-9, tr.play_channel(1, 1))
146
+ assert_equal(6, tr.get_channel(1).length)
147
+ end
148
+
149
+ #Test getting the free row for a channel
150
+ def test_channel_to_row
151
+ tr = ConnectNGame::Rack.new(4)
152
+
153
+ assert_equal(1, tr.channel_to_row(1))
154
+
155
+ tr.play_channel(1,1)
156
+ assert_equal(2, tr.channel_to_row(1))
157
+
158
+ tr.play_channel(1,1)
159
+ assert_equal(3, tr.channel_to_row(1))
160
+
161
+ tr.play_channel(1,1)
162
+ assert_equal(4, tr.channel_to_row(1))
163
+
164
+ tr.play_channel(1,1)
165
+ assert_equal(5, tr.channel_to_row(1))
166
+
167
+ tr.play_channel(1,1)
168
+ assert_equal(6, tr.channel_to_row(1))
169
+
170
+ tr.play_channel(1,1)
171
+ assert_nil(tr.channel_to_row(1))
172
+ end
173
+
174
+ #Test that we can count cells around a position.
175
+ def test_score_move
176
+ tr = ConnectNGame::Rack.new(4)
177
+ #.......
178
+ #.......
179
+ #.......
180
+ #.......
181
+
182
+ assert_equal(1, tr.play_channel(3,1))
183
+ #.......
184
+ #.......
185
+ #.......
186
+ #..X....
187
+
188
+ assert_equal(2, tr.play_channel(4,1))
189
+ #.......
190
+ #.......
191
+ #.......
192
+ #..XX...
193
+
194
+ assert_equal(2, tr.play_channel(4,1))
195
+ #.......
196
+ #.......
197
+ #...X...
198
+ #..XX...
199
+
200
+ assert_equal(2, tr.play_channel(3,1))
201
+ #.......
202
+ #.......
203
+ #..XX...
204
+ #..XX...
205
+
206
+ assert_equal(3, tr.play_channel(3,1))
207
+ #.......
208
+ #..X....
209
+ #..XX...
210
+ #..XX...
211
+
212
+ assert_equal(4, tr.play_channel(3,1))
213
+ #..X....
214
+ #..X....
215
+ #..XX...
216
+ #..XX...
217
+
218
+ #It should not hang either!
219
+ assert_raises { tr.score_move(3, nil) }
220
+ end
221
+
222
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connect_n_game
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-23 00:00:00.000000000 Z
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -128,9 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.5.2
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: The Connect 4 (or more) Game gem.
135
135
  test_files: []
136
- has_rdoc: