taka_tic_tac_toe 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/Rakefile +12 -0
- data/lib/taka_tic_tac_toe/ai_difficulty/medium_ai.rb +44 -0
- data/lib/taka_tic_tac_toe/computer.rb +2 -2
- data/lib/taka_tic_tac_toe/console.rb +13 -0
- data/lib/taka_tic_tac_toe/player.rb +6 -0
- data/lib/taka_tic_tac_toe.rb +3 -0
- metadata +15 -68
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -19
data/README.md
CHANGED
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module TakaTicTacToe
|
2
|
+
class MediumAi < Computer
|
3
|
+
Negative_Infinity = -1.0/0
|
4
|
+
|
5
|
+
def make_move(board)
|
6
|
+
#possible_moves = {}
|
7
|
+
best_score = Negative_Infinity
|
8
|
+
best_index = 0
|
9
|
+
board.empty_slots.each do |slots|
|
10
|
+
board.set_move(@mark, slots)
|
11
|
+
score = -negamax_score(board, -1, 0)
|
12
|
+
#possible_moves[slots] = -negamax_score(board, -1)
|
13
|
+
board.undo_move(slots)
|
14
|
+
if score > best_score
|
15
|
+
best_score = score
|
16
|
+
best_index = slots
|
17
|
+
end
|
18
|
+
end
|
19
|
+
#puts possible_moves
|
20
|
+
return best_index
|
21
|
+
end
|
22
|
+
|
23
|
+
def negamax_score(board, color, depth)
|
24
|
+
score = Negative_Infinity
|
25
|
+
|
26
|
+
mark = color == 1 ? @mark : @opponent_mark
|
27
|
+
|
28
|
+
return check_game_state(board, (mark)) if board.has_winner || board.is_tie || depth == 3
|
29
|
+
|
30
|
+
board.empty_slots.each do |slots|
|
31
|
+
board.set_move(mark, slots)
|
32
|
+
score = [score, -negamax_score(board, -color, depth += 1)].max
|
33
|
+
board.undo_move(slots)
|
34
|
+
end
|
35
|
+
return score
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_game_state(board, mark)
|
39
|
+
return 0 if board.is_tie
|
40
|
+
return 1 if board.winner == mark
|
41
|
+
-1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -9,11 +9,11 @@ module TakaTicTacToe
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def difficulty= difficulty
|
12
|
-
@difficulty = TakaTicTacToe
|
12
|
+
@difficulty = eval("TakaTicTacToe::#{difficulty}").new(@mark, @opponent_mark)
|
13
13
|
end
|
14
14
|
|
15
15
|
def make_move(board)
|
16
|
-
@
|
16
|
+
@difficulty.make_move(board)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/taka_tic_tac_toe.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
require 'taka_tic_tac_toe/player'
|
2
|
+
require 'taka_tic_tac_toe/console'
|
1
3
|
require 'taka_tic_tac_toe/game'
|
2
4
|
require 'taka_tic_tac_toe/board'
|
3
5
|
require 'taka_tic_tac_toe/human'
|
4
6
|
require 'taka_tic_tac_toe/computer'
|
5
7
|
require 'taka_tic_tac_toe/ai_difficulty/impossible_ai'
|
6
8
|
require 'taka_tic_tac_toe/ai_difficulty/easy_ai'
|
9
|
+
require 'taka_tic_tac_toe/ai_difficulty/medium_ai'
|
metadata
CHANGED
@@ -1,86 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taka_tic_tac_toe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Taka Goto
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
13
|
-
dependencies:
|
14
|
-
|
15
|
-
name: rdoc
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.12'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '3.12'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: bundler
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.3.5
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.3.5
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: jeweler
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 1.8.4
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8.4
|
62
|
-
description: tic tac toe application
|
12
|
+
date: 2013-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: tic tac toe engine
|
63
15
|
email: tak.yuki@gmail.com
|
64
16
|
executables: []
|
65
17
|
extensions: []
|
66
|
-
extra_rdoc_files:
|
67
|
-
- LICENSE.txt
|
68
|
-
- README.md
|
69
|
-
- README.rdoc
|
18
|
+
extra_rdoc_files: []
|
70
19
|
files:
|
71
|
-
-
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
72
22
|
- lib/taka_tic_tac_toe/ai_difficulty/easy_ai.rb
|
73
23
|
- lib/taka_tic_tac_toe/ai_difficulty/impossible_ai.rb
|
24
|
+
- lib/taka_tic_tac_toe/ai_difficulty/medium_ai.rb
|
74
25
|
- lib/taka_tic_tac_toe/board.rb
|
75
26
|
- lib/taka_tic_tac_toe/computer.rb
|
27
|
+
- lib/taka_tic_tac_toe/console.rb
|
76
28
|
- lib/taka_tic_tac_toe/game.rb
|
77
29
|
- lib/taka_tic_tac_toe/human.rb
|
78
|
-
-
|
79
|
-
-
|
80
|
-
|
81
|
-
|
82
|
-
licenses:
|
83
|
-
- MIT
|
30
|
+
- lib/taka_tic_tac_toe/player.rb
|
31
|
+
- lib/taka_tic_tac_toe.rb
|
32
|
+
homepage:
|
33
|
+
licenses: []
|
84
34
|
post_install_message:
|
85
35
|
rdoc_options: []
|
86
36
|
require_paths:
|
@@ -91,9 +41,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
41
|
- - ! '>='
|
92
42
|
- !ruby/object:Gem::Version
|
93
43
|
version: '0'
|
94
|
-
segments:
|
95
|
-
- 0
|
96
|
-
hash: 4172279214151776976
|
97
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
45
|
none: false
|
99
46
|
requirements:
|
@@ -105,5 +52,5 @@ rubyforge_project:
|
|
105
52
|
rubygems_version: 1.8.24
|
106
53
|
signing_key:
|
107
54
|
specification_version: 3
|
108
|
-
summary: tic tac toe
|
55
|
+
summary: a tic tac toe engine for console and sinatra app
|
109
56
|
test_files: []
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2013 Takayuki Goto
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= taka_tic_tac_toe
|
2
|
-
|
3
|
-
Description goes here.
|
4
|
-
|
5
|
-
== Contributing to taka_tic_tac_toe
|
6
|
-
|
7
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
-
* Fork the project.
|
10
|
-
* Start a feature/bugfix branch.
|
11
|
-
* Commit and push until you are happy with your contribution.
|
12
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
-
|
15
|
-
== Copyright
|
16
|
-
|
17
|
-
Copyright (c) 2013 Takayuki Goto. See LICENSE.txt for
|
18
|
-
further details.
|
19
|
-
|