ultimate_tic_tac_toe 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 +4 -4
- data/README.md +2 -1
- data/lib/ultimate_tic_tac_toe.rb +1 -2
- data/lib/ultimate_tic_tac_toe/global_vars.rb +11 -0
- data/lib/ultimate_tic_tac_toe/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/ultimate_tic_tac_toe/computer_spec.rb +0 -1
- metadata +4 -9
- data/lib/ultimate_tic_tac_toe/game.rb +0 -83
- data/lib/ultimate_tic_tac_toe/interface.rb +0 -75
- data/spec/ultimate_tic_tac_toe/game_spec.rb +0 -29
- data/spec/ultimate_tic_tac_toe/interface_spec.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01d7235b18b68a18582585e55ce9f5ebf6eae57e
|
4
|
+
data.tar.gz: 179446d7a2c5fb9ebd1234d7b522315d5b8ea981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b8fb7ecb3f51738586c7433b060846347522c98bd3c47e8928d25a0b038236870436968b26f90e5a452e632c3c7a5f6bc99f3d4887d7fa542e77b138da3ce61
|
7
|
+
data.tar.gz: 75f1d7476f2aa230ed2cdcf9690781fcb2a67ba3296b8521ad0051b94e03d90ab5593a4267eab32690e381b10c3c87c4b55fa07a6d28d9ad9060e889038cc6b8
|
data/README.md
CHANGED
data/lib/ultimate_tic_tac_toe.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ultimate_tic_tac_toe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rod Levy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,14 +53,11 @@ files:
|
|
53
53
|
- lib/ultimate_tic_tac_toe.rb
|
54
54
|
- lib/ultimate_tic_tac_toe/board.rb
|
55
55
|
- lib/ultimate_tic_tac_toe/computer.rb
|
56
|
-
- lib/ultimate_tic_tac_toe/
|
57
|
-
- lib/ultimate_tic_tac_toe/interface.rb
|
56
|
+
- lib/ultimate_tic_tac_toe/global_vars.rb
|
58
57
|
- lib/ultimate_tic_tac_toe/version.rb
|
59
58
|
- spec/spec_helper.rb
|
60
59
|
- spec/ultimate_tic_tac_toe/board_spec.rb
|
61
60
|
- spec/ultimate_tic_tac_toe/computer_spec.rb
|
62
|
-
- spec/ultimate_tic_tac_toe/game_spec.rb
|
63
|
-
- spec/ultimate_tic_tac_toe/interface_spec.rb
|
64
61
|
- ultimate_tic_tac_toe.gemspec
|
65
62
|
homepage: ''
|
66
63
|
licenses:
|
@@ -82,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
79
|
version: '0'
|
83
80
|
requirements: []
|
84
81
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.1.5
|
86
83
|
signing_key:
|
87
84
|
specification_version: 4
|
88
85
|
summary: Implements a game of tic-tac-toe where the computer always wins
|
@@ -90,5 +87,3 @@ test_files:
|
|
90
87
|
- spec/spec_helper.rb
|
91
88
|
- spec/ultimate_tic_tac_toe/board_spec.rb
|
92
89
|
- spec/ultimate_tic_tac_toe/computer_spec.rb
|
93
|
-
- spec/ultimate_tic_tac_toe/game_spec.rb
|
94
|
-
- spec/ultimate_tic_tac_toe/interface_spec.rb
|
@@ -1,83 +0,0 @@
|
|
1
|
-
class Game
|
2
|
-
|
3
|
-
HUMAN = "X"
|
4
|
-
COMPUTER = "O"
|
5
|
-
|
6
|
-
attr_accessor :position
|
7
|
-
|
8
|
-
def initialize(interface, computer)
|
9
|
-
@interface = interface
|
10
|
-
@computer = computer
|
11
|
-
end
|
12
|
-
|
13
|
-
def check_within_range(position, grid_length)
|
14
|
-
if position == "0"
|
15
|
-
true
|
16
|
-
elsif position.to_i < grid_length && position.to_i > 0
|
17
|
-
true
|
18
|
-
else
|
19
|
-
false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def check_space_unoccupied(position)
|
24
|
-
@board.unoccupied(position)
|
25
|
-
end
|
26
|
-
|
27
|
-
def validate_input(inputted_position, grid)
|
28
|
-
end_of_grid = grid.length
|
29
|
-
|
30
|
-
until check_within_range(inputted_position, end_of_grid)
|
31
|
-
@interface.reject(inputted_position)
|
32
|
-
@interface.prompt
|
33
|
-
inputted_position = @interface.user_input
|
34
|
-
end
|
35
|
-
|
36
|
-
until check_space_unoccupied(inputted_position.to_i)
|
37
|
-
@interface.denied
|
38
|
-
@interface.prompt
|
39
|
-
inputted_position = @interface.user_input
|
40
|
-
end
|
41
|
-
|
42
|
-
inputted_position.to_i
|
43
|
-
end
|
44
|
-
|
45
|
-
def game_over
|
46
|
-
(@board.tie? || @board.winner?(COMPUTER) || @board.winner?(HUMAN))
|
47
|
-
end
|
48
|
-
|
49
|
-
def check_board_after_computer_move
|
50
|
-
if @board.winner?("O") == true
|
51
|
-
@interface.computer_wins
|
52
|
-
@interface.pretty_print_board(@board.grid)
|
53
|
-
|
54
|
-
elsif @board.tie?
|
55
|
-
@interface.cats_game
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def play
|
60
|
-
@board = @board ||= Board.new(@interface.grid_size)
|
61
|
-
|
62
|
-
until game_over
|
63
|
-
|
64
|
-
@interface.pretty_print_board(@board.grid)
|
65
|
-
@interface.prompt
|
66
|
-
position = validate_input(@interface.user_input, @board.grid)
|
67
|
-
|
68
|
-
@board.store_position(position, HUMAN)
|
69
|
-
|
70
|
-
if @board.winner?("X") == true
|
71
|
-
@interface.player_wins
|
72
|
-
@interface.pretty_print_board(@board.grid)
|
73
|
-
else
|
74
|
-
@computer.computer_move(@board)
|
75
|
-
check_board_after_computer_move
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
|
@@ -1,75 +0,0 @@
|
|
1
|
-
class Interface
|
2
|
-
|
3
|
-
def opening_prompt
|
4
|
-
puts "What size board do you want to play (9, 16, 25)"
|
5
|
-
size = user_input
|
6
|
-
size
|
7
|
-
end
|
8
|
-
|
9
|
-
def grid_size
|
10
|
-
size = opening_prompt
|
11
|
-
|
12
|
-
if size == "9" || size == "16" || size == '25'
|
13
|
-
return size.to_i
|
14
|
-
else
|
15
|
-
puts "Please enter 9, 16 or 25"
|
16
|
-
grid_size
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def axis_length(size)
|
22
|
-
Math.sqrt(size).to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def insert_spaces(position, size, output, grid)
|
26
|
-
if position % axis_length(size) == (axis_length(size) - 1)
|
27
|
-
output << "\n" unless position == (size - 1)
|
28
|
-
else
|
29
|
-
if position < 10 || !grid[position].nil?
|
30
|
-
output << " "
|
31
|
-
else
|
32
|
-
output << " "
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
def pretty_print_board(grid)
|
39
|
-
output = ""
|
40
|
-
size = grid.length
|
41
|
-
size.times do |position|
|
42
|
-
output << (grid[position].nil? ? position.to_s : "#{grid[position]}")
|
43
|
-
insert_spaces(position, size, output, grid)
|
44
|
-
end
|
45
|
-
puts "\n Your Board \n\n\n" + output
|
46
|
-
end
|
47
|
-
|
48
|
-
def prompt
|
49
|
-
puts "Where do you want to place your X?"
|
50
|
-
end
|
51
|
-
|
52
|
-
def user_input
|
53
|
-
gets.chomp
|
54
|
-
end
|
55
|
-
|
56
|
-
def denied
|
57
|
-
puts "Already occupied, try again"
|
58
|
-
end
|
59
|
-
|
60
|
-
def cats_game
|
61
|
-
puts "CATS GAME!"
|
62
|
-
end
|
63
|
-
|
64
|
-
def computer_wins
|
65
|
-
puts "Computer wins! Again"
|
66
|
-
end
|
67
|
-
|
68
|
-
def player_wins
|
69
|
-
puts "Human wins! Impossible!"
|
70
|
-
end
|
71
|
-
|
72
|
-
def reject(position)
|
73
|
-
puts "#{position} isnt no good"
|
74
|
-
end
|
75
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'game'
|
2
|
-
require 'interface'
|
3
|
-
require 'board'
|
4
|
-
# puts $:
|
5
|
-
describe Game do
|
6
|
-
let!(:new_interface) {Interface.new}
|
7
|
-
let!(:new_board) {Board.new(9)}
|
8
|
-
let(:new_computer) {Computer.new}
|
9
|
-
let(:fun_game) {Game.new(new_interface, new_computer)}
|
10
|
-
|
11
|
-
it "can check that human's move is within the board" do
|
12
|
-
fun_game.check_within_range("7", new_board.grid.length).should eq true
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'determines when the game is over' do
|
16
|
-
fun_game.stub(:new).and_return(new_board)
|
17
|
-
new_board.stub(:tie?).and_return(true)
|
18
|
-
fun_game.game_over.should be(true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "informs the player of bad input" do
|
22
|
-
# new_interface.stub(:gets){"g\n"}
|
23
|
-
# fun_game.validate_input("\z", new_board.grid)
|
24
|
-
# fun_game.should_receive(:validate_input).with("d", new_board.grid)
|
25
|
-
fun_game.should_receive(:puts).with("f isnt no good")
|
26
|
-
fun_game.validate_input("f", new_board.grid)
|
27
|
-
# new_interface.prompt
|
28
|
-
end
|
29
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'game'
|
2
|
-
require 'interface'
|
3
|
-
require 'board'
|
4
|
-
|
5
|
-
|
6
|
-
describe Interface do
|
7
|
-
|
8
|
-
let!(:new_interface) {Interface.new}
|
9
|
-
let!(:new_board) {Board.new(9)}
|
10
|
-
let(:new_computer) {Computer.new}
|
11
|
-
let(:fun_game) {Game.new(new_interface, new_computer)}
|
12
|
-
|
13
|
-
# it "informs the player of bad input" do
|
14
|
-
# Interface.stub(:new).and_return(new_interface)
|
15
|
-
# new_interface.stub(:gets){"g\n"}
|
16
|
-
# fun_game.should_receive(:puts).with("f isnt no good").at_least(1).times
|
17
|
-
# new_interface.prompt
|
18
|
-
# end
|
19
|
-
|
20
|
-
# it 'prints a board that corresponds to the grid size' do
|
21
|
-
|
22
|
-
# end
|
23
|
-
it 'gets the initial input from human' do
|
24
|
-
new_interface.stub(:gets){"9\n"}
|
25
|
-
new_interface.opening_prompt.should == "9"
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'determines the grid length of the board' do
|
29
|
-
new_interface.stub(:gets){"9\n"}
|
30
|
-
new_interface.grid_size.should == 9
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'prints out a pretty board' do
|
34
|
-
new_interface.should_receive(:puts).with("\n Your Board \n\n\n0 1 2\n3 4 5\n6 7 8")
|
35
|
-
new_interface.pretty_print_board(new_board.grid)
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|