bashrw-ttt 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/bin/play.rb +10 -0
  2. data/lib/bashrw-ttt.rb +3 -0
  3. data/lib/ttt/ai.rb +33 -0
  4. data/lib/ttt/ai_easy.rb +17 -0
  5. data/lib/ttt/ai_hard.rb +21 -0
  6. data/lib/ttt/ai_medium.rb +21 -0
  7. data/lib/ttt/ai_medium_back.rb +58 -0
  8. data/lib/ttt/board.rb +37 -0
  9. data/lib/ttt/config_helper.rb +53 -0
  10. data/lib/ttt/config_options.rb +27 -0
  11. data/lib/ttt/context.rb +214 -0
  12. data/lib/ttt/four_by_four.rb +62 -0
  13. data/lib/ttt/game.rb +94 -0
  14. data/lib/ttt/game_history.rb +37 -0
  15. data/lib/ttt/game_interactor.rb +126 -0
  16. data/lib/ttt/human.rb +12 -0
  17. data/lib/ttt/interfaces/cli/lib/cli/board_selection.rb +34 -0
  18. data/lib/ttt/interfaces/cli/lib/cli/cli_game.rb +186 -0
  19. data/lib/ttt/interfaces/cli/lib/cli/cli_presenter.rb +216 -0
  20. data/lib/ttt/interfaces/cli/lib/cli/clio.rb +17 -0
  21. data/lib/ttt/interfaces/cli/lib/cli/play_again.rb +38 -0
  22. data/lib/ttt/interfaces/cli/lib/cli/player_selection.rb +43 -0
  23. data/lib/ttt/interfaces/cli/lib/cli/selection.rb +8 -0
  24. data/lib/ttt/interfaces/cli/lib/cli/walk_history.rb +48 -0
  25. data/lib/ttt/interfaces/cli/spec/cli/board_selection_spec.rb +29 -0
  26. data/lib/ttt/interfaces/cli/spec/cli/cli_game_spec.rb +376 -0
  27. data/lib/ttt/interfaces/cli/spec/cli/cli_presenter_spec.rb +147 -0
  28. data/lib/ttt/interfaces/cli/spec/cli/play_again_spec.rb +39 -0
  29. data/lib/ttt/interfaces/cli/spec/cli/player_selection_spec.rb +62 -0
  30. data/lib/ttt/interfaces/cli/spec/cli/walk_history_spec.rb +115 -0
  31. data/lib/ttt/interfaces/cli/spec/spec_helper.rb +14 -0
  32. data/lib/ttt/interfaces/limelight/four_by_four/props.rb +1 -0
  33. data/lib/ttt/interfaces/limelight/four_by_four/styles.rb +74 -0
  34. data/lib/ttt/interfaces/limelight/four_by_four_finished/props.rb +1 -0
  35. data/lib/ttt/interfaces/limelight/four_by_four_finished/styles.rb +74 -0
  36. data/lib/ttt/interfaces/limelight/game_list/players/load_button.rb +10 -0
  37. data/lib/ttt/interfaces/limelight/game_list/props.rb +17 -0
  38. data/lib/ttt/interfaces/limelight/game_list/styles.rb +8 -0
  39. data/lib/ttt/interfaces/limelight/main_menu/players/exit_ttt.rb +3 -0
  40. data/lib/ttt/interfaces/limelight/main_menu/players/load_game.rb +3 -0
  41. data/lib/ttt/interfaces/limelight/main_menu/players/new_game.rb +3 -0
  42. data/lib/ttt/interfaces/limelight/main_menu/props.rb +17 -0
  43. data/lib/ttt/interfaces/limelight/new_game/players/board_type.rb +1 -0
  44. data/lib/ttt/interfaces/limelight/new_game/players/new_game.rb +5 -0
  45. data/lib/ttt/interfaces/limelight/new_game/players/player_type.rb +1 -0
  46. data/lib/ttt/interfaces/limelight/new_game/players/setup_button.rb +21 -0
  47. data/lib/ttt/interfaces/limelight/new_game/props.rb +21 -0
  48. data/lib/ttt/interfaces/limelight/new_game/styles.rb +23 -0
  49. data/lib/ttt/interfaces/limelight/partials/board_partial.rb +14 -0
  50. data/lib/ttt/interfaces/limelight/partials/menu_button_partial.rb +5 -0
  51. data/lib/ttt/interfaces/limelight/partials/move_history_partial.rb +6 -0
  52. data/lib/ttt/interfaces/limelight/partials/title_history_partial.rb +10 -0
  53. data/lib/ttt/interfaces/limelight/players/board.rb +3 -0
  54. data/lib/ttt/interfaces/limelight/players/game.rb +4 -0
  55. data/lib/ttt/interfaces/limelight/players/generic_move_history.rb +5 -0
  56. data/lib/ttt/interfaces/limelight/players/generic_player.rb +8 -0
  57. data/lib/ttt/interfaces/limelight/players/left_button.rb +3 -0
  58. data/lib/ttt/interfaces/limelight/players/main_menu.rb +3 -0
  59. data/lib/ttt/interfaces/limelight/players/right_button.rb +3 -0
  60. data/lib/ttt/interfaces/limelight/playscripts/game_playscript.rb +169 -0
  61. data/lib/ttt/interfaces/limelight/production.rb +14 -0
  62. data/lib/ttt/interfaces/limelight/spec/game_playscript_spec.rb +218 -0
  63. data/lib/ttt/interfaces/limelight/spec/main_menu/main_menu_spec.rb +38 -0
  64. data/lib/ttt/interfaces/limelight/spec/new_game/new_game_spec.rb +45 -0
  65. data/lib/ttt/interfaces/limelight/spec/spec_helper.rb +8 -0
  66. data/lib/ttt/interfaces/limelight/stages.rb +6 -0
  67. data/lib/ttt/interfaces/limelight/styles.rb +119 -0
  68. data/lib/ttt/interfaces/limelight/three_by_three/props.rb +1 -0
  69. data/lib/ttt/interfaces/limelight/three_by_three/styles.rb +39 -0
  70. data/lib/ttt/interfaces/limelight/three_by_three_by_three/props.rb +1 -0
  71. data/lib/ttt/interfaces/limelight/three_by_three_by_three/styles.rb +119 -0
  72. data/lib/ttt/interfaces/limelight/three_by_three_by_three_finished/props.rb +1 -0
  73. data/lib/ttt/interfaces/limelight/three_by_three_by_three_finished/styles.rb +119 -0
  74. data/lib/ttt/interfaces/limelight/three_by_three_finished/props.rb +1 -0
  75. data/lib/ttt/interfaces/limelight/three_by_three_finished/styles.rb +39 -0
  76. data/lib/ttt/interfaces/rails/app/controllers/application_controller.rb +3 -0
  77. data/lib/ttt/interfaces/rails/app/controllers/ttt_games_controller.rb +86 -0
  78. data/lib/ttt/interfaces/rails/app/helpers/application_helper.rb +2 -0
  79. data/lib/ttt/interfaces/rails/app/models/ttt_game.rb +34 -0
  80. data/lib/ttt/interfaces/rails/app/presenters/web_game_presenter.rb +159 -0
  81. data/lib/ttt/interfaces/rails/autotest/discover.rb +1 -0
  82. data/lib/ttt/interfaces/rails/config/application.rb +67 -0
  83. data/lib/ttt/interfaces/rails/config/boot.rb +6 -0
  84. data/lib/ttt/interfaces/rails/config/environment.rb +5 -0
  85. data/lib/ttt/interfaces/rails/config/environments/development.rb +37 -0
  86. data/lib/ttt/interfaces/rails/config/environments/production.rb +67 -0
  87. data/lib/ttt/interfaces/rails/config/environments/test.rb +37 -0
  88. data/lib/ttt/interfaces/rails/config/initializers/backtrace_silencers.rb +7 -0
  89. data/lib/ttt/interfaces/rails/config/initializers/inflections.rb +15 -0
  90. data/lib/ttt/interfaces/rails/config/initializers/mime_types.rb +5 -0
  91. data/lib/ttt/interfaces/rails/config/initializers/secret_token.rb +7 -0
  92. data/lib/ttt/interfaces/rails/config/initializers/session_store.rb +8 -0
  93. data/lib/ttt/interfaces/rails/config/initializers/wrap_parameters.rb +14 -0
  94. data/lib/ttt/interfaces/rails/config/routes.rb +49 -0
  95. data/lib/ttt/interfaces/rails/db/schema.rb +28 -0
  96. data/lib/ttt/interfaces/rails/db/seeds.rb +7 -0
  97. data/lib/ttt/interfaces/rails/spec/controllers/ttt_games_controller_spec.rb +211 -0
  98. data/lib/ttt/interfaces/rails/spec/models/ttt_game_spec.rb +76 -0
  99. data/lib/ttt/interfaces/rails/spec/presenters/web_game_presenter_spec.rb +52 -0
  100. data/lib/ttt/interfaces/rails/spec/spec_helper.rb +13 -0
  101. data/lib/ttt/interfaces/web_interface/html_generator.rb +76 -0
  102. data/lib/ttt/interfaces/web_interface/web_game_presenter.rb +0 -0
  103. data/lib/ttt/minimax.rb +46 -0
  104. data/lib/ttt/move_history.rb +10 -0
  105. data/lib/ttt/move_traverser.rb +49 -0
  106. data/lib/ttt/player.rb +15 -0
  107. data/lib/ttt/riak_db.rb +53 -0
  108. data/lib/ttt/setup.rb +59 -0
  109. data/lib/ttt/three_by_three.rb +35 -0
  110. data/lib/ttt/three_by_three_by_three.rb +37 -0
  111. data/spec/spec_helper.rb +22 -0
  112. data/spec/ttt/ai_easy_spec.rb +15 -0
  113. data/spec/ttt/ai_hard_spec.rb +76 -0
  114. data/spec/ttt/ai_medium_spec.rb +65 -0
  115. data/spec/ttt/ai_spec.rb +50 -0
  116. data/spec/ttt/board_spec.rb +96 -0
  117. data/spec/ttt/config_helper_spec.rb +54 -0
  118. data/spec/ttt/context_spec.rb +398 -0
  119. data/spec/ttt/four_by_four_spec.rb +112 -0
  120. data/spec/ttt/game_history_spec.rb +41 -0
  121. data/spec/ttt/game_interactor_spec.rb +197 -0
  122. data/spec/ttt/game_spec.rb +246 -0
  123. data/spec/ttt/human_spec.rb +18 -0
  124. data/spec/ttt/move_history_spec.rb +13 -0
  125. data/spec/ttt/move_traverser_spec.rb +75 -0
  126. data/spec/ttt/player_spec.rb +13 -0
  127. data/spec/ttt/riak_db_spec.rb +64 -0
  128. data/spec/ttt/setup_spec.rb +63 -0
  129. data/spec/ttt/three_by_three_by_three_spec.rb +130 -0
  130. data/spec/ttt/three_by_three_spec.rb +110 -0
  131. metadata +239 -0
