tttazures 0.0.21 → 0.0.22

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 128b526e8dedd5732782ebfd4e6de6d0979fa58e
4
- data.tar.gz: c89b488722759f4b11bcaac2f79b5475dae710da
3
+ metadata.gz: ef94f65834ab731e70a97d0db473d72fa5b90b1f
4
+ data.tar.gz: 19c17db4cae887e16a24091c6b083bc85b79bf12
5
5
  SHA512:
6
- metadata.gz: 556e6a7c55e617f5249dbb37596f0e368ff18e4d667bb280c451aeadd057a19c032a0ae9de456ad48ed21248137a696cb1a0f9843c33839207d4538f635cebe1
7
- data.tar.gz: c0d66819d3c0726857cc0e2c23434081261815a89d2770792b8ced9929fd31513b8e8e718e2910209be40454aad0865f509fe9f41d72cda7f66f5acc4c2160d4
6
+ metadata.gz: c124f2556d21796c3065fce36a59abeb09507b2f217a722ae48562281d45374e36f9bd435217141a3b81ba96ecab4163ee23302cc2cc3e218089b62cc345a3b0
7
+ data.tar.gz: da26f3a9967bf5188121a0d9475ab545e5cc9e7e9ceebdec65084477b4761a1d24d000c77c94c50274d0668d1b7860df8333f85c5cb281dccfec707ddf3e5972
@@ -5,7 +5,7 @@ require_relative './two_dimensional_board'
5
5
  require_relative './three_dimensional_board'
6
6
  require_relative './board_printer_three_dim'
7
7
  require_relative './board_printer_two_dim'
8
- require_relative "./config"
8
+ require_relative "./factory"
9
9
 
10
10
  class GameController
11
11
 
@@ -13,7 +13,7 @@ class GameController
13
13
 
14
14
  def initialize
15
15
  @console = ConsoleUI.new
16
- @config = Configurer.new(@console)
16
+ @config = Factory.new(@console)
17
17
  end
18
18
 
19
19
  def run
@@ -1,5 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative '../lib/ttt/two_dimensional_board'
3
2
 
4
3
  describe TwoDimensionalBoard do
5
4
 
@@ -1,5 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative '../lib/ttt/three_dimensional_board'
3
2
 
4
3
  describe ThreeDimensionalBoard do
5
4
 
@@ -1,5 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative "../lib/ttt/two_dimensional_board"
3
2
 
4
3
  describe TwoDimensionalBoard do
5
4
 
@@ -1,5 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative "../lib/ttt/two_dimensional_board"
3
2
 
4
3
  describe TwoDimensionalBoard do
5
4
 
@@ -1,6 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative '../lib/ttt/two_dimensional_board'
3
- require_relative '../lib/ttt/computer_ai'
4
2
 
5
3
  describe ComputerAI do
6
4
 
@@ -1,6 +1,4 @@
1
1
  require_relative "spec_helper"
2
- require_relative '../lib/ttt/computer_ai'
3
- require_relative "../lib/ttt/two_dimensional_board"
4
2
 
5
3
  describe ComputerAI do
6
4
 
@@ -1,18 +1,13 @@
1
1
  require_relative "spec_helper"
2
- require_relative "../lib/ttt/human_player"
3
- require_relative "../lib/ttt/console_ui"
4
- require_relative "../lib/ttt/two_dimensional_board"
5
2
 
6
3
  describe HumanPlayer do
7
4
 
8
- let(:console){c = ConsoleUI.new}
9
- let(:human_player){hp = HumanPlayer.new(:x,console)}
5
+ let(:human_player){hp = HumanPlayer.new(:x)}
10
6
  let(:board){board = TwoDimensionalBoard.new(3)}
11
7
 
12
8
  describe '#make_move' do
13
9
 
14
10
  it "makes valid move" do
15
- console.stub(:query_user_for_choice){1}
16
11
  board.stub(:record_choice){true}
