tic_tac_toe_nhu 0.0.3 → 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 +4 -4
- data/spec/integration/tictactoe/unbeatable_computer_spec.rb +11 -12
- data/spec/tic_tac_toe/game_spec.rb +0 -31
- data/tic_tac_toe_nhu.gemspec +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ce848a6a1b98e49fe1ed21d164699803a9b4833
|
4
|
+
data.tar.gz: 59ec4617389b657d7cfb61c494af0aacf3efeefe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7a2aeda27b4a5aec06a1103bb11a3d09a013266fcd4feabb27f8a3b10a734e6e6c0492a9196fd1dfe6d4ac8508e79c191ffbfe8d4a9954217fd09e3d2f834bd
|
7
|
+
data.tar.gz: 874c77c1609da0cc49cf0d46cc12b056f46ae89d5a4400d88962e60d2daece1d12f70f5b079ab9cea5c73d48835b13cd6d3e0e3ef2668b1eb937ac26793444a5
|
@@ -18,11 +18,11 @@ describe "Unbeatable computer", :slow_test => true do
|
|
18
18
|
|
19
19
|
it "wins all game when computer goes first" do
|
20
20
|
make_computer_move(@board)
|
21
|
-
|
21
|
+
play_game_for_each_available_move(@board)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "wins all game when human goes first" do
|
25
|
-
|
25
|
+
play_game_for_each_available_move(@board)
|
26
26
|
end
|
27
27
|
|
28
28
|
def make_computer_move(clone_board)
|
@@ -35,24 +35,23 @@ describe "Unbeatable computer", :slow_test => true do
|
|
35
35
|
TicTacToe::Rules.new(board)
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def play_game_for_each_available_move(board, move_history=[])
|
39
39
|
if rules(board).game_over?
|
40
40
|
print "."
|
41
41
|
if rules(board).winner == @human_value
|
42
|
-
|
43
|
-
raise "Human wins."
|
42
|
+
raise "Human wins: #{move_history.inspect}"
|
44
43
|
end
|
45
44
|
else
|
46
45
|
board.available_moves.each do |move|
|
47
|
-
move_history
|
48
|
-
cloned_board = board.clone
|
49
|
-
cloned_board.mark(move, "X")
|
50
|
-
make_computer_move(cloned_board) if !rules(cloned_board).game_over?
|
51
|
-
make_move(cloned_board, move_history)
|
52
|
-
move_history.delete(move)
|
46
|
+
make_players_move(board.clone, move_history.dup, move)
|
53
47
|
end
|
54
48
|
end
|
55
49
|
end
|
56
50
|
|
57
|
-
|
51
|
+
def make_players_move(board, move_history, move)
|
52
|
+
move_history << move
|
53
|
+
board.mark(move, "X")
|
54
|
+
make_computer_move(board) if !rules(board).game_over?
|
55
|
+
play_game_for_each_available_move(board, move_history)
|
56
|
+
end
|
58
57
|
end
|
@@ -86,37 +86,6 @@ describe TicTacToe::Game do
|
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
|
-
# describe "a copy of the game" do
|
90
|
-
# it "has the same current player" do
|
91
|
-
# @player1_strategy.add_move(1)
|
92
|
-
# @game.make_move
|
93
|
-
# @game.clone.current_player.should == @game.current_player
|
94
|
-
# end
|
95
|
-
#
|
96
|
-
# it "has the same moves previously made" do
|
97
|
-
# @player1_strategy.add_move(1)
|
98
|
-
# @game.make_move
|
99
|
-
# @game.clone.board.available_moves.should_not include(1)
|
100
|
-
# end
|
101
|
-
#
|
102
|
-
# it "has the current player unaffected by changes to the original game" do
|
103
|
-
# clone_game = @game.clone
|
104
|
-
# @player1_strategy.add_move(1)
|
105
|
-
# @game.make_move
|
106
|
-
#
|
107
|
-
# clone_game.current_player.should == @player1
|
108
|
-
# @game.current_player.should == @player2
|
109
|
-
# end
|
110
|
-
#
|
111
|
-
# it "clones the board" do
|
112
|
-
# clone_game = @game.clone
|
113
|
-
# @player1_strategy.add_move(1)
|
114
|
-
# @game.make_move
|
115
|
-
#
|
116
|
-
# @game.board.available_moves.should_not include(1)
|
117
|
-
# clone_game.board.available_moves.should include(1)
|
118
|
-
# end
|
119
|
-
# end
|
120
89
|
def mark_board(moves, value)
|
121
90
|
moves.each do |m|
|
122
91
|
@board.mark(m, value)
|
data/tic_tac_toe_nhu.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'tic_tac_toe_nhu'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.4'
|
4
4
|
s.date = '2013-06-11'
|
5
5
|
s.summary = "Tic Tac Toe"
|
6
6
|
s.description = "A simple tic tac toe game with AI"
|
@@ -8,4 +8,5 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.email = 'nhu313@gmail.com'
|
9
9
|
s.files = `git ls-files`.split("\n")
|
10
10
|
s.homepage = 'http://rubygems.org/gems/tic_tac_toe_nhu'
|
11
|
+
s.executables << 'tic_tac_toe'
|
11
12
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tic_tac_toe_nhu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nhu Nguyen
|
@@ -12,7 +12,8 @@ date: 2013-06-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: A simple tic tac toe game with AI
|
14
14
|
email: nhu313@gmail.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- tic_tac_toe
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
@@ -84,3 +85,4 @@ signing_key:
|
|
84
85
|
specification_version: 4
|
85
86
|
summary: Tic Tac Toe
|
86
87
|
test_files: []
|
88
|
+
has_rdoc:
|