bashrw_ttt 0.1.0
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.
- data/bin/play.rb +10 -0
- data/lib/ttt/ai.rb +33 -0
- data/lib/ttt/ai_easy.rb +17 -0
- data/lib/ttt/ai_hard.rb +21 -0
- data/lib/ttt/ai_medium.rb +21 -0
- data/lib/ttt/ai_medium_back.rb +58 -0
- data/lib/ttt/board.rb +37 -0
- data/lib/ttt/config_helper.rb +53 -0
- data/lib/ttt/config_options.rb +27 -0
- data/lib/ttt/context.rb +214 -0
- data/lib/ttt/four_by_four.rb +62 -0
- data/lib/ttt/game.rb +94 -0
- data/lib/ttt/game_history.rb +37 -0
- data/lib/ttt/game_interactor.rb +126 -0
- data/lib/ttt/human.rb +12 -0
- data/lib/ttt/interfaces/cli/lib/cli/board_selection.rb +34 -0
- data/lib/ttt/interfaces/cli/lib/cli/cli_game.rb +186 -0
- data/lib/ttt/interfaces/cli/lib/cli/cli_presenter.rb +216 -0
- data/lib/ttt/interfaces/cli/lib/cli/clio.rb +17 -0
- data/lib/ttt/interfaces/cli/lib/cli/play_again.rb +38 -0
- data/lib/ttt/interfaces/cli/lib/cli/player_selection.rb +43 -0
- data/lib/ttt/interfaces/cli/lib/cli/selection.rb +8 -0
- data/lib/ttt/interfaces/cli/lib/cli/walk_history.rb +48 -0
- data/lib/ttt/interfaces/cli/spec/cli/board_selection_spec.rb +29 -0
- data/lib/ttt/interfaces/cli/spec/cli/cli_game_spec.rb +376 -0
- data/lib/ttt/interfaces/cli/spec/cli/cli_presenter_spec.rb +147 -0
- data/lib/ttt/interfaces/cli/spec/cli/play_again_spec.rb +39 -0
- data/lib/ttt/interfaces/cli/spec/cli/player_selection_spec.rb +62 -0
- data/lib/ttt/interfaces/cli/spec/cli/walk_history_spec.rb +115 -0
- data/lib/ttt/interfaces/cli/spec/spec_helper.rb +14 -0
- data/lib/ttt/interfaces/limelight/four_by_four/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/four_by_four/styles.rb +74 -0
- data/lib/ttt/interfaces/limelight/four_by_four_finished/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/four_by_four_finished/styles.rb +74 -0
- data/lib/ttt/interfaces/limelight/game_list/players/load_button.rb +10 -0
- data/lib/ttt/interfaces/limelight/game_list/props.rb +17 -0
- data/lib/ttt/interfaces/limelight/game_list/styles.rb +8 -0
- data/lib/ttt/interfaces/limelight/main_menu/players/exit_ttt.rb +3 -0
- data/lib/ttt/interfaces/limelight/main_menu/players/load_game.rb +3 -0
- data/lib/ttt/interfaces/limelight/main_menu/players/new_game.rb +3 -0
- data/lib/ttt/interfaces/limelight/main_menu/props.rb +17 -0
- data/lib/ttt/interfaces/limelight/new_game/players/board_type.rb +1 -0
- data/lib/ttt/interfaces/limelight/new_game/players/new_game.rb +5 -0
- data/lib/ttt/interfaces/limelight/new_game/players/player_type.rb +1 -0
- data/lib/ttt/interfaces/limelight/new_game/players/setup_button.rb +21 -0
- data/lib/ttt/interfaces/limelight/new_game/props.rb +21 -0
- data/lib/ttt/interfaces/limelight/new_game/styles.rb +23 -0
- data/lib/ttt/interfaces/limelight/partials/board_partial.rb +14 -0
- data/lib/ttt/interfaces/limelight/partials/menu_button_partial.rb +5 -0
- data/lib/ttt/interfaces/limelight/partials/move_history_partial.rb +6 -0
- data/lib/ttt/interfaces/limelight/partials/title_history_partial.rb +10 -0
- data/lib/ttt/interfaces/limelight/players/board.rb +3 -0
- data/lib/ttt/interfaces/limelight/players/game.rb +4 -0
- data/lib/ttt/interfaces/limelight/players/generic_move_history.rb +5 -0
- data/lib/ttt/interfaces/limelight/players/generic_player.rb +8 -0
- data/lib/ttt/interfaces/limelight/players/left_button.rb +3 -0
- data/lib/ttt/interfaces/limelight/players/main_menu.rb +3 -0
- data/lib/ttt/interfaces/limelight/players/right_button.rb +3 -0
- data/lib/ttt/interfaces/limelight/playscripts/game_playscript.rb +169 -0
- data/lib/ttt/interfaces/limelight/production.rb +14 -0
- data/lib/ttt/interfaces/limelight/spec/game_playscript_spec.rb +218 -0
- data/lib/ttt/interfaces/limelight/spec/main_menu/main_menu_spec.rb +38 -0
- data/lib/ttt/interfaces/limelight/spec/new_game/new_game_spec.rb +45 -0
- data/lib/ttt/interfaces/limelight/spec/spec_helper.rb +8 -0
- data/lib/ttt/interfaces/limelight/stages.rb +6 -0
- data/lib/ttt/interfaces/limelight/styles.rb +119 -0
- data/lib/ttt/interfaces/limelight/three_by_three/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/three_by_three/styles.rb +39 -0
- data/lib/ttt/interfaces/limelight/three_by_three_by_three/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/three_by_three_by_three/styles.rb +119 -0
- data/lib/ttt/interfaces/limelight/three_by_three_by_three_finished/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/three_by_three_by_three_finished/styles.rb +119 -0
- data/lib/ttt/interfaces/limelight/three_by_three_finished/props.rb +1 -0
- data/lib/ttt/interfaces/limelight/three_by_three_finished/styles.rb +39 -0
- data/lib/ttt/interfaces/rails/app/controllers/application_controller.rb +3 -0
- data/lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb +86 -0
- data/lib/ttt/interfaces/rails/app/helpers/application_helper.rb +2 -0
- data/lib/ttt/interfaces/rails/app/models/ttt_game.rb +34 -0
- data/lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb +159 -0
- data/lib/ttt/interfaces/rails/autotest/discover.rb +1 -0
- data/lib/ttt/interfaces/rails/config/application.rb +67 -0
- data/lib/ttt/interfaces/rails/config/boot.rb +6 -0
- data/lib/ttt/interfaces/rails/config/environment.rb +5 -0
- data/lib/ttt/interfaces/rails/config/environments/development.rb +37 -0
- data/lib/ttt/interfaces/rails/config/environments/production.rb +67 -0
- data/lib/ttt/interfaces/rails/config/environments/test.rb +37 -0
- data/lib/ttt/interfaces/rails/config/initializers/backtrace_silencers.rb +7 -0
- data/lib/ttt/interfaces/rails/config/initializers/inflections.rb +15 -0
- data/lib/ttt/interfaces/rails/config/initializers/mime_types.rb +5 -0
- data/lib/ttt/interfaces/rails/config/initializers/secret_token.rb +7 -0
- data/lib/ttt/interfaces/rails/config/initializers/session_store.rb +8 -0
- data/lib/ttt/interfaces/rails/config/initializers/wrap_parameters.rb +14 -0
- data/lib/ttt/interfaces/rails/config/routes.rb +49 -0
- data/lib/ttt/interfaces/rails/db/schema.rb +28 -0
- data/lib/ttt/interfaces/rails/db/seeds.rb +7 -0
- data/lib/ttt/interfaces/rails/spec/controllers/ttt_games_controller_spec.rb +211 -0
- data/lib/ttt/interfaces/rails/spec/models/ttt_game_spec.rb +76 -0
- data/lib/ttt/interfaces/rails/spec/presenters/web_game_presenter_spec.rb +52 -0
- data/lib/ttt/interfaces/rails/spec/spec_helper.rb +13 -0
- data/lib/ttt/interfaces/web_interface/html_generator.rb +76 -0
- data/lib/ttt/interfaces/web_interface/web_game_presenter.rb +0 -0
- data/lib/ttt/minimax.rb +46 -0
- data/lib/ttt/move_history.rb +10 -0
- data/lib/ttt/move_traverser.rb +49 -0
- data/lib/ttt/player.rb +15 -0
- data/lib/ttt/riak_db.rb +53 -0
- data/lib/ttt/setup.rb +59 -0
- data/lib/ttt/three_by_three.rb +35 -0
- data/lib/ttt/three_by_three_by_three.rb +37 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/ttt/ai_easy_spec.rb +15 -0
- data/spec/ttt/ai_hard_spec.rb +76 -0
- data/spec/ttt/ai_medium_spec.rb +65 -0
- data/spec/ttt/ai_spec.rb +50 -0
- data/spec/ttt/board_spec.rb +96 -0
- data/spec/ttt/config_helper_spec.rb +54 -0
- data/spec/ttt/context_spec.rb +398 -0
- data/spec/ttt/four_by_four_spec.rb +112 -0
- data/spec/ttt/game_history_spec.rb +41 -0
- data/spec/ttt/game_interactor_spec.rb +197 -0
- data/spec/ttt/game_spec.rb +246 -0
- data/spec/ttt/human_spec.rb +18 -0
- data/spec/ttt/move_history_spec.rb +13 -0
- data/spec/ttt/move_traverser_spec.rb +75 -0
- data/spec/ttt/player_spec.rb +13 -0
- data/spec/ttt/riak_db_spec.rb +64 -0
- data/spec/ttt/setup_spec.rb +63 -0
- data/spec/ttt/three_by_three_by_three_spec.rb +130 -0
- data/spec/ttt/three_by_three_spec.rb +110 -0
- metadata +238 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module CLI
|
|
4
|
+
describe CLIPresenter do
|
|
5
|
+
let(:instream) { StringIO.new }
|
|
6
|
+
let(:outstream) { StringIO.new }
|
|
7
|
+
let(:presenter) { CLIPresenter.new(instream, outstream) }
|
|
8
|
+
|
|
9
|
+
describe "#new" do
|
|
10
|
+
it "returns a new presenter object" do
|
|
11
|
+
presenter.should_not be_nil
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#output" do
|
|
16
|
+
it "sends an output message to the io" do
|
|
17
|
+
presenter.output "hello"
|
|
18
|
+
presenter.io.outstream.include? "Hello"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#welcome_prompt" do
|
|
23
|
+
it "displays 'Welcome to TTT!'" do
|
|
24
|
+
presenter.welcome_prompt
|
|
25
|
+
presenter.io.outstream.include? "Welcome to TTT!"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "#command_list" do
|
|
30
|
+
it "sends a command list message to the io" do
|
|
31
|
+
presenter.io.should_receive(:output).at_least(4).times
|
|
32
|
+
presenter.command_list
|
|
33
|
+
presenter.io.outstream.include? "Please select an option from the following list:"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe "#menu" do
|
|
38
|
+
it "sends a welcome prompt message to the io" do
|
|
39
|
+
presenter.io.outstream.include? "Welcome to TTT!"
|
|
40
|
+
presenter.io.outstream.include? "1. Play ttt!"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe "#input" do
|
|
45
|
+
it "receives input from the command line" do
|
|
46
|
+
presenter.io.instream = StringIO.new("Hello\n")
|
|
47
|
+
presenter.input.chomp.should == "Hello"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
describe "#process_game_list" do
|
|
52
|
+
it "sends an output message to the io" do
|
|
53
|
+
list = %w(5 4 3 2 1)
|
|
54
|
+
presenter.io.outstream = StringIO.new(list.join("\n"))
|
|
55
|
+
presenter.io.instream = StringIO.new("1\n")
|
|
56
|
+
presenter.io.should_receive(:output).at_least(2)
|
|
57
|
+
presenter.process_game_list(list)
|
|
58
|
+
presenter.io.outstream.string.should == "5\n4\n3\n2\n1"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
describe "#sort_list" do
|
|
63
|
+
it "sorts an array of game id strings into integers" do
|
|
64
|
+
ary = %w(5 4 3 2 1)
|
|
65
|
+
presenter.sort_list(ary).should == %w(1 2 3 4 5)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "#no_games" do
|
|
70
|
+
it "displays 'No games were found.' to the user" do
|
|
71
|
+
presenter.no_games
|
|
72
|
+
presenter.io.outstream.include? "No games were found"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "#player_prompt" do
|
|
77
|
+
it "displays the prompt for the player type" do
|
|
78
|
+
history = stub(:each_with_index => [])
|
|
79
|
+
board = Array.new(9, ' ')
|
|
80
|
+
player = double('player')
|
|
81
|
+
player.stub(:prompt).and_return("Entere move:")
|
|
82
|
+
presenter.player_prompt(board, history, player)
|
|
83
|
+
presenter.io.outstream.include? "Enter move:"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe "#output_three_by_three" do
|
|
88
|
+
it "prints game board" do
|
|
89
|
+
board = Array.new(9, ' ')
|
|
90
|
+
presenter.output_three_by_three(board)
|
|
91
|
+
presenter.io.outstream.string.chomp.should == "\n | | \n"+
|
|
92
|
+
"-----------------\n"+
|
|
93
|
+
" | | \n"+
|
|
94
|
+
"-----------------\n"+
|
|
95
|
+
" | | "
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
describe "#output_four_by_four" do
|
|
100
|
+
it "displays a four by four board" do
|
|
101
|
+
board = Array.new(16, ' ')
|
|
102
|
+
presenter.output_four_by_four(board)
|
|
103
|
+
presenter.io.outstream.string.chomp.should == "\n | | | \n"+
|
|
104
|
+
"-----------------------\n"+
|
|
105
|
+
" | | | \n"+
|
|
106
|
+
"-----------------------\n"+
|
|
107
|
+
" | | | \n"+
|
|
108
|
+
"-----------------------\n"+
|
|
109
|
+
" | | | "
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe "#winner_prompt" do
|
|
114
|
+
it "displays 'Player 1 is the winner!" do
|
|
115
|
+
presenter.winner_prompt("Player 1")
|
|
116
|
+
presenter.io.outstream.string.split("\n").include? "Player 1 is the winner!"
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
describe "#draw_prompt" do
|
|
121
|
+
it "displays 'It's a draw!'" do
|
|
122
|
+
presenter.draw_prompt
|
|
123
|
+
presenter.io.outstream.string.split("\n").include? "It's a draw!"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
describe "#four_by_four_move_prompt" do
|
|
128
|
+
it "displays a help menu to indicate how the user can move on a 4x4 board" do
|
|
129
|
+
presenter.four_by_four_move_prompt
|
|
130
|
+
presenter.io.outstream.string.chomp.should == "\n 0 | 1 | 2 | 3 \n"+
|
|
131
|
+
"-----------------------\n"+
|
|
132
|
+
" 4 | 5 | 6 | 7 \n"+
|
|
133
|
+
"-----------------------\n"+
|
|
134
|
+
" 8 | 9 | 10 | 11 \n"+
|
|
135
|
+
"-----------------------\n"+
|
|
136
|
+
" 12 | 13 | 14 | 15 "
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
describe "#post_game_msg" do
|
|
141
|
+
it "prompts the user if they 'Would like to review the game history'?" do
|
|
142
|
+
presenter.post_game_msg
|
|
143
|
+
presenter.io.outstream.include? "\nWould you like to review the game history (y or n)?"
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module CLI
|
|
4
|
+
describe PlayAgain do
|
|
5
|
+
let(:presenter) { CLIPresenter.new(StringIO.new, StringIO.new) }
|
|
6
|
+
let(:againio) { PlayAgain.new(presenter) }
|
|
7
|
+
|
|
8
|
+
describe "#valid_reply?" do
|
|
9
|
+
it "returns nil if the play again response is not 'y' or 'n'" do
|
|
10
|
+
againio.valid_reply?("1\n").should == nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "returns zero if the play again response is 'y' or 'n'" do
|
|
14
|
+
againio.valid_reply?("n\n").should == 0
|
|
15
|
+
againio.valid_reply?("y\n").should == 0
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe "#play_again_msg" do
|
|
20
|
+
it "sends a play_again_msg message to gameio" do
|
|
21
|
+
presenter.should_receive(:play_again_msg)
|
|
22
|
+
againio.play_again_msg
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe "#play_again?" do
|
|
27
|
+
it "prompts the user to play again" do
|
|
28
|
+
presenter.io.instream = StringIO.new("n\n")
|
|
29
|
+
presenter.io.outstream.string.split("\n").include? "Play again (y or n)?"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "prompts the user to re-enter input when invalid input is received" do
|
|
33
|
+
presenter.io.instream = StringIO.new("i\nn\n")
|
|
34
|
+
againio.play_again?
|
|
35
|
+
presenter.io.outstream.string.split("\n").include? "I'm sorry, I didn't understand you. Please try again."
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module CLI
|
|
4
|
+
describe PlayerSelection do
|
|
5
|
+
let(:presenter) { CLIPresenter.new(StringIO.new, StringIO.new) }
|
|
6
|
+
let(:players) { TTT::Setup.new.players }
|
|
7
|
+
|
|
8
|
+
let(:ptypeio) { PlayerSelection.new(players, presenter) }
|
|
9
|
+
|
|
10
|
+
describe "#player_selection_valid?" do
|
|
11
|
+
it "returns false if input is not an integer within the range of available options" do
|
|
12
|
+
ptypeio.player_selection_valid?(10).should == false
|
|
13
|
+
ptypeio.player_selection_valid?(6).should == false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns true if input is an integer within the range of available options" do
|
|
17
|
+
ptypeio.player_selection_valid?(2).should == true
|
|
18
|
+
ptypeio.player_selection_valid?(3).should == true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
describe "#player_type_prompt" do
|
|
23
|
+
it "displays an enumerable list of player types the user can choose from" do
|
|
24
|
+
presenter.player_type_prompt(1, players)
|
|
25
|
+
ptypeio.presenter.io.outstream.string.split('n').include? "1. Human"
|
|
26
|
+
ptypeio.presenter.io.outstream.string.split('n').include? "2. AI Easy"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe "#set_player_string" do
|
|
31
|
+
it "sets a player type string representing the class constant in the list of player types" do
|
|
32
|
+
ptypeio.set_player_string(1, 1)
|
|
33
|
+
ptypeio.player1.should == "Human"
|
|
34
|
+
ptypeio.set_player_string(2, 2)
|
|
35
|
+
ptypeio.player2.should == "AI Easy"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe "#process_player_type_input" do
|
|
40
|
+
it "when input passes validation, the player type is associated with that player number as a string" do
|
|
41
|
+
ptypeio.process_player_type_input(1, "1\n")
|
|
42
|
+
ptypeio.player1.should == "Human"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "when input doesn't pass validation, an error prompt is generated and the user is prompted to input again" do
|
|
46
|
+
ptypeio.presenter.io.instream = StringIO.new("1\n")
|
|
47
|
+
ptypeio.process_player_type_input(1, "6\n")
|
|
48
|
+
ptypeio.presenter.io.outstream.string.split("\n").include? "I'm sorry, I didn't understand. Please try again."
|
|
49
|
+
ptypeio.player1.should == "Human"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe "#process" do
|
|
54
|
+
it "prompts the player to enter a type for player1 and player2, resulting in player1 and player2 being set" do
|
|
55
|
+
ptypeio.presenter.io.instream = StringIO.new("1\n1\n")
|
|
56
|
+
ptypeio.process
|
|
57
|
+
ptypeio.player1.should == "Human"
|
|
58
|
+
ptypeio.player2.should == "Human"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module CLI
|
|
4
|
+
describe WalkHistory do
|
|
5
|
+
let(:setup) { TTT::Setup.new }
|
|
6
|
+
let(:move_history) { [TTT::MoveHistory.new(:side => 'x', :move => '0'), TTT::MoveHistory.new(:side => 'o', :move => '1'), TTT::MoveHistory.new(:side => 'x', :move => '4'), TTT::MoveHistory.new(:side => 'o', :move => '5'), TTT::MoveHistory.new(:side => 'x', :move => '8') ] }
|
|
7
|
+
let(:game) { setup.new_game(:player1 => setup.players.first, :player2 => setup.players.first, :board => setup.boards.first) }
|
|
8
|
+
let(:presenter) { CLIPresenter.new(StringIO.new, StringIO.new) }
|
|
9
|
+
let(:walkio) { WalkHistory.new(presenter, game) }
|
|
10
|
+
|
|
11
|
+
before(:each) do
|
|
12
|
+
game.record_move(0, 'x')
|
|
13
|
+
game.mark_move(0, 'x')
|
|
14
|
+
game.record_move(1, 'o')
|
|
15
|
+
game.mark_move(1, 'o')
|
|
16
|
+
game.record_move(4, 'x')
|
|
17
|
+
game.mark_move(4, 'x')
|
|
18
|
+
game.record_move(5, 'o')
|
|
19
|
+
game.mark_move(5, 'o')
|
|
20
|
+
game.record_move(8, 'x')
|
|
21
|
+
game.mark_move(8, 'x')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#build_board" do
|
|
25
|
+
it "returns a board array representing the game board at move index 0" do
|
|
26
|
+
walkio.build_board(game.board, 0).should == Array.new(9, ' ')
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns a board array representing the game board at move index 1" do
|
|
30
|
+
walkio.build_board(game.board, 1).should == ['x', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns a board array representing the game board at move index 2" do
|
|
34
|
+
walkio.build_board(game.board, 2).should == ['x', 'o', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "returns a board array representing the game board at move index 3" do
|
|
38
|
+
walkio.build_board(game.board, 3).should == ['x', 'o', ' ', ' ', 'x', ' ', ' ', ' ', ' ']
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "returns a board array representing the game board at move index 4" do
|
|
42
|
+
walkio.build_board(game.board, 4).should == ['x', 'o', ' ', ' ', 'x', 'o', ' ', ' ', ' ']
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "returns a board array representing the game board at move index 5" do
|
|
46
|
+
walkio.build_board(game.board, 5).should == ['x', 'o', ' ', ' ', 'x', 'o', ' ', ' ', 'x']
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#post_game_msg" do
|
|
51
|
+
it "prompts the user if they 'Would like to review the game history'?" do
|
|
52
|
+
walkio.stub(:process => nil)
|
|
53
|
+
walkio.presenter.stub(:input => 'n\n')
|
|
54
|
+
walkio.presenter.should_receive(:post_game_msg)
|
|
55
|
+
walkio.post_game_msg
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "#process" do
|
|
60
|
+
it "does nothing if the user inputs 'n' or 'N'" do
|
|
61
|
+
walkio.process('n').should == nil
|
|
62
|
+
walkio.process('N').should == nil
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "does presents the user with the `walk_msg` prompt if the user input 'y' or 'Y'" do
|
|
66
|
+
walkio.should_receive(:walk_msg)
|
|
67
|
+
walkio.process('y\n')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "gives the user an error message if they input invalid characters" do
|
|
71
|
+
walkio.process('1092093019823\n')
|
|
72
|
+
walkio.presenter.io.outstream.include? "error"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe "#walk_msg" do
|
|
77
|
+
it "prompts the user to enter 1, 0 or -1 to walk forward, exit or go backward in the game history" do
|
|
78
|
+
walkio.presenter.stub(:input => '0')
|
|
79
|
+
walkio.walk_msg
|
|
80
|
+
walkio.presenter.io.outstream.include? "Enter -1 to go back, 0 for main menu, or 1 to go forward"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
describe "#walk_history" do
|
|
85
|
+
before(:each) do
|
|
86
|
+
walkio.stub(:walk_msg => nil)
|
|
87
|
+
end
|
|
88
|
+
it "outputs the final board state when asked for a move index greater than the last move made index" do
|
|
89
|
+
final_board = walkio.game.board[]
|
|
90
|
+
walkio.walk_history(1)
|
|
91
|
+
walkio.presenter.io.outstream.include? final_board
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "returns a virgin board state when asked for a move index less than the first move made index" do
|
|
95
|
+
first_board = Array.new(9, " ")
|
|
96
|
+
walkio.walk_history(-100)
|
|
97
|
+
walkio.presenter.io.outstream.include? first_board
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "returns board at move index four when asked for the next move index (current move index is 3)" do
|
|
101
|
+
expected_board = ['x', 'o', ' ', ' ', 'x', 'o', ' ', ' ', ' ']
|
|
102
|
+
walkio.move_traverser.move_index = 3
|
|
103
|
+
walkio.walk_history(1)
|
|
104
|
+
walkio.presenter.io.outstream.include? expected_board
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "returns board at move index three when asked for the previous move index (current move index is 4)" do
|
|
108
|
+
expected_board = ['x', 'o', ' ', ' ', 'x', ' ', ' ', ' ', ' ']
|
|
109
|
+
walkio.move_traverser.move_index = 4
|
|
110
|
+
walkio.walk_history(-1)
|
|
111
|
+
walkio.presenter.io.outstream.include? expected_board
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
$LOAD_PATH.unshift File.dirname(__FILE__)
|
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../../../../../', __FILE__)
|
|
4
|
+
|
|
5
|
+
require 'simplecov'
|
|
6
|
+
#SimpleCov.start
|
|
7
|
+
require 'cli/clio'
|
|
8
|
+
require 'cli/cli_game'
|
|
9
|
+
require 'cli/player_selection'
|
|
10
|
+
require 'cli/board_selection'
|
|
11
|
+
require 'ttt/setup'
|
|
12
|
+
require 'cli/cli_presenter'
|
|
13
|
+
require 'cli/selection'
|
|
14
|
+
require 'cli/walk_history'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__install 'partials/title_history_partial.rb', :text => "4x4", :n => 16, :c => 1
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
squares {
|
|
2
|
+
width 415
|
|
3
|
+
horizontal_alignment :center
|
|
4
|
+
vertical_alignment :center
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
square0 {
|
|
8
|
+
extends :square
|
|
9
|
+
extends :left_of_square
|
|
10
|
+
extends :above_square
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
square1 {
|
|
14
|
+
extends :square0
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
square2 {
|
|
18
|
+
extends :square0
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
square3 {
|
|
22
|
+
extends :above_square
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
square4 {
|
|
26
|
+
extends :square0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
square5 {
|
|
30
|
+
extends :square0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
square6 {
|
|
34
|
+
extends :square0
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
square7 {
|
|
38
|
+
extends :above_square
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
square8 {
|
|
42
|
+
extends :square0
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
square9 {
|
|
46
|
+
extends :square0
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
square10 {
|
|
50
|
+
extends :square0
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
square11 {
|
|
54
|
+
extends :above_square
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
square12 {
|
|
58
|
+
extends :square
|
|
59
|
+
extends :left_of_square
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
square13 {
|
|
63
|
+
extends :square
|
|
64
|
+
extends :left_of_square
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
square14 {
|
|
68
|
+
extends :square
|
|
69
|
+
extends :left_of_square
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
square15 {
|
|
73
|
+
extends :square
|
|
74
|
+
}
|