17
12
  human_player.make_move(board)
18
13
  end
data/spec/long_tests.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require_relative '../lib/ttt/computer_ai'
2
- require_relative '../lib/ttt/two_dimensional_board'
3
- require_relative '../lib/ttt/three_dimensional_board'
4
2
 
5
3
  describe ComputerAI do
6
4
  let(:ai) {nai = ComputerAI.new(:o, 100);}
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,11 @@
1
+ require_relative "../lib/two_dimensional_board"
2
+ require_relative "../lib/three_dimensional_board"
3
+ require_relative "../lib/board"
4
+ require_relative "../lib/human_player"
5
+ require_relative "../lib/computer_ai"
6
+ require_relative "../lib/factory"
7
+
8
+
1
9
  require 'simplecov'
2
10
  SimpleCov.start do
3
11
  add_filter '/spec/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tttazures
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Zures
@@ -17,11 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/board.rb
20
- - lib/board_printer_three_dim.rb
21
- - lib/board_printer_two_dim.rb
22
20
  - lib/computer_ai.rb
23
- - lib/console_ui.rb
24
- - lib/driver.rb
25
21
  - lib/factory.rb
26
22
  - lib/game_controller.rb
27
23
  - lib/human_player.rb
@@ -33,8 +29,6 @@ files:
33
29
  - spec/board_5x5_spec.rb
34
30
  - spec/computer_ai_3x3_board_spec.rb
35
31
  - spec/computer_ai_spec.rb
36
- - spec/configurer_spec.rb
37
- - spec/console_ui_spec.rb
38
32
  - spec/coverage/assets/0.7.1/application.css
39
33
  - spec/coverage/assets/0.7.1/application.js
40
34
  - spec/coverage/assets/0.7.1/fancybox/blank.gif
@@ -76,7 +70,6 @@ files:
76
70
  - spec/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png
77
71
  - spec/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png
78
72
  - spec/coverage/index.html
79
- - spec/game_controller_spec.rb
80
73
  - spec/human_player_spec.rb
81
74
  - spec/long_tests.rb
82
75
  - spec/spec_helper.rb
@@ -111,8 +104,6 @@ test_files:
111
104
  - spec/board_5x5_spec.rb
112
105
  - spec/computer_ai_3x3_board_spec.rb
113
106
  - spec/computer_ai_spec.rb
114
- - spec/configurer_spec.rb
115
- - spec/console_ui_spec.rb
116
107
  - spec/coverage/assets/0.7.1/application.css
117
108
  - spec/coverage/assets/0.7.1/application.js
118
109
  - spec/coverage/assets/0.7.1/fancybox/blank.gif
@@ -154,7 +145,6 @@ test_files:
154
145
  - spec/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png
155
146
  - spec/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png
156
147
  - spec/coverage/index.html
157
- - spec/game_controller_spec.rb
158
148
  - spec/human_player_spec.rb
159
149
  - spec/long_tests.rb
160
150
  - spec/spec_helper.rb
