bashrw-ttt 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. metadata +2 -3
  2. data/lib/ttt/ai_medium_back.rb +0 -58
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashrw-ttt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -86,7 +86,6 @@ files:
86
86
  - lib/ttt/ai_easy.rb
87
87
  - lib/ttt/ai_hard.rb
88
88
  - lib/ttt/ai_medium.rb
89
- - lib/ttt/ai_medium_back.rb
90
89
  - lib/ttt/board.rb
91
90
  - lib/ttt/config_helper.rb
92
91
  - lib/ttt/config_options.rb
@@ -1,58 +0,0 @@
1
- require 'ttt/ai'
2
- module TTT
3
- class AIMedium < AI
4
- attr_accessor :max_ply, :best
5
-
6
- def move(options)
7
- board(options[:board].dup)
8
- self.max_ply = set_max_ply(available_moves.length)
9
- self.best = {}
10
- self.best[:index] = nil
11
- self.best[:score] = 0
12
- minimax
13
- end
14
-
15
- def minimax(max_player = true, ply = 0, min_score = 1000, max_score = -1000)
16
- if board.winner?
17
- return(max_player ? (-1000 + ply) : (1000 - ply))
18
- elsif board.draw_game?
19
- return 0
20
- end
21
-
22
- if ply >= max_ply
23
- return(max_player ? (max_score) : (min_score))
24
- end
25
-
26
- best_move = 0
27
- score = (max_player ? max_score : min_score )
28
- available_moves.each do |index|
29
- board[][index] = ( max_player ? side : opposite_side(side) )
30
- score = minimax(!max_player, ply + 1, min_score, max_score)
31
- undo_move(index)
32
- if max_player && score > max_score
33
- max_score = score
34
- best_move = index
35
- elsif !max_player && score < min_score
36
- min_score = score
37
- end
38
- break if max_min_swapped?(max_score, min_score)
39
- end
40
-
41
- return( ply == 0 ? best_move : ( max_player ? max_score : min_score ) )
42
- end
43
-
44
- def set_max_ply(moves)
45
- if moves > 15
46
- return 3
47
- elsif moves > 5
48
- return 5
49
- else
50
- return 7
51
- end
52
- end
53
-
54
- def max_min_swapped?(max, min)
55
- max >= min
56
- end
57
- end
58
- end