tic_tac_toe 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +20 -12
- data/bin/tic_tac_toe +24 -48
- data/lib/tic_tac_toe/version.rb +1 -1
- data/tic_tac_toe.gemspec +1 -0
- metadata +37 -43
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 669bcc6a62e3529623b90a6d63ea18b5a30bc2c8
|
4
|
+
data.tar.gz: 97390978eca78ae37f26674b559c91f153d875bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad42b25232cf62cd0c62238c30cbb5921163c97a0416fd170d47c546abab4e957c66bdb712b1c4466eebb765ec996aabf6fe8a3229e72f8e25c7576f0c634d74
|
7
|
+
data.tar.gz: 0944cf1cac8d17226c9467a4dc7669be36ea86e851121447b0ba8e3859cff4aa08b2ec983f0dde7f3be3af72432f97d4e52d367dc8019ceb979e46a4517dd312
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,17 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tic_tac_toe (0.2.3)
|
5
|
+
dispel
|
6
|
+
|
1
7
|
GEM
|
2
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
bump (0.
|
5
|
-
diff-lcs (1.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
rspec-
|
10
|
-
rspec-
|
11
|
-
|
12
|
-
rspec-
|
13
|
-
|
14
|
-
|
10
|
+
bump (0.5.0)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
dispel (0.0.1)
|
13
|
+
rake (10.1.0)
|
14
|
+
rspec (2.14.1)
|
15
|
+
rspec-core (~> 2.14.0)
|
16
|
+
rspec-expectations (~> 2.14.0)
|
17
|
+
rspec-mocks (~> 2.14.0)
|
18
|
+
rspec-core (2.14.7)
|
19
|
+
rspec-expectations (2.14.4)
|
20
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
21
|
+
rspec-mocks (2.14.4)
|
15
22
|
|
16
23
|
PLATFORMS
|
17
24
|
ruby
|
@@ -20,3 +27,4 @@ DEPENDENCIES
|
|
20
27
|
bump
|
21
28
|
rake
|
22
29
|
rspec (~> 2)
|
30
|
+
tic_tac_toe!
|
data/bin/tic_tac_toe
CHANGED
@@ -1,62 +1,38 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.expand_path('../../lib/tic_tac_toe', __FILE__)
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
3
|
|
4
|
+
require 'dispel'
|
5
|
+
require 'tic_tac_toe'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def init_screen
|
10
|
-
Curses.noecho # do not show typed keys
|
11
|
-
Curses.init_screen
|
12
|
-
Curses.stdscr.keypad(true) # enable arrow keys
|
13
|
-
begin
|
14
|
-
yield
|
15
|
-
ensure
|
16
|
-
Curses.close_screen
|
17
|
-
end
|
7
|
+
def draw(ttt)
|
8
|
+
[ttt.board, status_line(ttt), "q=Quit r=Reset a=AI-move"].join("\n")
|
18
9
|
end
|
19
10
|
|
20
|
-
def
|
21
|
-
Curses.setpos(line, column)
|
22
|
-
Curses.addstr(text);
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def display(ttt)
|
27
|
-
write 0,0,ttt.board
|
11
|
+
def status_line(ttt)
|
28
12
|
if winner = ttt.winner
|
29
|
-
|
13
|
+
"Player #{winner} has won!!!!"
|
30
14
|
elsif ttt.draw?
|
31
|
-
|
15
|
+
"It is a draw..."
|
32
16
|
else
|
33
|
-
|
17
|
+
"It is #{ttt.player}`s turn..."
|
34
18
|
end
|
35
19
|
end
|
36
20
|
|
37
|
-
|
38
|
-
# pad the status with spaces to replace old characters
|
39
|
-
message += " " * (STATUS_LINE_LENGTH - message.length)
|
40
|
-
write(STATUS_LINE, 0, message)
|
41
|
-
end
|
42
|
-
|
43
|
-
init_screen do
|
21
|
+
Dispel::Screen.open do |screen|
|
44
22
|
ttt = TicTacToe.new
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
when
|
53
|
-
when
|
54
|
-
when
|
55
|
-
when
|
56
|
-
when
|
57
|
-
when 10 then ttt.set # enter
|
58
|
-
when ?q then break
|
59
|
-
when ?r then ttt = TicTacToe.new
|
23
|
+
screen.draw draw(ttt)
|
24
|
+
|
25
|
+
Dispel::Keyboard.output do |key|
|
26
|
+
case key
|
27
|
+
when :up then ttt.move(0,-1)
|
28
|
+
when :down then ttt.move(0,1)
|
29
|
+
when :right then ttt.move(1,0)
|
30
|
+
when :left then ttt.move(-1,0)
|
31
|
+
when "a" then ttt.ai_move
|
32
|
+
when :enter then ttt.set # enter
|
33
|
+
when "q" then break
|
34
|
+
when "r" then ttt = TicTacToe.new
|
60
35
|
end
|
36
|
+
screen.draw draw(ttt)
|
61
37
|
end
|
62
|
-
end
|
38
|
+
end
|
data/lib/tic_tac_toe/version.rb
CHANGED
data/tic_tac_toe.gemspec
CHANGED
metadata
CHANGED
@@ -1,32 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tic_tac_toe
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 2
|
10
|
-
version: 0.2.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Michael Grosser
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
date: 2013-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dispel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
21
27
|
description:
|
22
28
|
email: michael@grosser.it
|
23
|
-
executables:
|
29
|
+
executables:
|
24
30
|
- tic_tac_toe
|
25
31
|
extensions: []
|
26
|
-
|
27
32
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
33
|
+
files:
|
30
34
|
- Gemfile
|
31
35
|
- Gemfile.lock
|
32
36
|
- Rakefile
|
@@ -38,37 +42,27 @@ files:
|
|
38
42
|
- spec/tic_tac_toe_spec.rb
|
39
43
|
- tic_tac_toe.gemspec
|
40
44
|
homepage: http://github.com/grosser/tic_tac_toe
|
41
|
-
licenses:
|
45
|
+
licenses:
|
42
46
|
- MIT
|
47
|
+
metadata: {}
|
43
48
|
post_install_message:
|
44
49
|
rdoc_options: []
|
45
|
-
|
46
|
-
require_paths:
|
50
|
+
require_paths:
|
47
51
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ">="
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 3
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
version: "0"
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
66
62
|
requirements: []
|
67
|
-
|
68
63
|
rubyforge_project:
|
69
|
-
rubygems_version:
|
64
|
+
rubygems_version: 2.0.14
|
70
65
|
signing_key:
|
71
|
-
specification_version:
|
66
|
+
specification_version: 4
|
72
67
|
summary: Play Tic-Tac-Toe using Curses
|
73
68
|
test_files: []
|
74
|
-
|