bashrw-ttt 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/play.rb +10 -0
- data/lib/bashrw-ttt.rb +3 -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 +239 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
class GamePlayscript
|
2
|
+
attr_accessor :context, :game_id, :production
|
3
|
+
def initialize(options)
|
4
|
+
self.context = options.fetch(:context)
|
5
|
+
self.game_id = options.fetch(:game_id)
|
6
|
+
self.production = options.fetch(:production)
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize_history
|
11
|
+
production.context.initialize_history(game_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def view_history(index_diff)
|
15
|
+
game = production.context.get_game(game_id)
|
16
|
+
game.adjust_move_index(index_diff)
|
17
|
+
production.context.save_game(game_id, game)
|
18
|
+
process_game_history
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_game_history
|
22
|
+
history_board = production.context.get_history_board(game_id)
|
23
|
+
update_context_board(history_board)
|
24
|
+
end
|
25
|
+
|
26
|
+
def display_results
|
27
|
+
update_context_board
|
28
|
+
display_move_history
|
29
|
+
game_over_prompt
|
30
|
+
end
|
31
|
+
|
32
|
+
def game_move_index
|
33
|
+
context.get_history(game_id).length
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_move_index
|
37
|
+
production.move_index
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate_history_board
|
41
|
+
game = context.get_game(game_id)
|
42
|
+
game.history.move_traverser.adjust_move_index(production.move_index)
|
43
|
+
game.history.move_traverser.history_board_builder(game.board, production.move_index)
|
44
|
+
end
|
45
|
+
|
46
|
+
def player_move(cell)
|
47
|
+
@move = cell.id
|
48
|
+
return unless valid_move? && not_finished?
|
49
|
+
mark_move
|
50
|
+
update_context_board
|
51
|
+
update_move_history
|
52
|
+
prompt_next_player
|
53
|
+
display_results if finished?
|
54
|
+
process_ai_move unless finished?
|
55
|
+
end
|
56
|
+
|
57
|
+
def process_ai_move
|
58
|
+
return unless next_move_is_ai?
|
59
|
+
ai_move
|
60
|
+
update_context_board
|
61
|
+
update_move_history
|
62
|
+
prompt_next_player
|
63
|
+
display_results if finished?
|
64
|
+
if next_move_is_ai? && not_finished?
|
65
|
+
sleep 1
|
66
|
+
process_ai_move
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def which_board?
|
71
|
+
production.context.which_board(@game_id)
|
72
|
+
end
|
73
|
+
|
74
|
+
def set_move(cell)
|
75
|
+
@move = cell.id
|
76
|
+
end
|
77
|
+
|
78
|
+
def move
|
79
|
+
cell_location.to_i
|
80
|
+
end
|
81
|
+
|
82
|
+
def cell_location
|
83
|
+
return @move[-2..-1] if @move[-2..-1] !~ (/[a-z]/i)
|
84
|
+
@move[-1..-1]
|
85
|
+
end
|
86
|
+
|
87
|
+
def game_over_prompt
|
88
|
+
if winner?
|
89
|
+
@context.find_by_id("player_turn").text = "#{winner} is the winner!"
|
90
|
+
else
|
91
|
+
@context.find_by_id("player_turn").text = "It's a draw"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def update_context_board(new_board = board)
|
96
|
+
new_board.each_with_index do |square, index|
|
97
|
+
@context.find_by_id("square_text_#{index}").text = square
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def update_move_history
|
102
|
+
history = production.context.get_history(@game_id)
|
103
|
+
size = history.size
|
104
|
+
value = history[size - 1]
|
105
|
+
@context.find_by_id("move_history").text += "\n#{value.side} #{value.move}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def display_move_history
|
109
|
+
history = production.context.get_history(@game_id)
|
110
|
+
@context.find_by_id("move_history").text = "Move History"
|
111
|
+
result_string = ''
|
112
|
+
history.each do |value|
|
113
|
+
@context.find_by_id("move_history").text += "\n#{value.side} #{value.move}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def prompt_next_player
|
118
|
+
@context.find_by_id("player_turn").text = "#{which_current_player?}'s turn"
|
119
|
+
end
|
120
|
+
|
121
|
+
def ai_move
|
122
|
+
production.context.ai_move(@game_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
def next_move_is_ai?
|
126
|
+
production.context.ai_move?(@game_id)
|
127
|
+
end
|
128
|
+
|
129
|
+
def mark_move
|
130
|
+
player = production.context.which_current_player?(@game_id)
|
131
|
+
production.context.update_game(@game_id, move, player_side(player))
|
132
|
+
end
|
133
|
+
|
134
|
+
def player_side(player_num)
|
135
|
+
if player_num == "Player 1"
|
136
|
+
"x"
|
137
|
+
else
|
138
|
+
"o"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def board
|
143
|
+
production.context.board(@game_id)
|
144
|
+
end
|
145
|
+
|
146
|
+
def which_current_player?
|
147
|
+
production.context.which_current_player?(@game_id)
|
148
|
+
end
|
149
|
+
|
150
|
+
def finished?
|
151
|
+
production.context.finished?(@game_id)
|
152
|
+
end
|
153
|
+
|
154
|
+
def not_finished?
|
155
|
+
!finished?
|
156
|
+
end
|
157
|
+
|
158
|
+
def winner?
|
159
|
+
production.context.winner?(@game_id)
|
160
|
+
end
|
161
|
+
|
162
|
+
def winner
|
163
|
+
production.context.winner(@game_id)
|
164
|
+
end
|
165
|
+
|
166
|
+
def valid_move?
|
167
|
+
production.context.valid_move?(@game_id, move)
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift File.expand_path("../../../../", __FILE__)
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require "playscripts/game_playscript"
|
6
|
+
require 'ttt/setup'
|
7
|
+
require 'ttt/context'
|
8
|
+
|
9
|
+
on_production_loaded do
|
10
|
+
backstage_pass :context
|
11
|
+
backstage_pass :game_id
|
12
|
+
backstage_pass :limelight_game
|
13
|
+
backstage_pass :move_index
|
14
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'playscripts/game_playscript'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'ttt/context'
|
5
|
+
require 'ttt/setup'
|
6
|
+
|
7
|
+
describe "GamePlayscript" do
|
8
|
+
let(:context) { TTT::Context.instance }
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
context.setup = TTT::Setup
|
12
|
+
players = context.players
|
13
|
+
boards = context.boards
|
14
|
+
ai_game_id = context.create_game(players[1], players[1], boards[0])
|
15
|
+
game_id = context.create_game(players[0], players[0], boards[0])
|
16
|
+
production = stub(:context => context)
|
17
|
+
@ai_game_ps = GamePlayscript.new(:context => context, :game_id => ai_game_id, :production => production)
|
18
|
+
@game_ps = GamePlayscript.new(:context => context, :game_id => game_id, :production => production)
|
19
|
+
@game = @game_ps.context.get_game(@game_ps.game_id)
|
20
|
+
@ai_game = @ai_game_ps.context.get_game(@ai_game_ps.game_id)
|
21
|
+
@game_id = @game_ps.game_id
|
22
|
+
@ai_id = @ai_game_ps.game_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def save_game(id, game)
|
26
|
+
context.save_game(id, game)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#set_move" do
|
30
|
+
before(:each) do
|
31
|
+
@mock_move = double('move')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sets the player's move from a board square for squares 0 - 8" do
|
35
|
+
@mock_move.should_receive(:id).and_return("square1")
|
36
|
+
@game_ps.set_move(@mock_move)
|
37
|
+
@game_ps.move.should == 1
|
38
|
+
end
|
39
|
+
|
40
|
+
it "sets the player's move from a board square for squares 9 - 26" do
|
41
|
+
@mock_move.should_receive(:id).and_return("square22")
|
42
|
+
@game_ps.set_move(@mock_move)
|
43
|
+
@game_ps.move.should == 22
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#which_current_player?" do
|
48
|
+
it "returns 'Player 1' when it's player1's turn" do
|
49
|
+
@game_ps.which_current_player?.should == "Player 1"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns 'Player 2' when it's player2's turn" do
|
53
|
+
@game.current_player = @game.player2
|
54
|
+
save_game(@game_id, @game)
|
55
|
+
@game_ps.which_current_player?.should == "Player 2"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#finished?" do
|
60
|
+
it "returns true when the game board is full" do
|
61
|
+
@game.board.board = %w(a b c d e f g h i)
|
62
|
+
save_game(@game_id, @game)
|
63
|
+
@game_ps.finished?.should == true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns false when the game board contains a blank space (means free square)" do
|
67
|
+
@game.board.board = Array.new(9, " ")
|
68
|
+
save_game(@game_id, @game)
|
69
|
+
@game_ps.finished?.should == false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#not_finished?" do
|
74
|
+
it "returns true when the game is not finished" do
|
75
|
+
@game_ps.not_finished?.should == true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns false when the game is finished" do
|
79
|
+
@game.board.board = [0,1,2,3,4,5,6,7,8]
|
80
|
+
save_game(@game_id, @game)
|
81
|
+
@game_ps.not_finished?.should == false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#finished" do
|
86
|
+
it "returns true when the game is over" do
|
87
|
+
@game.board.board = ['x', 'o', 'x', 'o', 'x', 'o', 'x', 'o', 'x', 'o']
|
88
|
+
save_game(@game_id, @game)
|
89
|
+
@game_ps.finished?.should == true
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns false when the game isn't over yet" do
|
93
|
+
@game_ps.finished?.should == false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#winner" do
|
98
|
+
before(:each) do
|
99
|
+
@game.board.board = ['x', 'x', 'x', '', '', '', '', '', '']
|
100
|
+
save_game(@game_id, @game)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "displays `Player 1 is the winner` when player 1 wins" do
|
104
|
+
@game.current_player = @game.player2
|
105
|
+
save_game(@game_id, @game)
|
106
|
+
@game_ps.winner.should == "Player 1"
|
107
|
+
end
|
108
|
+
|
109
|
+
it "displays `Player 2 is the winner` when player 2 wins" do
|
110
|
+
@game_ps.winner.should == "Player 2"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
describe "#winner?" do
|
116
|
+
it "returns true when the game has a winner" do
|
117
|
+
@game.board.board = ['x', 'x', 'x', '', '', '', '', '', '']
|
118
|
+
save_game(@game_id, @game)
|
119
|
+
@game_ps.winner?.should == true
|
120
|
+
end
|
121
|
+
|
122
|
+
it "returns false when the game does not have a winner" do
|
123
|
+
@game.board.board = ['y', 't', 'z', 'c', 'h', 'g', 'c', 'p', 'q']
|
124
|
+
save_game(@game_id, @game)
|
125
|
+
@game_ps.winner?.should == false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#valid_move?" do
|
130
|
+
before(:each) do
|
131
|
+
@mock_move = double('move')
|
132
|
+
@mock_move.should_receive(:id).and_return("square1")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns true when the move is valid" do
|
136
|
+
@game_ps.set_move(@mock_move)
|
137
|
+
@game_ps.valid_move?.should == true
|
138
|
+
end
|
139
|
+
|
140
|
+
it "returns flase when the move is invalid" do
|
141
|
+
@game.board.board = %w(a b c d e f g h i)
|
142
|
+
save_game(@game_id, @game)
|
143
|
+
@game_ps.set_move(@mock_move)
|
144
|
+
@game_ps.valid_move?.should == false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "#next_move_is_ai?" do
|
149
|
+
it "returns true when current player is an ai player" do
|
150
|
+
@ai_game_ps.next_move_is_ai?.should == true
|
151
|
+
end
|
152
|
+
|
153
|
+
it "returns false when the curent player is a human player" do
|
154
|
+
@game_ps.next_move_is_ai?.should == false
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#board" do
|
159
|
+
it "requests the board array from the game" do
|
160
|
+
@game_ps.board.should == @game.board.board
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#mark_move" do
|
165
|
+
it "sends a mark_move message to the game" do
|
166
|
+
@game_ps.should_receive(:move).and_return(1)
|
167
|
+
@game_ps.context.should_receive(:update_game).with(@game_id, 1, 'x')
|
168
|
+
@game_ps.mark_move
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "#ai_move" do
|
173
|
+
it "sends a next_move message to the game indicating it's the computer player's turn" do
|
174
|
+
@game_ps.context.should_receive(:ai_move).with(@game_id)
|
175
|
+
@game_ps.ai_move
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe "#which_board" do
|
180
|
+
it "returns 'three_by_three' when it's a 3x3 board" do
|
181
|
+
@game_ps.which_board?.should == "three_by_three"
|
182
|
+
end
|
183
|
+
|
184
|
+
it "returns 'four_by_four' when it's a 4x4 board" do
|
185
|
+
@game.board = TTT::FourByFour.new
|
186
|
+
save_game(@game_id, @game)
|
187
|
+
@game_ps.which_board?.should == "four_by_four"
|
188
|
+
end
|
189
|
+
|
190
|
+
it "returns 'three_by_three_by_three' when it's a 3x3x3 board" do
|
191
|
+
@game.board = TTT::ThreeByThreeByThree.new
|
192
|
+
save_game(@game_id, @game)
|
193
|
+
@game_ps.which_board?.should == "three_by_three_by_three"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context "user wants to move through a previously played game's move history" do
|
198
|
+
before(:each) do
|
199
|
+
@game.record_move(0, 'x')
|
200
|
+
@game.mark_move(0, 'x')
|
201
|
+
@game.record_move(1, 'o')
|
202
|
+
@game.mark_move(1, 'o')
|
203
|
+
@game.record_move(4, 'x')
|
204
|
+
@game.mark_move(4, 'x')
|
205
|
+
@game.record_move(2, 'o')
|
206
|
+
@game.mark_move(2, 'o')
|
207
|
+
@game.record_move(8, 'x')
|
208
|
+
@game.mark_move(8, 'x')
|
209
|
+
save_game(@game_id, @game)
|
210
|
+
end
|
211
|
+
|
212
|
+
describe "#game_move_index" do
|
213
|
+
it "gets the number of moves made for a completed game" do
|
214
|
+
@game_ps.game_move_index.should == 5
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ttt/setup'
|
3
|
+
require 'ttt/context'
|
4
|
+
|
5
|
+
describe "main menu scene" do
|
6
|
+
|
7
|
+
uses_limelight :scene => "main_menu", :hidden => true
|
8
|
+
|
9
|
+
it "has a 'new game' button" do
|
10
|
+
button = scene.find("new_game")
|
11
|
+
button.text.should == "New Game"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a 'load game' button" do
|
15
|
+
button = scene.find("load_game")
|
16
|
+
button.text.should == "Load Game"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a 'exit' button" do
|
20
|
+
button = scene.find("exit")
|
21
|
+
button.text.should == "Exit"
|
22
|
+
end
|
23
|
+
|
24
|
+
context "user clicks `Play Game`" do
|
25
|
+
xit "loads the 'new_game' scene" do
|
26
|
+
new_game_button = scene.find("new_game")
|
27
|
+
mouse.push new_game_button
|
28
|
+
current_scene.name.should == "new_game"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "user clicks `Load Game`" do
|
33
|
+
xit "loads the 'load_game' scene" do
|
34
|
+
mouse.push scene.find("load_game")
|
35
|
+
current_scene.name.should == "LoadGame"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ttt/setup'
|
3
|
+
require 'ttt/context'
|
4
|
+
|
5
|
+
describe "new game scene" do
|
6
|
+
|
7
|
+
uses_limelight :scene => "new_game", :hidden => true
|
8
|
+
|
9
|
+
%w(player1 player2).each do |player_num|
|
10
|
+
it "has a #{player_num}" do
|
11
|
+
player = scene.find("#{player_num}")
|
12
|
+
player.should_not be_nil
|
13
|
+
player.drop_down.value.should == TTT::Setup.new.players.first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a setup_button" do
|
18
|
+
scene.find("setup_button").should_not be_nil
|
19
|
+
scene.find("setup_button").text.should == "Start Game"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has a board list" do
|
23
|
+
scene.find("board").drop_down.value.should == TTT::Setup.new.boards.first
|
24
|
+
end
|
25
|
+
|
26
|
+
[1,2].each do |num|
|
27
|
+
it "finds the dropdown values for player#{num}" do
|
28
|
+
scene.find("player#{num}").text.should == "Human"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it "adds a context singleton to production" do
|
33
|
+
production.context.class.should == TTT::Context
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when start game button is pressed" do
|
37
|
+
it "creates a new game" do
|
38
|
+
scene.find("player1").drop_down.value = "AI Medium"
|
39
|
+
scene.find("player2").drop_down.value = "AI Medium"
|
40
|
+
scene.find("board").drop_down.value = "3x3"
|
41
|
+
mouse.push scene.find("setup_button")
|
42
|
+
production.game_id.should_not == nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
setup_list {
|
2
|
+
text_color :white
|
3
|
+
font_size 20
|
4
|
+
width "50%"
|
5
|
+
horizontal_alignment :right
|
6
|
+
vertical_alignment :top
|
7
|
+
right_margin 20
|
8
|
+
bottom_margin 20
|
9
|
+
}
|
10
|
+
|
11
|
+
type_list {
|
12
|
+
text_color :black
|
13
|
+
font_size 20
|
14
|
+
width "50%"
|
15
|
+
horizontal_alignment :left
|
16
|
+
left_margin 20
|
17
|
+
}
|
18
|
+
|
19
|
+
setup_button_row {
|
20
|
+
width "100%"
|
21
|
+
horizontal_alignment :center
|
22
|
+
}
|
23
|
+
|
24
|
+
row {
|
25
|
+
height "10%"
|
26
|
+
width "100%"
|
27
|
+
}
|
28
|
+
|
29
|
+
third {
|
30
|
+
width "33%"
|
31
|
+
}
|
32
|
+
|
33
|
+
half {
|
34
|
+
width "50%"
|
35
|
+
}
|
36
|
+
|
37
|
+
ttt {
|
38
|
+
background_color :gray
|
39
|
+
height 800
|
40
|
+
width 1200
|
41
|
+
}
|
42
|
+
|
43
|
+
title {
|
44
|
+
horizontal_alignment :center
|
45
|
+
top_margin 100
|
46
|
+
font_size 40
|
47
|
+
text_color :white
|
48
|
+
width "100%"
|
49
|
+
}
|
50
|
+
|
51
|
+
move_history {
|
52
|
+
float :on
|
53
|
+
text_color :white
|
54
|
+
font_size 15
|
55
|
+
x 1000
|
56
|
+
y 200
|
57
|
+
}
|
58
|
+
|
59
|
+
player_turn {
|
60
|
+
horizontal_alignment :center
|
61
|
+
text_color :white
|
62
|
+
font_size 30
|
63
|
+
top_margin 30
|
64
|
+
width "100%"
|
65
|
+
}
|
66
|
+
|
67
|
+
game_board_row {
|
68
|
+
width "100%"
|
69
|
+
top_margin 40
|
70
|
+
horizontal_alignment :center
|
71
|
+
}
|
72
|
+
|
73
|
+
menu_button_row {
|
74
|
+
width "100%"
|
75
|
+
horizontal_alignment :center
|
76
|
+
top_margin 40
|
77
|
+
}
|
78
|
+
|
79
|
+
squares {
|
80
|
+
width 310
|
81
|
+
}
|
82
|
+
|
83
|
+
square {
|
84
|
+
height 100
|
85
|
+
width 100
|
86
|
+
}
|
87
|
+
|
88
|
+
square_text {
|
89
|
+
width "100%"
|
90
|
+
height "100%"
|
91
|
+
text_color :white
|
92
|
+
font_size 40
|
93
|
+
horizontal_alignment :center
|
94
|
+
vertical_alignment :center
|
95
|
+
}
|
96
|
+
|
97
|
+
above_square {
|
98
|
+
bottom_border_width 5
|
99
|
+
}
|
100
|
+
|
101
|
+
left_of_square {
|
102
|
+
right_border_width 5
|
103
|
+
}
|
104
|
+
|
105
|
+
move_button_row {
|
106
|
+
float :on
|
107
|
+
x 472
|
108
|
+
y 720
|
109
|
+
background_color :gray
|
110
|
+
width "100%"
|
111
|
+
}
|
112
|
+
|
113
|
+
left_button {
|
114
|
+
horizontal_alignment :center
|
115
|
+
}
|
116
|
+
|
117
|
+
right_button {
|
118
|
+
horizontal_alignment :center
|
119
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
__install 'partials/title_history_partial.rb', :text => "3x3", :n => 9, :c => 1
|
@@ -0,0 +1,39 @@
|
|
1
|
+
square0 {
|
2
|
+
extends :square
|
3
|
+
extends :above_square
|
4
|
+
extends :left_of_square
|
5
|
+
}
|
6
|
+
|
7
|
+
square1 {
|
8
|
+
extends :square0
|
9
|
+
}
|
10
|
+
|
11
|
+
square2 {
|
12
|
+
extends :above_square
|
13
|
+
}
|
14
|
+
|
15
|
+
square3 {
|
16
|
+
extends :square0
|
17
|
+
}
|
18
|
+
|
19
|
+
square4 {
|
20
|
+
extends :square0
|
21
|
+
}
|
22
|
+
|
23
|
+
square5 {
|
24
|
+
extends :above_square
|
25
|
+
}
|
26
|
+
|
27
|
+
square6 {
|
28
|
+
extends :square
|
29
|
+
extends :left_of_square
|
30
|
+
}
|
31
|
+
|
32
|
+
square7 {
|
33
|
+
extends :square
|
34
|
+
extends :left_of_square
|
35
|
+
}
|
36
|
+
|
37
|
+
square8 {
|
38
|
+
extends :square
|
39
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
__install "partials/title_history_partial.rb", :c => 3, :n => 9, :text => "3x3x3"
|