tic_tac_toes 0.0.1 → 0.0.2
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/.gitignore +0 -1
- data/Gemfile.lock +33 -0
- data/README.md +7 -2
- data/Rakefile +3 -24
- data/bin/destroy_ttt_databases +10 -0
- data/bin/set_up_ttt_databases +10 -0
- data/lib/tic_tac_toes/tasks/destroy_databases.rake +9 -0
- data/lib/tic_tac_toes/tasks/set_up_databases.rake +41 -0
- data/lib/tic_tac_toes/version.rb +1 -1
- data/spec/database/pg_wrapper_spec.rb +3 -3
- data/spec/tic_tac_toes/board_spec.rb +3 -3
- data/tic_tac_toes.gemspec +2 -2
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eba6ff9bd4e9e32b11a8d56fec6a495e8c3b6f4c
|
4
|
+
data.tar.gz: 3b3a75a1cce99eaeb7a7f98c816f5b48cc348244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28447b247bb23d735ccf63dbccacb1a65a5179e382a54fc50ed25ff005d6354552db44b548af93fd26253a2a0055910bcec8798151265a05a177f294483a04f7
|
7
|
+
data.tar.gz: 9c276bb9a57b910eb7e8a6fac87f5f1036551923c7e682ec19532010fa5cb1fbc6eb68a7001d21b97a3390e7779be9a5f6a519c4967461d86e0b66cb49c77217
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tic_tac_toes (0.0.1)
|
5
|
+
pg
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
pg (0.17.1)
|
12
|
+
rake (10.3.2)
|
13
|
+
rspec (3.0.0)
|
14
|
+
rspec-core (~> 3.0.0)
|
15
|
+
rspec-expectations (~> 3.0.0)
|
16
|
+
rspec-mocks (~> 3.0.0)
|
17
|
+
rspec-core (3.0.1)
|
18
|
+
rspec-support (~> 3.0.0)
|
19
|
+
rspec-expectations (3.0.1)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.0.0)
|
22
|
+
rspec-mocks (3.0.1)
|
23
|
+
rspec-support (~> 3.0.0)
|
24
|
+
rspec-support (3.0.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler
|
31
|
+
rake
|
32
|
+
rspec
|
33
|
+
tic_tac_toes!
|
data/README.md
CHANGED
@@ -4,5 +4,10 @@ The game Tic-tac-toe, featuring an unbeatable AI.
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
1. Install
|
8
|
-
2.
|
7
|
+
1. Install [PostgreSQL][]
|
8
|
+
2. Install the gem: `gem install tic_tac_toes`
|
9
|
+
3. Create the databases: `set_up_ttt_databases`
|
10
|
+
* To drop the databases: `destroy_ttt_databases`
|
11
|
+
4. Launch the game: `tic_tac_toes`
|
12
|
+
|
13
|
+
[PostgreSQL]: http://www.postgresql.org
|
data/Rakefile
CHANGED
@@ -1,25 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'pg'
|
1
|
+
require 'bundler/gem_tasks'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
connection.exec("CREATE TABLE games (
|
7
|
-
id serial primary key,
|
8
|
-
board_size integer,
|
9
|
-
winner varchar)")
|
10
|
-
connection.exec("CREATE TABLE moves (
|
11
|
-
game integer REFERENCES games (id),
|
12
|
-
number integer,
|
13
|
-
token varchar,
|
14
|
-
space integer)")
|
15
|
-
end
|
16
|
-
|
17
|
-
task :destroy_tables do
|
18
|
-
connection = establish_connection
|
19
|
-
connection.exec("DROP TABLE moves")
|
20
|
-
connection.exec("DROP TABLE games")
|
21
|
-
end
|
22
|
-
|
23
|
-
def establish_connection
|
24
|
-
PG.connect(dbname: "tic_tac_toes")
|
25
|
-
end
|
3
|
+
load './lib/tic_tac_toes/tasks/set_up_databases.rake'
|
4
|
+
load './lib/tic_tac_toes/tasks/destroy_databases.rake'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pg'
|
2
|
+
|
3
|
+
PRODUCTION_DATABASE = 'tic_tac_toes'
|
4
|
+
TEST_DATABASE = 'tic_tac_toes_test'
|
5
|
+
|
6
|
+
desc 'Set up tic_tac_toes databases'
|
7
|
+
task :set_up_databases do
|
8
|
+
create_databases_if_not_exist
|
9
|
+
create_production_tables_if_not_exist
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_databases_if_not_exist
|
13
|
+
connection = PG.connect(dbname: "postgres")
|
14
|
+
|
15
|
+
connection.exec("CREATE DATABASE #{PRODUCTION_DATABASE}") unless already_exists?(PRODUCTION_DATABASE, connection)
|
16
|
+
connection.exec("CREATE DATABASE #{TEST_DATABASE}") unless already_exists?(TEST_DATABASE, connection)
|
17
|
+
end
|
18
|
+
|
19
|
+
def already_exists?(database, connection)
|
20
|
+
existing_ttt_database_result = connection.exec("SELECT COUNT(*) FROM pg_database WHERE datname = '#{database}'")
|
21
|
+
number_of_existing_ttt_databases = existing_ttt_database_result.getvalue(0,0).to_i
|
22
|
+
|
23
|
+
number_of_existing_ttt_databases == 1 ? true : false
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_production_tables_if_not_exist
|
27
|
+
connection = PG.connect(dbname: "#{PRODUCTION_DATABASE}")
|
28
|
+
|
29
|
+
# Suppress "already exist" notices
|
30
|
+
connection.exec("set client_min_messages=warning")
|
31
|
+
|
32
|
+
connection.exec("CREATE TABLE IF NOT EXISTS games (
|
33
|
+
id serial primary key,
|
34
|
+
board_size integer,
|
35
|
+
winner varchar)")
|
36
|
+
connection.exec("CREATE TABLE IF NOT EXISTS moves (
|
37
|
+
game integer REFERENCES games (id),
|
38
|
+
number integer,
|
39
|
+
token varchar,
|
40
|
+
space integer)")
|
41
|
+
end
|
data/lib/tic_tac_toes/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'database/pg_wrapper'
|
2
2
|
require 'pg'
|
3
|
-
require 'tic_tac_toes/history'
|
4
3
|
require 'tic_tac_toes/spec_helper'
|
5
4
|
|
6
5
|
describe Database::PGWrapper do
|
7
|
-
database = "
|
6
|
+
database = "tic_tac_toes_test"
|
7
|
+
|
8
8
|
let(:pg_wrapper) { Database::PGWrapper.new(database) }
|
9
9
|
let(:history1) { double("history 1",
|
10
10
|
:board_size => 9,
|
@@ -44,7 +44,7 @@ describe Database::PGWrapper do
|
|
44
44
|
pg_wrapper.record_game_history(history1)
|
45
45
|
pg_wrapper.record_game_history(history2)
|
46
46
|
histories_from_database = pg_wrapper.read_game_histories
|
47
|
-
expect(histories_from_database).to
|
47
|
+
expect(histories_from_database.size).to eq(2)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -48,7 +48,7 @@ describe TicTacToes::Board do
|
|
48
48
|
board = generate_board(structure)
|
49
49
|
first_row = [:X, :X, :X, :X]
|
50
50
|
|
51
|
-
expect(board.rows).to
|
51
|
+
expect(board.rows.size).to eq(4)
|
52
52
|
expect(board.rows.first).to eql(first_row)
|
53
53
|
end
|
54
54
|
end
|
@@ -63,7 +63,7 @@ describe TicTacToes::Board do
|
|
63
63
|
board = generate_board(structure)
|
64
64
|
first_column = [:X, :X, :X, :X]
|
65
65
|
|
66
|
-
expect(board.columns).to
|
66
|
+
expect(board.columns.size).to eq(4)
|
67
67
|
expect(board.columns.first).to eql(first_column)
|
68
68
|
end
|
69
69
|
end
|
@@ -79,7 +79,7 @@ describe TicTacToes::Board do
|
|
79
79
|
back_diagonal = [:X, :X, :X, :X]
|
80
80
|
front_diagonal = [:O, :O, :O, :O]
|
81
81
|
|
82
|
-
expect(board.diagonals).to
|
82
|
+
expect(board.diagonals.size).to eq(2)
|
83
83
|
expect(board.diagonals.first).to eql(back_diagonal)
|
84
84
|
expect(board.diagonals.last).to eql(front_diagonal)
|
85
85
|
end
|
data/tic_tac_toes.gemspec
CHANGED
@@ -13,11 +13,11 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
|
-
spec.executables = ["tic_tac_toes"]
|
16
|
+
spec.executables = ["tic_tac_toes", "set_up_ttt_databases", "destroy_ttt_databases"]
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ["lib"]
|
19
19
|
|
20
|
-
spec.add_development_dependency "bundler"
|
20
|
+
spec.add_development_dependency "bundler"
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "rspec"
|
23
23
|
spec.add_dependency "pg"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tic_tac_toes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Spatafora
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,14 +71,19 @@ email:
|
|
71
71
|
- benjamin.spatafora@gmail.com
|
72
72
|
executables:
|
73
73
|
- tic_tac_toes
|
74
|
+
- set_up_ttt_databases
|
75
|
+
- destroy_ttt_databases
|
74
76
|
extensions: []
|
75
77
|
extra_rdoc_files: []
|
76
78
|
files:
|
77
79
|
- ".gitignore"
|
78
80
|
- Gemfile
|
81
|
+
- Gemfile.lock
|
79
82
|
- LICENSE.txt
|
80
83
|
- README.md
|
81
84
|
- Rakefile
|
85
|
+
- bin/destroy_ttt_databases
|
86
|
+
- bin/set_up_ttt_databases
|
82
87
|
- bin/tic_tac_toes
|
83
88
|
- lib/command_line/io.rb
|
84
89
|
- lib/command_line/menu.rb
|
@@ -94,6 +99,8 @@ files:
|
|
94
99
|
- lib/tic_tac_toes/player_factory.rb
|
95
100
|
- lib/tic_tac_toes/rules.rb
|
96
101
|
- lib/tic_tac_toes/strings.rb
|
102
|
+
- lib/tic_tac_toes/tasks/destroy_databases.rake
|
103
|
+
- lib/tic_tac_toes/tasks/set_up_databases.rake
|
97
104
|
- lib/tic_tac_toes/version.rb
|
98
105
|
- spec/command_line/menu_spec.rb
|
99
106
|
- spec/command_line/runner_spec.rb
|