tic-tac-toe 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/tic-tac-toe.rb +2 -2
- data/lib/tic-tac-toe/board.rb +47 -0
- data/lib/tic-tac-toe/player.rb +9 -0
- data/tic-tac-toe.gemspec +59 -0
- metadata +8 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.0
|
data/lib/tic-tac-toe.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'tic-tac-toe/
|
2
|
-
require 'tic-tac-toe/
|
1
|
+
require 'tic-tac-toe/player.rb'
|
2
|
+
require 'tic-tac-toe/board.rb'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Board
|
2
|
+
# Board Positions:
|
3
|
+
# 0 | 1 | 2
|
4
|
+
# ---------
|
5
|
+
# 3 | 4 | 5
|
6
|
+
# ---------
|
7
|
+
# 6 | 7 | 8
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@board = Array.new()
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
str = "-----------\n"
|
15
|
+
(1..3).to_a.each do |i|
|
16
|
+
str << " #{@board[(i*3)-3] || (i*3)-2} | #{@board[(i*3)-2] || (i*3)-1} | #{@board[(i*3)-1] || i*3} \n"
|
17
|
+
str << "-----------\n"
|
18
|
+
end
|
19
|
+
str
|
20
|
+
end
|
21
|
+
|
22
|
+
def place_marker(marker, location)
|
23
|
+
if location < 9 && location >= 0
|
24
|
+
unless @board[location].nil?
|
25
|
+
raise 'Location already taken'
|
26
|
+
else
|
27
|
+
@board[location] = marker
|
28
|
+
end
|
29
|
+
else
|
30
|
+
raise 'Location does not exist'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_winner
|
35
|
+
return @board[0] if(@board[0] == @board[1] && @board[1] == @board[2]) # Top Row
|
36
|
+
return @board[3] if(@board[3] == @board[4] && @board[4] == @board[5]) # Middle Row
|
37
|
+
return @board[6] if(@board[6] == @board[7] && @board[7] == @board[8]) # Bottom Row
|
38
|
+
return @board[0] if(@board[0] == @board[4] && @board[4] == @board[8]) # Diagonal from Top Right
|
39
|
+
return @board[2] if(@board[2] == @board[4] && @board[4] == @board[6]) # Diagonal from Top Left
|
40
|
+
return nil # No one has won
|
41
|
+
end
|
42
|
+
|
43
|
+
def game_over?
|
44
|
+
(0..8).inject(true) { |val, i| val && @board[i] } || get_winner
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
data/tic-tac-toe.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tic-tac-toe}
|
8
|
+
s.version = "1.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mike Skalnik"]
|
12
|
+
s.date = %q{2010-11-04}
|
13
|
+
s.default_executable = %q{tic-tac-toe}
|
14
|
+
s.description = %q{A very simple tic-tac-toe game. Run `tic-tac-toe` to play.}
|
15
|
+
s.email = %q{mike.skalnik@gmail.com}
|
16
|
+
s.executables = ["tic-tac-toe"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/tic-tac-toe",
|
29
|
+
"lib/tic-tac-toe.rb",
|
30
|
+
"lib/tic-tac-toe/board.rb",
|
31
|
+
"lib/tic-tac-toe/player.rb",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_tic-tac-toe.rb",
|
34
|
+
"tic-tac-toe.gemspec"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/skalnik/tic-tac-toe}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.7}
|
40
|
+
s.summary = %q{A simple tic-tac-toe game!}
|
41
|
+
s.test_files = [
|
42
|
+
"test/helper.rb",
|
43
|
+
"test/test_tic-tac-toe.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tic-tac-toe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Skalnik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-04 00:00:00 -04:00
|
19
19
|
default_executable: tic-tac-toe
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,10 +48,13 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- bin/tic-tac-toe
|
51
52
|
- lib/tic-tac-toe.rb
|
53
|
+
- lib/tic-tac-toe/board.rb
|
54
|
+
- lib/tic-tac-toe/player.rb
|
52
55
|
- test/helper.rb
|
53
56
|
- test/test_tic-tac-toe.rb
|
54
|
-
-
|
57
|
+
- tic-tac-toe.gemspec
|
55
58
|
has_rdoc: true
|
56
59
|
homepage: http://github.com/skalnik/tic-tac-toe
|
57
60
|
licenses: []
|