taka_tic_tac_toe 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,20 +4,17 @@ module TakaTicTacToe
4
4
  Negative_Infinity = -1.0/0
5
5
 
6
6
  def make_move(board)
7
- #possible_moves = {}
8
7
  best_score = Negative_Infinity
9
8
  best_index = 0
10
9
  board.empty_slots.each do |slots|
11
10
  board.set_move(@mark, slots)
12
11
  score = -negamax_score(board, -1)
13
- #possible_moves[slots] = -negamax_score(board, -1)
14
12
  board.undo_move(slots)
15
13
  if score > best_score
16
14
  best_score = score
17
15
  best_index = slots
18
16
  end
19
17
  end
20
- #puts possible_moves
21
18
  return best_index
22
19
  end
23
20
 
@@ -1,15 +1,14 @@
1
1
  module TakaTicTacToe
2
2
  class Computer
3
- attr_accessor :mark
4
- attr_reader :difficulty, :opponent_mark
3
+ attr_reader :difficulty, :opponent_mark, :mark
5
4
 
6
5
  def initialize(mark, opponent_mark)
7
6
  @mark = mark
8
7
  @opponent_mark = opponent_mark
9
8
  end
10
9
 
11
- def difficulty= difficulty
12
- @difficulty = eval("TakaTicTacToe::#{difficulty}").new(@mark, @opponent_mark)
10
+ def set_difficulty(difficulty)
11
+ @difficulty = difficulty.new(@mark, @opponent_mark)
13
12
  end
14
13
 
15
14
  def make_move(board)
@@ -5,5 +5,9 @@ module TakaTicTacToe
5
5
  def initialize(mark)
6
6
  @mark = mark
7
7
  end
8
+
9
+ def make_move(index, board)
10
+ board.set_move(@mark, index)
11
+ end
8
12
  end
9
13
  end
@@ -3,7 +3,7 @@ module TakaTicTacToe
3
3
  def create(input)
4
4
  if input[:type] == :computer
5
5
  player = Computer.new(input[:mark], input[:opponent_mark])
6
- player.difficulty = input[:difficulty]
6
+ player.set_difficulty(input[:difficulty])
7
7
  elsif input[:type] == :human
8
8
  player = Human.new(input[:mark])
9
9
  else
@@ -1,4 +1,4 @@
1
- require 'taka_tic_tac_toe/computer_factory'
1
+ require 'taka_tic_tac_toe/player_factory'
2
2
  require 'taka_tic_tac_toe/board'
3
3
  require 'taka_tic_tac_toe/human'
4
4
  require 'taka_tic_tac_toe/computer'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taka_tic_tac_toe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
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-04-29 00:00:00.000000000 Z
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: tic tac toe engine
15
15
  email: tak.yuki@gmail.com
@@ -24,8 +24,8 @@ files:
24
24
  - lib/taka_tic_tac_toe/ai_difficulty/medium_ai.rb
25
25
  - lib/taka_tic_tac_toe/board.rb
26
26
  - lib/taka_tic_tac_toe/computer.rb
27
- - lib/taka_tic_tac_toe/computer_factory.rb
28
27
  - lib/taka_tic_tac_toe/human.rb
28
+ - lib/taka_tic_tac_toe/player_factory.rb
29
29
  - lib/taka_tic_tac_toe.rb
30
30
  homepage:
31
31
  licenses: []