tic_tac_toe_nhu 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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +8 -0
  5. data/Gemfile.lock +39 -0
  6. data/README.md +19 -0
  7. data/Rakefile +15 -0
  8. data/bin/tic_tac_toe +6 -0
  9. data/coverage/.last_run.json +5 -0
  10. data/coverage/.resultset.json +502 -0
  11. data/features/step_definitions/tictactoe_steps.rb +6 -0
  12. data/features/support/env.rb +2 -0
  13. data/features/tictactoe_start_game.feature +11 -0
  14. data/features/tictactoe_submit_move.feature +9 -0
  15. data/lib/tic_tac_toe/board.rb +99 -0
  16. data/lib/tic_tac_toe/game.rb +41 -0
  17. data/lib/tic_tac_toe/game_factory.rb +55 -0
  18. data/lib/tic_tac_toe/main.rb +47 -0
  19. data/lib/tic_tac_toe/player.rb +15 -0
  20. data/lib/tic_tac_toe/player_factory.rb +17 -0
  21. data/lib/tic_tac_toe/rules.rb +32 -0
  22. data/lib/tic_tac_toe/strategy/console_user.rb +26 -0
  23. data/lib/tic_tac_toe/strategy/minimax.rb +83 -0
  24. data/lib/tic_tac_toe/ui/console.rb +60 -0
  25. data/spec/integration/tictactoe/tic_tac_toe.rb +7 -0
  26. data/spec/mocks/game.rb +11 -0
  27. data/spec/mocks/game_factory.rb +8 -0
  28. data/spec/mocks/player_factory.rb +8 -0
  29. data/spec/mocks/rules.rb +9 -0
  30. data/spec/mocks/strategy/dynamic.rb +19 -0
  31. data/spec/mocks/ui/console.rb +15 -0
  32. data/spec/tic_tac_toe/board_spec.rb +186 -0
  33. data/spec/tic_tac_toe/game_factory_spec.rb +78 -0
  34. data/spec/tic_tac_toe/game_spec.rb +94 -0
  35. data/spec/tic_tac_toe/main_spec.rb +104 -0
  36. data/spec/tic_tac_toe/player_factory_mock.rb +10 -0
  37. data/spec/tic_tac_toe/player_factory_spec.rb +59 -0
  38. data/spec/tic_tac_toe/player_spec.rb +32 -0
  39. data/spec/tic_tac_toe/rules_spec.rb +185 -0
  40. data/spec/tic_tac_toe/spec_helper.rb +9 -0
  41. data/spec/tic_tac_toe/strategy/console_user_spec.rb +34 -0
  42. data/spec/tic_tac_toe/strategy/minimax_spec.rb +163 -0
  43. data/spec/tic_tac_toe/strategy/mock.rb +19 -0
  44. data/spec/tic_tac_toe/ui/console_spec.rb +93 -0
  45. data/tic_tac_toe_nhu.gemspec +11 -0
  46. metadata +86 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b9d9d16f137592a3f7a289e6438f7f6da7cf3058