@@ -1,40 +0,0 @@
1
- class BoardPrinterThreeDim
2
-
3
- def initialize output= STDOUT
4
- @output = output
5
- end
6
-
7
- def print print_results
8
- board = print_results[0]
9
- row_length = print_results[1].to_i
10
-
11
- start_index = 0
12
- row_length.times do
13
- index = start_index
14
- row_length.times do
15
- row_length.times do
16
- symbol = get_element_symbol board, index
17
- if symbol.to_s.size == 1
18
- @output.print " #{symbol} "
19
- else
20
- @output.print " #{symbol} "
21
- end
22
- index += 1
23
- end
24
- @output.print " "
25
- index += 6
26
- end
27
- @output.puts
28
- start_index += row_length
29
- end
30
- @output.puts
31
- end
32
-
33
- def get_element_symbol board_array, index
34
- case board_array[index]
35
- when :x then symbol = "X"
36
- when :o then symbol = "O"
37
- else symbol = index end
38
- symbol
39
- end
40
- end
@@ -1,32 +0,0 @@
1
- class BoardPrinterTwoDim
2
-
3
- def initialize output= STDOUT
4
- @output = output
5
- end
6
-
7
- def print print_results
8
- board = print_results[0]
9
- row_length = print_results[1]
10
-
11
- board.to_enum.with_index.each do |value, index|
12
- symbol = get_element_symbol board, index
13
-
14
- if symbol.to_s.size == 1
15
- @output.print " #{symbol}"
16
- else
17
- @output.print " #{symbol}"
18
- end
19
-
20
- @output.puts "" if (index+1) % row_length == 0 && (index+1) != (row_length * row_length)
21
- end
22
- @output.puts "\n \n"
23
- end
24
-
25
- def get_element_symbol board_array, index
26
- case board_array[index]
27
- when :x then symbol = "X"
28
- when :o then symbol = "O"
29
- else symbol = index end
30
- symbol
31
- end
32
- end
data/lib/console_ui.rb DELETED
@@ -1,107 +0,0 @@
1
- class ConsoleUI
2
-
3
- def initialize output= STDOUT
4
- @output = output
5
- end
6
-
7
- def query_user_for_choice user
8
- @output.puts "User #{user}: Choose!"
9
- receive_user_choice.to_i
10
- end
11
-
12
- def query_user_for_new_game
13
- print_new_game_prompt
14
- choice = receive_user_choice
15
- return choice == "y" ? true : false
16
- end
17
-
18
- def receive_user_choice
19
- begin
20
- choice = gets.chomp.downcase
21
- rescue Interrupt => e
22
- @output.puts e
23
- end
24
- say_goodbye if choice == 'q'
25
- return choice
26
- end
27
-
28
- def print_player_move move, player
29
- puts "Player #{player.player} chose #{move}"
30
- end
31
-
32
- def respond_to_choice choice_accepted, choice
33
- if choice_accepted then @output.puts "You Chose: #{choice}"
34
- else print_user_input_error end
35
- end
36
-
37
- def query_user_for_board_type
38
- print_board_options
39
- receive_user_choice.to_i
40
- end
41
-
42
- def query_user_for_ai_difficulty symbol
43
- print_ai_difficulty_options(symbol)
44
- receive_user_choice.to_i
45
- end
46
-
47
- def query_user_for_game_type
48
- valid_choice = false
49
- while valid_choice == false
50
- print_game_options
51
- choice = receive_user_choice.to_i
52
- if choice >= 0 && choice < 4 then valid_choice = true
53
- else print_user_input_error end
54
- end
55
- choice
56
- end
57
-
58
- def print_board_options
59
- @output.puts "What type of board size would you like to use?"
60
- @output.puts " Choose 0 for 3x3 board"
61
- @output.puts " Choose 1 for 4x4 board"
62
- @output.puts " Choose 2 for 5x5 board"
63
- @output.puts " Choose 3 for 3x3x3 board"
64
- end
65
-
66
- def print_ai_difficulty_options player
67
- @output.puts "How difficult will Player #{player} AI be?"
68
- @output.puts " Choose 0: AI is easy to beat"
69
- @output.puts " Choose 1: AI is medium difficulty"
70
- @output.puts " Choose 2: AI is unbeatable (except for 3x3x3)"
71
- end
72
-
73
- def print_game_options
74
- @output.puts "Choose Game Type"
75
- @output.puts " Choose 0 for Human v. Human"
76
- @output.puts " Choose 1 for Human v. Computer, Human goes first"
77
- @output.puts " Choose 2 for Human v. Computer, Computer goes first"
78
- @output.puts " Choose 3 for Computer v. Computer"
79
- end
80
-
81
- def present_game_result game_result
82
- if game_result == :tie then @output.puts "Game Over: Tie"
83
- else @output.puts "Game Over. Player #{game_result} Wins" end
84
- end
85
-
86
- def greet_user
87
- @output.puts "---Welcome to Tic Tac Toe---"
88
- @output.puts "Press 'q' at any time to exit game"
89
- end
90
-
91
- def say_goodbye
92
- @output.puts "Thanks for playing!"
93
- exit
94
- end
95
-
96
- def print_user_input_error
97
- @output.puts "Whoops! That choice wasn't valid, try again:"
98
- end
99
-
100
- def print_new_game_prompt
101
- @output.puts "Would you like to start another game? Press 'Y' if yes. Press Any Other Key to Exit"
102
- end
103
-
104
- def print printString
105
- @output.puts printString;
106
- end
107
- end
data/lib/driver.rb DELETED
@@ -1,3 +0,0 @@
1
- require './game_controller'
2
- controller = GameController.new
3
- controller.run
@@ -1,140 +0,0 @@
1
- require_relative "spec_helper"
2
- require_relative "../lib/ttt/config"
3
- require_relative "../lib/ttt/human_player"
4
- require_relative "../lib/ttt/computer_ai"
5
- require_relative "../lib/ttt/console_ui"
6
- require_relative "../lib/ttt/board_printer_two_dim"
7
- require_relative "../lib/ttt/board_printer_three_dim"
8
-
9
- describe Configurer do
10
-
11
-
12
- let(:console){con = ConsoleUI.new}
13
- let(:config){c = Configurer.new console}
14
-
15
- describe '#get_players' do
16
-
17
- it "return two human objects if 0 chosen" do
18
- console.stub(:query_user_for_game_type){0}
19
- result = config.get_players
20
- result[:player1].should be_an_instance_of HumanPlayer
21
- result[:player2].should be_an_instance_of HumanPlayer
22
- end
23
-
24
- it "returns human as p1, computer as p2, if 1 is chosen" do
25
- console.stub(:query_user_for_game_type){1}
26
- config.stub(:get_ai_choice_from_user){2}
27
- result = config.get_players
28
- result[:player1].should be_an_instance_of HumanPlayer
29
- result[:player2].should be_an_instance_of ComputerAI
30
- end
31
-
32
- it "returns computer as p1, human as p2, if 2 is chosen" do
33
- console.stub(:query_user_for_game_type){2}
34
- config.stub(:get_ai_choice_from_user){2}
35
- result = config.get_players
36
- result[:player1].should be_an_instance_of ComputerAI
37
- result[:player2].should be_an_instance_of HumanPlayer
38
- end
39
-
40
- it "returns two computer players if 3 is chosen" do
41
- console.stub(:query_user_for_game_type){3}
42
- config.stub(:get_ai_choice_from_user){2}
43
- config.stub(:get_ai_choice_from_user){2}
44
- result = config.get_players
45
- result[:player1].should be_an_instance_of ComputerAI
46
- result[:player2].should be_an_instance_of ComputerAI
47
- end
48
-
49
- end
50
-
51
- describe '#set_ai_difficulty' do
52
-
53
- it "returns easy ai if 0 is chosen" do
54
- config.stub(:get_ai_choice_from_user){0}
55
- result = config.set_ai_difficulty(:x)
56
- result.threshold.should == 10
57
- end
58
-
59
- it "returns medium ai if 1 is chosen" do
60
- config.stub(:get_ai_choice_from_user){1}
61
- result = config.set_ai_difficulty(:x)
62
- result.threshold.should == 50
63
- end
64
-
65
- it "returns unbeatable ai if 2 is chosen" do
66
- config.stub(:get_ai_choice_from_user){2}
67
- result = config.set_ai_difficulty(:x)
68
- result.threshold.should == 100
69
- end
70
- end
71
-
72
- describe '#get_board' do
73
-
74
- it "gets a 3x3 board when input is 0" do
75
- config.stub(:get_board_choice){0}
76
- result = config.get_board
77
- result.should be_an_instance_of TwoDimensionalBoard
78
- result.row_length.should == 3
79
- end
80
-
81
- it "gets a 4x4 board when input is 1" do
82
- config.stub(:get_board_choice){1}
83
- result = config.get_board
84
- result.should be_an_instance_of TwoDimensionalBoard
85
- result.row_length.should == 4
86
- end
87
-
88
- it "gets a 5x5 board when input is 2" do
89
- config.stub(:get_board_choice){2}
90
- result = config.get_board
91
- result.should be_an_instance_of TwoDimensionalBoard
92
- result.row_length.should == 5
93
- end
94
-
95
- it "gets a 3x3x3 board when input is 3" do
96
- config.stub(:get_board_choice){3}
97
- result = config.get_board
98
- result.should be_an_instance_of ThreeDimensionalBoard
99
- result.row_length.should == 3
100
- end
101
- end
102
-
103
- describe '#get_board_choice' do
104
-
105
- it "returns valid board choice" do
106
- console.stub(:query_user_for_board_type){1}
107
- config.get_board_choice.should == 1
108
-
109
- console.stub(:query_user_for_board_type){5}
110
- console.stub(:query_user_for_board_type){2}
111
- config.get_board_choice.should == 2
112
- end
113
- end
114
-
115
- describe '#get_ai_choice_from_user' do
116
- it "returns valid ai choice" do
117
- console.stub(:query_user_for_ai_difficulty){1}
118
- config.get_ai_choice_from_user(:x).should == 1
119
-
120
- console.stub(:query_user_for_ai_difficulty){5}
121
- console.stub(:query_user_for_ai_difficulty){2}
122
- config.get_ai_choice_from_user(:x).should == 2
123
- end
124
- end
125
-
126
- describe '#get_board_printer' do
127
- it "returns 2d board printer for 2d board" do
128
- board = TwoDimensionalBoard.new(3)
129
- result = config.get_board_printer(board)
130
- result.should be_an_instance_of BoardPrinterTwoDim
131
- end
132
-
133
- it "returns 3d board printer for 3d board" do
134
- board = ThreeDimensionalBoard.new(3)
135
- result = config.get_board_printer(board)
136
- result.should be_an_instance_of BoardPrinterThreeDim
137
- end
138
- end
139
-
140
- end
@@ -1,115 +0,0 @@
1
- require_relative "spec_helper"
2
- require './lib/ttt/console_ui'
3
-
4
- describe ConsoleUI do
5
-
6
- let(:io) {io = StringIO.new}
7
- let(:console) {c = ConsoleUI.new io}
8
-
9
- it "creates new ui console" do
10
- console.should be_an_instance_of ConsoleUI
11
- end
12
-
13
- describe '#receive_user_choice' do
14
-
15
- it "receives user choice and sanitizes input" do
16
- console.stub(:gets){"1"}
17
- console.receive_user_choice.should == "1"
18
-
19
- console.stub(:gets){"Y"}
20
- console.receive_user_choice.should == "y"
21
- end
22
- end
23
-
24
- describe '#query_user_for_choice' do
25
- player1 = 1
26
- player2 = -1
27
-
28
- it "receives input from user once at a time" do
29
- player = 1
30
- console.stub(:receive_user_choice) {1}
31
- console.query_user_for_choice(player).should eql(1)
32
- end
33
-
34
- it "queries for user input - player1" do
35
- player = 1
36
- console.stub(:receive_user_choice) {1}
37
- console.query_user_for_choice(player)
38
- io.string.should match "User 1: Choose"
39
- end
40
-
41
- it "queries for user input - player2" do
42
-
43
- player = -1
44
- console.stub(:receive_user_choice) {1}
45
- console.query_user_for_choice(player)
46
- io.string.should match "User -1: Choose"
47
- end
48
- end
49
-
50
- describe '#query_user_for_choice' do
51
-
52
- it "asks user for new game" do
53
- console.stub(:receive_user_choice) {1}
54
- console.query_user_for_new_game
55
- io.string.should match "Would you like to start another game?"
56
- end
57
-
58
- it "returns true if user inputs 'y'" do
59
- console.stub(:receive_user_choice) {"y"}
60
- console.query_user_for_new_game.should == true
61
- end
62
- end
63
-
64
- describe '#respond_to_choice' do
65
-
66
- it "tells user that invalid choice is invalid" do
67
- choice = 1
68
- console.respond_to_choice(false, choice)
69
- io.string.should match "Whoops! That choice wasn't valid"
70
-
71
- end
72
-
73
- it "tells user if choice was valid (choice = 1)" do
74
- choice = 1
75
- console.respond_to_choice(true, choice)
76
- io.string.should match "You Chose: 1"
77
- end
78
-
79
- it "tells user if choice was valid (choice = 9)" do
80
- choice = 9
81
- console.respond_to_choice(true, choice)
82
- io.string.should match "You Chose: 9"
83
- end
84
- end
85
-
86
- describe '#present_game_result' do
87
-
88
- it "presents tie text to user if result is tie" do
89
- console.present_game_result(:tie)
90
- io.string.should match "Game Over: Tie"
91
- end
92
-
93
- it "sends player 1 win to console" do
94
- player = 1
95
- console.present_game_result(:x)
96
- io.string.should match "Player x Wins"
97
- end
98
-
99
- it "sends player -1 win to console" do
100
- player = -1
101
- console.present_game_result(:o)
102
- io.string.should match "Player o Wins"
103
- end
104
- end
105
-
106
- describe '#query_user_for_ai_difficulty' do
107
-
108
- it "should print difficulty options" do
109
- console.print_ai_difficulty_options(:x)
110
- io.string.should match "Choose 0: AI is easy"
111
- io.string.should match "Choose 1: AI is medium"
112
- io.string.should match "Choose 2: AI is unbeatable"
113
- end
114
- end
115
- end
@@ -1,50 +0,0 @@
1
- require_relative "spec_helper"
2
- require_relative '../lib/ttt/game_controller'
3
- require_relative '../lib/ttt/console_ui'
4
- require_relative "../lib/ttt/two_dimensional_board"
5
-
6
- describe GameController do
7
-
8
- let(:io) {io = StringIO.new}
9
- let(:controller){
10
- controller = GameController.new
11
- controller.instance_variable_set(:@board, TwoDimensionalBoard.new(3))
12
- console1 = ConsoleUI.new(io)
13
- controller.instance_variable_set(:@console, console1)
14
- console = controller.console
15
- final_controller = controller
16
- }
17
- let(:console){c = controller.console}
18
- let(:ai){ai = controller.ai}
19
-
20
- =begin
21
- describe '#execute_game' do
22
- it "breaks game loop and presents winner" do
23
- console.stub(:greet_user){}
24
- controller.stub(:set_board){}
25
- controller.stub(:set_ai_difficulty){}
26
- controller.stub(:display_game_status){}
27
- board_manager.stub(:check_board_status){1}
28
- controller.stub(:present_game_result){}
29
- controller.stub(:play_again?){false}
30
- controller.execute_game.should == nil
31
- end
32
- end
33
- =end
34
-
35
-
36
- describe '#play_again?' do
37
-
38
- it "returns false if no new game wanted" do
39
- console.stub(:query_user_for_new_game){true}
40
- console.stub(:receive_user_choice){"y"}
41
- controller.play_again?.should == true
42
-
43
- console.stub(:query_user_for_new_game){false}
44
- console.stub(:say_goodbye){}
45
- console.stub(:receive_user_choice){"n"}
46
- controller.play_again?.should == false
47
- end
48
- end
49
-
50
- end