@@ -0,0 +1,119 @@
1
+ move_history {
2
+ float :on
3
+ text_color :white
4
+ font_size 15
5
+ x 1100
6
+ y 200
7
+ }
8
+
9
+ square0 {
10
+ extends :square
11
+ extends :above_square
12
+ extends :left_of_square
13
+ }
14
+
15
+ square9 {
16
+ extends :square0
17
+ }
18
+
19
+ square18 {
20
+ extends :square0
21
+ }
22
+
23
+ square1 {
24
+ extends :square0
25
+ }
26
+
27
+ square10 {
28
+ extends :square0
29
+ }
30
+
31
+ square19 {
32
+ extends :square0
33
+ }
34
+
35
+ square2 {
36
+ extends :square
37
+ extends :above_square
38
+ }
39
+
40
+ square11 {
41
+ extends :square2
42
+ }
43
+
44
+ square20 {
45
+ extends :square2
46
+ }
47
+
48
+ square3 {
49
+ extends :square0
50
+ }
51
+
52
+ square12 {
53
+ extends :square0
54
+ }
55
+
56
+ square21 {
57
+ extends :square0
58
+ }
59
+
60
+ square4 {
61
+ extends :square0
62
+ }
63
+
64
+ square13 {
65
+ extends :square0
66
+ }
67
+
68
+ square22 {
69
+ extends :square0
70
+ }
71
+
72
+ square5 {
73
+ extends :square2
74
+ }
75
+
76
+ square14 {
77
+ extends :square2
78
+ }
79
+
80
+ square23 {
81
+ extends :square2
82
+ }
83
+
84
+ square6 {
85
+ extends :square
86
+ extends :left_of_square
87
+ }
88
+
89
+ square15 {
90
+ extends :square6
91
+ }
92
+
93
+ square24 {
94
+ extends :square6
95
+ }
96
+
97
+ square7 {
98
+ extends :square6
99
+ }
100
+
101
+ square16 {
102
+ extends :square6
103
+ }
104
+
105
+ square25 {
106
+ extends :square6
107
+ }
108
+
109
+ square8 {
110
+ extends :square
111
+ }
112
+
113
+ square17 {
114
+ extends :square
115
+ }
116
+
117
+ square26 {
118
+ extends :square
119
+ }
@@ -0,0 +1 @@
1
+ __install "partials/move_history_partial.rb", :c => 3, :n => 9, :text => "3x3x3"
@@ -0,0 +1,119 @@
1
+ move_history {
2
+ float :on
3
+ text_color :white
4
+ font_size 15
5
+ x 1100
6
+ y 200
7
+ }
8
+
9
+ square0 {
10
+ extends :square
11
+ extends :above_square
12
+ extends :left_of_square
13
+ }
14
+
15
+ square9 {
16
+ extends :square0
17
+ }
18
+
19
+ square18 {
20
+ extends :square0
21
+ }
22
+
23
+ square1 {
24
+ extends :square0
25
+ }
26
+
27
+ square10 {
28
+ extends :square0
29
+ }
30
+
31
+ square19 {
32
+ extends :square0
33
+ }
34
+
35
+ square2 {
36
+ extends :square
37
+ extends :above_square
38
+ }
39
+
40
+ square11 {
41
+ extends :square2
42
+ }
43
+
44
+ square20 {
45
+ extends :square2
46
+ }
47
+
48
+ square3 {
49
+ extends :square0
50
+ }
51
+
52
+ square12 {
53
+ extends :square0
54
+ }
55
+
56
+ square21 {
57
+ extends :square0
58
+ }
59
+
60
+ square4 {
61
+ extends :square0
62
+ }
63
+
64
+ square13 {
65
+ extends :square0
66
+ }
67
+
68
+ square22 {
69
+ extends :square0
70
+ }
71
+
72
+ square5 {
73
+ extends :square2
74
+ }
75
+
76
+ square14 {
77
+ extends :square2
78
+ }
79
+
80
+ square23 {
81
+ extends :square2
82
+ }
83
+
84
+ square6 {
85
+ extends :square
86
+ extends :left_of_square
87
+ }
88
+
89
+ square15 {
90
+ extends :square6
91
+ }
92
+
93
+ square24 {
94
+ extends :square6
95
+ }
96
+
97
+ square7 {
98
+ extends :square6
99
+ }
100
+
101
+ square16 {
102
+ extends :square6
103
+ }
104
+
105
+ square25 {
106
+ extends :square6
107
+ }
108
+
109
+ square8 {
110
+ extends :square
111
+ }
112
+
113
+ square17 {
114
+ extends :square
115
+ }
116
+
117
+ square26 {
118
+ extends :square
119
+ }
@@ -0,0 +1 @@
1
+ __install 'partials/move_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,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,86 @@
1
+ require 'ttt/setup'
2
+ require 'ttt/context'
3
+
4
+ class TttGamesController < ApplicationController
5
+ before_filter :set_context
6
+
7
+ def welcome
8
+ redirect_to :action => "new"
9
+ end
10
+
11
+ def new
12
+ cookies[:game_id] = nil
13
+ cookies[:move_index] = nil
14
+ @players = @context.players
15
+ @boards = @context.boards
16
+ end
17
+
18
+ def create_game
19
+ game = @context.setup.new_game(player1: params[:player1], player2: params[:player2], board: params[:board])
20
+ cookies[:game_id] = @context.add_game(game)
21
+ flash[:notice] = "Welcome to Tic Tac Toe!"
22
+ redirect_to :action => "show"
23
+ end
24
+
25
+ def show
26
+ @game = @context.get_game(cookies[:game_id])
27
+ @web_game_presenter = WebGamePresenter.for(board: @game.board, id: cookies[:game_id])
28
+ @web_game_history = @context.get_history(cookies[:game_id])
29
+ @id = cookies[:game_id]
30
+ @finished = @game.board.finished?
31
+ flash[:notice], view_file = TttGame.evaluate_game(cookies[:game_id], @context)
32
+ render view_file
33
+ end
34
+
35
+ def game_list
36
+ @games = @context.game_list
37
+ end
38
+
39
+ def get_game
40
+ cookies[:game_id] = params[:id]
41
+ redirect_to :action => "show"
42
+ end
43
+
44
+ def move_history
45
+ @game = @context.get_game(params[:id])
46
+ @id, cookies[:game_id] = params[:id], params[:id]
47
+ @web_game_history = @context.get_history(@id)
48
+ adjust_move_index_pointers(params[:index_diff].to_i)
49
+ @game.board.board = TttGame.get_history_board(@game, cookies[:move_index])
50
+ @web_game_presenter = WebGamePresenter.for(board: @game.board, id: cookies[:game_id])
51
+ @finished = true
52
+ cookies[:last_id] = @id
53
+ flash[:notice], view_file = TttGame.evaluate_game(cookies[:game_id], @context)
54
+ render view_file
55
+ end
56
+
57
+ def update_game
58
+ @game = @context.get_game(params[:id])
59
+ @context.update_game(params[:id], params[:move], @game.current_player.side)
60
+ cookies[:game_id] = params[:id]
61
+ redirect_to :action => "show"
62
+ end
63
+
64
+ def next_move
65
+ @context.ai_move(params[:id])
66
+ redirect_to :action => "show"
67
+ end
68
+
69
+ private
70
+ def adjust_move_index_pointers(index_diff)
71
+ max_length = TttGame.get_history_length(cookies[:game_id], @context)
72
+ if cookies[:game_id] == cookies[:last_id]
73
+ cur_index = cookies[:move_index].to_i
74
+ temp_index = cur_index + index_diff
75
+ cur_index += index_diff if((max_length - temp_index.abs >= 0) && (temp_index <= 0))
76
+ cookies[:move_index] = cur_index
77
+ else
78
+ cookies[:move_index] = index_diff.to_i
79
+ end
80
+ end
81
+
82
+ def set_context
83
+ @context = TTT::Context.instance
84
+ @context.setup = TTT::Setup
85
+ end
86
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ class TttGame
4
+ def self.evaluate_game(game_id, context)
5
+ @game_id, @context = game_id, context
6
+ if finished? && winner?
7
+ winner = @context.winner(@game_id) + " is the winner!"
8
+ return winner, "end_game"
9
+ elsif finished?
10
+ return "It's a draw", "end_game"
11
+ else
12
+ player = @context.which_current_player?(@game_id) + "'s turn"
13
+ return player, "show"
14
+ end
15
+ end
16
+
17
+ def self.get_history_length(game_id, context)
18
+ context.get_history_length(game_id)
19
+ end
20
+
21
+ def self.get_history_board(game, move_index_diff)
22
+ move_traverser = game.history.move_traverser
23
+ move_traverser.adjust_move_index(move_index_diff.to_i)
24
+ move_traverser.history_board_builder(game.board, move_traverser.move_index)
25
+ end
26
+
27
+ def self.finished?
28
+ @context.finished?(@game_id)
29
+ end
30
+
31
+ def self.winner?
32
+ @context.winner?(@game_id)
33
+ end
34
+ end
@@ -0,0 +1,159 @@
1
+ module WebGamePresenter
2
+ def self.for(options)
3
+ klass = case options.fetch :board
4
+ when TTT::ThreeByThree then ThreeByThree
5
+ when TTT::FourByFour then FourByFour
6
+ when TTT::ThreeByThreeByThree then ThreeByThreeByThree
7
+ else
8
+ raise ArgumentError, "Unknown board: #{board.inspect}"
9
+ end
10
+ klass.new board: options[:board], id: options[:id]
11
+ end
12
+
13
+ class Base
14
+
15
+ def initialize(options)
16
+ self.board = options.fetch :board
17
+ self.id = options.fetch :id
18
+ end
19
+
20
+ def board
21
+ board.board[]
22
+ end
23
+
24
+ def side_class(square)
25
+ return 'x_taken_square' if square == "x"
26
+ 'o_taken_square'
27
+ end
28
+
29
+ def next_player_move
30
+ if TTT::Context.instance.ai_move?(id)
31
+ "ai"
32
+ else
33
+ "human"
34
+ end
35
+ end
36
+
37
+ def generate_form(index)
38
+ %Q(<form id="#{index}" class="untaken_square" accept-charset="UTF-8" action="/ttt_games/#{id}/update_game" method="post"><input type="hidden" name="move" value="#{index}"></form>)
39
+ end
40
+
41
+ attr_accessor :board, :id
42
+ end
43
+
44
+ class ThreeByThree < Base
45
+ def show_board
46
+ html_string = "<table class='three_by_three'><tr>"
47
+ board[].each_with_index do |square, index|
48
+ html_string += "</tr><tr>" if index % 3 == 0 && index != 0
49
+ if square == " "
50
+ html_string += %Q(#{generate_form(index) unless board.finished?}<td value="#{index}" class="square #{next_player_move} #{square_class(index)}"></td>)
51
+ else
52
+ html_string += %Q(<td id="#{index}" name="move" class="square #{side_class(square)} #{square_class(index)}">#{square}</td>)
53
+ end
54
+ end
55
+ html_string += "</tr></table>"
56
+ end
57
+
58
+ def square_class(index)
59
+ html_class = case index
60
+ when 0 then 'top_left'
61
+ when 1 then 'top_middle'
62
+ when 2 then 'top_right'
63
+ when 3 then 'middle_left'
64
+ when 4 then 'middle'
65
+ when 5 then 'middle_right'
66
+ when 6 then 'bottom_left'
67
+ when 7 then 'bottom_middle'
68
+ when 8 then 'bottom_right'
69
+ end
70
+ end
71
+ end
72
+
73
+ class FourByFour < Base
74
+ def show_board
75
+ html_string = "<table class='four_by_four'><tr>"
76
+ board[].each_with_index do |square, index|
77
+ html_string += "</tr><tr>" if index % 4 == 0 && index != 0
78
+ if square == " "
79
+ html_string += %Q(#{generate_form(index) unless board.finished?}<td value="#{index}" class="square #{next_player_move} #{square_class(index)}"></td>)
80
+ else
81
+ html_string += %Q(<td id="#{index}" class="square #{side_class(square)} #{square_class(index)}">#{square}</td>)
82
+ end
83
+ end
84
+ html_string += "</tr></table>"
85
+ end
86
+
87
+ def square_class(index)
88
+ html_class = case index
89
+ when 0 then 'top_left'
90
+ when 1 then 'top_middle'
91
+ when 2 then 'top_middle'
92
+ when 3 then 'top_right'
93
+ when 4 then 'middle_left'
94
+ when 5 then 'middle'
95
+ when 6 then 'middle'
96
+ when 7 then 'middle_right'
97
+ when 8 then 'middle_left'
98
+ when 9 then 'middle'
99
+ when 10 then 'middle'
100
+ when 11 then 'middle_right'
101
+ when 12 then 'bottom_left'
102
+ when 13 then 'bottom_middle'
103
+ when 14 then 'bottom_middle'
104
+ when 15 then 'bottom_right'
105
+ end
106
+ end
107
+ end
108
+
109
+ class ThreeByThreeByThree < Base
110
+ def show_board
111
+ html_string = ""
112
+ board[].each_slice(9).with_index do |board_level, board_level_index|
113
+ html_string += "<table class='three_by_three_by_three'><tr>"
114
+ board_level.each_with_index do |square, index|
115
+ html_string += "</tr><tr>" if index % 3 == 0 && index != 0
116
+ if square == " "
117
+ html_string += %Q(#{generate_form(index + (board_level_index * 9)) unless board.finished?}<td value="#{index + (board_level_index * 9)}" class="square #{next_player_move} #{square_class(index)}"></td>)
118
+ else
119
+ html_string += %Q(<td id="#{index}" class="square #{side_class(square)} #{square_class(index)}">#{square}</td>)
120
+ end
121
+ end
122
+ html_string += "</tr></table>"
123
+ end
124
+ html_string
125
+ end
126
+
127
+ def square_class(index)
128
+ html_class = case index
129
+ when 0 then 'top_left'
130
+ when 1 then 'top_middle'
131
+ when 2 then 'top_right'
132
+ when 3 then 'middle_left'
133
+ when 4 then 'middle'
134
+ when 5 then 'middle_right'
135
+ when 6 then 'bottom_left'
136
+ when 7 then 'bottom_middle'
137
+ when 8 then 'bottom_right'
138
+ when 9 then 'top_left'
139
+ when 10 then 'top_middle'
140
+ when 11 then 'top_right'
141
+ when 12 then 'middle_left'
142
+ when 13 then 'middle'
143
+ when 14 then 'middle_right'
144
+ when 15 then 'bottom_left'
145
+ when 16 then 'bottom_middle'
146
+ when 17 then 'bottom_right'
147
+ when 18 then 'top_left'
148
+ when 19 then 'top_middle'
149
+ when 20 then 'top_right'
150
+ when 21 then 'middle_left'
151
+ when 22 then 'middle'
152
+ when 23 then 'middle_right'
153
+ when 24 then 'bottom_left'
154
+ when 25 then 'bottom_middle'
155
+ when 26 then 'bottom_right'
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,67 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "active_resource/railtie"
8
+ require "sprockets/railtie"
9
+ require "rails/test_unit/railtie"
10
+
11
+ if defined?(Bundler)
12
+ # If you precompile assets before deploying to production, use this line
13
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
14
+ # If you want your assets lazily compiled in production, use this line
15
+ # Bundler.require(:default, :assets, Rails.env)
16
+ end
17
+
18
+ module Railsttt
19
+ class Application < Rails::Application
20
+ # Settings in config/environments/* take precedence over those specified here.
21
+ # Application configuration should go into files in config/initializers
22
+ # -- all .rb files in that directory are automatically loaded.
23
+
24
+ # Custom directories with classes and modules you want to be autoloadable.
25
+
26
+ config.autoload_paths += %W(#{config.root}/../../../)
27
+
28
+
29
+ # Only load the plugins named here, in the order given (default is alphabetical).
30
+ # :all can be used as a placeholder for all plugins not explicitly named.
31
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
32
+
33
+ # Activate observers that should always be running.
34
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
35
+
36
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
37
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
38
+ # config.time_zone = 'Central Time (US & Canada)'
39
+
40
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
41
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
42
+ # config.i18n.default_locale = :de
43
+
44
+ # Configure the default encoding used in templates for Ruby 1.9.
45
+ config.encoding = "utf-8"
46
+
47
+ # Configure sensitive parameters which will be filtered from the log file.
48
+ config.filter_parameters += [:password]
49
+
50
+ # Use SQL instead of Active Record's schema dumper when creating the database.
51
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
52
+ # like if you have constraints or database-specific column types
53
+ # config.active_record.schema_format = :sql
54
+
55
+ # Enforce whitelist mode for mass assignment.
56
+ # This will create an empty whitelist of attributes available for mass-assignment for all models
57
+ # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
58
+ # parameters by using an attr_accessible or attr_protected declaration.
59
+ config.active_record.whitelist_attributes = true
60
+
61
+ # Enable the asset pipeline
62
+ config.assets.enabled = true
63
+
64
+ # Version of your assets, change this if you want to expire all your assets
65
+ config.assets.version = '1.0'
66
+ end
67
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Railsttt::Application.initialize!
@@ -0,0 +1,37 @@
1
+ Railsttt::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger
20
+ config.active_support.deprecation = :log
21
+
22
+ # Only use best-standards-support built into browsers
23
+ config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Raise exception on mass assignment protection for Active Record models
26
+ config.active_record.mass_assignment_sanitizer = :strict
27
+
28
+ # Log the query plan for queries taking more than this (works
29
+ # with SQLite, MySQL, and PostgreSQL)
30
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
31
+
32
+ # Do not compress assets
33
+ config.assets.compress = false
34
+
35
+ # Expands the lines which load the assets
36
+ config.assets.debug = true
37
+ end