4
+ data.tar.gz: 127b37245247e3bddbb54ac8f4470fa837041797
5
+ SHA512:
6
+ metadata.gz: 7616a935a87c09b5b3031ed5e9de4f48c5cd949a088f881efdb51b0ae880600a4ccf63ef055302e46f1eab2896368a5dacfff50401f9a5da6d98e43921416de0
7
+ data.tar.gz: 7f2886491f0f0acec8094d466120fddedfb202835052df2cbcf9ed1d82a688a4eb0bfdaaca10c5a6670ecfa7de93608dd5034c3627f01b1a4a922734294b60b8
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ coverage/*
2
+ nhu_ttt/*
3
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
4
+ gem 'simplecov'
5
+ gem 'cucumber'
6
+ gem 'json', '~> 1.7.7'
7
+ gem 'rake'
8
+ gem 'surrogate'
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ builder (3.2.2)
5
+ cucumber (1.3.2)
6
+ builder (>= 2.1.2)
7
+ diff-lcs (>= 1.1.3)
8
+ gherkin (~> 2.12.0)
9
+ multi_json (~> 1.3)
10
+ diff-lcs (1.2.4)
11
+ gherkin (2.12.0)
12
+ multi_json (~> 1.3)
13
+ json (1.7.7)
14
+ multi_json (1.7.7)
15
+ rake (10.1.0)
16
+ rspec (2.13.0)
17
+ rspec-core (~> 2.13.0)
18
+ rspec-expectations (~> 2.13.0)
19
+ rspec-mocks (~> 2.13.0)
20
+ rspec-core (2.13.1)
21
+ rspec-expectations (2.13.0)
22
+ diff-lcs (>= 1.1.3, < 2.0)
23
+ rspec-mocks (2.13.1)
24
+ simplecov (0.7.1)
25
+ multi_json (~> 1.0)
26
+ simplecov-html (~> 0.7.1)
27
+ simplecov-html (0.7.1)
28
+ surrogate (0.7.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ cucumber
35
+ json (~> 1.7.7)
36
+ rake
37
+ rspec
38
+ simplecov
39
+ surrogate
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ #Overview#
2
+ This is a Tic Tac Toe game written in Ruby. See [wikipedia](http://en.wikipedia.org/wiki/Tic-tac-toe) for more information on the game. It uses the console for the UI.
3
+
4
+ Before you run any test or start the game, make sure you do "bundle install" to retrieve all the required gems.
5
+
6
+ #Start game#
7
+ >rake play
8
+
9
+ #Test#
10
+ The test files live in spec/tic_tac_toe.
11
+
12
+ To run all the test:
13
+ >rake
14
+
15
+ To run the slow test (i.e. computer player):
16
+ >rake slow_test
17
+
18
+ To run all the test except the slow test:
19
+ >rake test
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:default)
4
+
5
+ RSpec::Core::RakeTask.new(:slow_test) do |t|
6
+ t.rspec_opts = "--tag slow_test"
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:test) do |t|
10
+ t.rspec_opts = "--tag ~slow_test"
11
+ end
12
+
13
+ task :play do
14
+ ruby "bin/tic_tac_toe"
15
+ end
data/bin/tic_tac_toe ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ require 'tic_tac_toe/main'
4
+
5
+ game = TicTacToe::Main.new
6
+ game.start
@@ -0,0 +1,5 @@
1
+ {
2
+ "result": {
3
+ "covered_percent": 100.0
4
+ }
5
+ }
@@ -0,0 +1,502 @@
1
+ {
2
+ "RSpec": {
3
+ "coverage": {
4
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/board.rb": [
5
+ 1,
6
+ 1,
7
+ null,
8
+ null,
9
+ 1,
10
+ 1,
11
+ null,
12
+ 1,
13
+ 119,
14
+ 119,
15
+ null,
16
+ null,
17
+ 1,
18
+ 120,
19
+ 120,
20
+ 120,
21
+ null,
22
+ null,
23
+ 1,
24
+ 3380,
25
+ 3377,
26
+ 3377,
27
+ null,
28
+ 3,
29
+ null,
30
+ null,
31
+ null,
32
+ 1,
33
+ 3070,
34
+ null,
35
+ null,
36
+ 1,
37
+ 2244,
38
+ null,
39
+ null,
40
+ 1,
41
+ 26,
42
+ null,
43
+ null,
44
+ 1,
45
+ 8643,
46
+ 25929,
47
+ null,
48
+ null,
49
+ null,
50
+ 1,
51
+ 8640,
52
+ 8640,
53
+ null,
54
+ 233280,
55
+ 25920,
56
+ null,
57
+ 8640,
58
+ null,
59
+ null,
60
+ 1,
61
+ 8640,
62
+ 8640,
63
+ 8640,
64
+ null,
65
+ null,
66
+ 1,
67
+ 3898,
68
+ 3898,
69
+ 35082,
70
+ null,
71
+ 3898,
72
+ null,
73
+ null,
74
+ 1,
75
+ 1,
76
+ 38462,
77
+ 38460,
78
+ null,
79
+ 9667,
80
+ null,
81
+ null,
82
+ 1,
83
+ 38462,
84
+ 38461,
85
+ 38460,
86
+ null,
87
+ null,
88
+ 1,
89
+ 38460,
90
+ null,
91
+ null,
92
+ 1,
93
+ 8640,
94
+ 77760,
95
+ null,
96
+ 8640,
97
+ null,
98
+ null,
99
+ 1,
100
+ 86400,
101
+ null,
102
+ null,
103
+ null
104
+ ],
105
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/game_factory.rb": [
106
+ 1,
107
+ 1,
108
+ 1,
109
+ null,
110
+ 1,
111
+ 1,
112
+ 1,
113
+ 11,
114
+ null,
115
+ null,
116
+ 1,
117
+ 4,
118
+ null,
119
+ null,
120
+ 1,
121
+ 6,
122
+ null,
123
+ 2,
124
+ null,
125
+ 1,
126
+ null,
127
+ 1,
128
+ null,
129
+ 1,
130
+ null,
131
+ 1,
132
+ null,
133
+ null,
134
+ null,
135
+ 1,
136
+ 1,
137
+ 1,
138
+ 1,
139
+ 1,
140
+ null,
141
+ null,
142
+ 1,
143
+ 2,
144
+ 2,
145
+ 2,
146
+ null,
147
+ null,
148
+ 1,
149
+ 1,
150
+ 1,
151
+ 1,
152
+ null,
153
+ null,
154
+ 1,
155
+ 1,
156
+ 1,
157
+ 1,
158
+ null,
159
+ null,
160
+ null
161
+ ],
162
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/game.rb": [
163
+ 1,
164
+ null,
165
+ 1,
166
+ 1,
167
+ 1,
168
+ null,
169
+ 1,
170
+ 16,
171
+ 16,
172
+ 16,
173
+ 16,
174
+ null,
175
+ null,
176
+ 1,
177
+ 4,
178
+ 4,
179
+ 2,
180
+ 2,
181
+ null,
182
+ null,
183
+ null,
184
+ 1,
185
+ 4,
186
+ null,
187
+ null,
188
+ 1,
189
+ 3,
190
+ null,
191
+ null,
192
+ 1,
193
+ 1,
194
+ 2,
195
+ null,
196
+ null,
197
+ 1,
198
+ 3,
199
+ 2,
200
+ null,
201
+ null,
202
+ null,
203
+ null
204
+ ],
205
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/rules.rb": [
206
+ 1,
207
+ 1,
208
+ 1,
209
+ 73,
210
+ null,
211
+ null,
212
+ 1,
213
+ 3080,
214
+ 1922,
215
+ 1605,
216
+ null,
217
+ null,
218
+ 1,
219
+ 321,
220
+ null,
221
+ null,
222
+ 1,
223
+ 13528,
224
+ null,
225
+ null,
226
+ 1,
227
+ 1,
228
+ 8638,
229
+ 164366,
230
+ null,
231
+ null,
232
+ null,
233
+ 1,
234
+ 8638,
235
+ null,
236
+ null,
237
+ null
238
+ ],
239
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/player_factory.rb": [
240
+ 1,
241
+ 1,
242
+ 1,
243
+ null,
244
+ 1,
245
+ 1,
246
+ null,
247
+ 1,
248
+ 4,
249
+ null,
250
+ null,
251
+ 1,
252
+ 4,
253
+ 4,
254
+ null,
255
+ null,
256
+ null
257
+ ],
258
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/strategy/minimax.rb": [
259
+ 1,
260
+ null,
261
+ 1,
262
+ 1,
263
+ 1,
264
+ 1,
265
+ 27,
266
+ 27,
267
+ 27,
268
+ 27,
269
+ null,
270
+ null,
271
+ 1,
272
+ 23,
273
+ 3,
274
+ null,
275
+ 20,
276
+ 20,
277
+ null,
278
+ null,
279
+ null,
280
+ 1,
281
+ 1,
282
+ 1,
283
+ 1,
284
+ 1,
285
+ null,
286
+ 1,
287
+ 23,
288
+ 23,
289
+ null,
290
+ null,
291
+ 1,
292
+ 3,
293
+ 1,
294
+ null,
295
+ null,
296
+ 1,
297
+ 1620,
298
+ 1620,
299
+ 3068,
300
+ 3068,
301
+ 3068,
302
+ 3068,
303
+ null,
304
+ 1620,
305
+ null,
306
+ null,
307
+ 1,
308
+ 3068,
309
+ 1468,
310
+ null,
311
+ 1600,
312
+ 1600,
313
+ null,
314
+ null,
315
+ null,
316
+ 1,
317
+ 3068,
318
+ null,
319
+ null,
320
+ 1,
321
+ 1468,
322
+ 1468,
323
+ 320,
324
+ 317,
325
+ null,
326
+ null,
327
+ null,
328
+ null,
329
+ 1,
330
+ 1920,
331
+ null,
332
+ null,
333
+ 1,
334
+ 3227,
335
+ 4688,
336
+ null,
337
+ null,
338
+ null,
339
+ 1,
340
+ null,
341
+ null
342
+ ],
343
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/strategy/console_user.rb": [
344
+ 1,
345
+ 1,
346
+ 1,
347
+ null,
348
+ 1,
349
+ 7,
350
+ 7,
351
+ null,
352
+ null,
353
+ 1,
354
+ 3,
355
+ null,
356
+ 3,
357
+ 5,
358
+ 5,
359
+ null,
360
+ null,
361
+ 3,
362
+ null,
363
+ null,
364
+ 1,
365
+ 1,
366
+ null,
367
+ null,
368
+ null,
369
+ null
370
+ ],
371
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/player.rb": [
372
+ 1,
373
+ 1,
374
+ 1,
375
+ null,
376
+ 1,
377
+ 50,
378
+ 50,
379
+ 50,
380
+ null,
381
+ null,
382
+ 1,
383
+ 5,
384
+ null,
385
+ null,
386
+ null
387
+ ],
388
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/main.rb": [
389
+ 1,
390
+ 1,
391
+ 1,
392
+ null,
393
+ 1,
394
+ 1,
395
+ 1,
396
+ null,
397
+ 1,
398
+ 14,
399
+ 14,
400
+ 14,
401
+ null,
402
+ null,
403
+ 1,
404
+ 11,
405
+ 11,
406
+ 11,
407
+ null,
408
+ 11,
409
+ 11,
410
+ 11,
411
+ null,
412
+ null,
413
+ 1,
414
+ 1,
415
+ 7,
416
+ 7,
417
+ 7,
418
+ 7,
419
+ 7,
420
+ 1,
421
+ 1,
422
+ null,
423
+ null,
424
+ null,
425
+ 1,
426
+ 11,
427
+ 11,
428
+ 10,
429
+ null,
430
+ 1,
431
+ null,
432
+ null,
433
+ null,
434
+ null,
435
+ null
436
+ ],
437
+ "/Users/nhunguyen/Documents/Ruby/tictactoe/lib/tic_tac_toe/ui/console.rb": [
438
+ 1,
439
+ null,
440
+ 1,
441
+ 1,
442
+ null,
443
+ 1,
444
+ 13,
445
+ 13,
446
+ null,
447
+ null,
448
+ 1,
449
+ 1,
450
+ null,
451
+ null,
452
+ 1,
453
+ 4,
454
+ null,
455
+ null,
456
+ 1,
457
+ 3,
458
+ 3,
459
+ 3,
460
+ 3,
461
+ null,
462
+ null,
463
+ 1,
464
+ 1,
465
+ null,
466
+ null,
467
+ 1,
468
+ 1,
469
+ null,
470
+ null,
471
+ 1,
472
+ 1,
473
+ null,
474
+ null,
475
+ 1,
476
+ 1,
477
+ null,
478
+ null,
479
+ 1,
480
+ 1,
481
+ 4,
482
+ 4,
483
+ 21,
484
+ 21,
485
+ null,
486
+ 4,
487
+ null,
488
+ null,
489
+ 1,
490
+ 3,
491
+ 3,
492
+ 12,
493
+ null,
494
+ 3,
495
+ null,
496
+ null,
497
+ null
498
+ ]
499
+ },
500
+ "timestamp": 1372702698
501
+ }
502
+ }
@@ -0,0 +1,6 @@
1
+ Given(/^I am not yet playing$/) do
2
+ end
3
+
4
+ When (/^I start a new game$/) do
5
+ TicTacToe::Game.new(StringIO.new, TicTacToe::Board.new).start
6
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
+ require 'tictactoe'
@@ -0,0 +1,11 @@
1
+ Feature: Tic Tac Toe starts game
2
+ As a player
3
+ I want to start a game
4
+ So I can start to make my move
5
+
6
+ Scenario: start game
7
+ Given I am not yet playing
8
+ When I start a new game
9
+ Then I should see "Welcome to Tic Tac Toe!"
10
+ And I should see the board
11
+ And I should see "Please choose a move:"
@@ -0,0 +1,9 @@
1
+ Feature: player submits a move
2
+ As a player
3
+ I want to submit a move
4
+ So I can win the game
5
+
6
+ Scenario: submit move
7
+ Given I start playing the game
8
+ When I enter a number to make a move
9
+ Then I should see my mark on the board