reversi 1.0.2 → 2.0.0

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.
@@ -5,7 +5,9 @@ module Reversi::Player
5
5
  # Initializes a new BasePlayer object.
6
6
  def initialize(color, board)
7
7
  @my_color = color
8
- @opponent_color = (@my_color == :white ? :black : :white)
8
+ @opponent_color =
9
+ @my_color == Reversi::Board::DISK[:white] ?
10
+ Reversi::Board::DISK[:black] : Reversi::Board::DISK[:white]
9
11
  @board = board
10
12
  end
11
13
 
@@ -22,9 +24,7 @@ module Reversi::Player
22
24
  def put_disk(x, y, my_color = true)
23
25
  @board.push_stack
24
26
  color = my_color ? @my_color : @opponent_color
25
- x = (:a..:h).to_a.index(x) + 1 if x.is_a? Symbol
26
- flip_disks(x, y, color)
27
- @board.put_disk(x, y, color)
27
+ @board.flip_disks(x, y, color)
28
28
  end
29
29
 
30
30
  # Returns an array of the next moves.
@@ -33,13 +33,7 @@ module Reversi::Player
33
33
  # @return [Hash] the next moves
34
34
  def next_moves(my_color = true)
35
35
  color = my_color ? @my_color : @opponent_color
36
- @board.next_moves(color).map do |move|
37
- diff = flip_disks(*move, color)
38
- openness = diff.inject(0){ |sum, (x, y)| sum + @board.openness(x, y) }
39
- # undo the flipped disks
40
- diff.each{ |x, y| @board.put_disk(x, y, my_color ? @opponent_color : @my_color) }
41
- {:move => move, :openness => openness, :result => diff}
42
- end
36
+ @board.next_moves(color)
43
37
  end
44
38
 
45
39
  # Returns a number of the supplied color's disks.
@@ -47,7 +41,8 @@ module Reversi::Player
47
41
  # @param my_color [Boolean] my color or opponent's color
48
42
  # @return [Integer] a number of the supplied color's disks
49
43
  def count_disks(my_color = true)
50
- @board.count_disks(my_color ? @my_color : @opponent_color)
44
+ color = my_color ? @my_color : @opponent_color
45
+ @board.count_disks(color)
51
46
  end
52
47
 
53
48
  # Returns a hash containing the coordinates of each color.
@@ -55,19 +50,10 @@ module Reversi::Player
55
50
  # @return [Hash{Symbol => Array<Symbol, Integer>}]
56
51
  def status
57
52
  convert = {
58
- :black => @my_color == :black ? :mine : :opponent,
59
- :white => @my_color == :white ? :mine : :opponent,
53
+ :black => @my_color == Reversi::Board::DISK[:black] ? :mine : :opponent,
54
+ :white => @my_color == Reversi::Board::DISK[:white] ? :mine : :opponent,
60
55
  :none => :none }
61
56
  Hash[*@board.status.map{ |k, v| [convert[k], v] }.flatten(1)]
62
57
  end
63
-
64
- private
65
-
66
- def flip_disks(x, y, color)
67
- before = @board.status[color]
68
- @board.flip_disks(x, y, color)
69
- after = @board.status[color]
70
- after - before
71
- end
72
58
  end
73
59
  end
@@ -1,6 +1,15 @@
1
1
  module Reversi::Player
2
2
  class Human < BasePlayer
3
3
 
4
+ def initialize(color, _board)
5
+ super
6
+
7
+ case color
8
+ when Reversi::Board::DISK[:black] then @color = :black
9
+ when Reversi::Board::DISK[:white] then @color = :white
10
+ end
11
+ end
12
+
4
13
  def move(board)
5
14
  return if next_moves.empty?
6
15
  puts board.to_s
@@ -14,7 +23,7 @@ module Reversi::Player
14
23
 
15
24
  def input_move
16
25
  loop do
17
- print "#{@my_color}: "
26
+ print "#{@color}: "
18
27
  @input_move = gets.chomp.split("")
19
28
  exit if [['q'], ['e','x','i','t']].include? @input_move
20
29
  redo if check_size == :redo
@@ -40,7 +49,7 @@ module Reversi::Player
40
49
  end
41
50
 
42
51
  def check_valid
43
- unless next_moves.map{ |v| v[:move] }.include?(@input_move)
52
+ unless next_moves.include?(@input_move)
44
53
  return :redo
45
54
  end
46
55
  :valid
@@ -19,7 +19,7 @@ module Reversi::Player
19
19
  end
20
20
 
21
21
  def move(board)
22
- moves = next_moves.map{ |v| v[:move] }
22
+ moves = next_moves
23
23
  return if moves.empty?
24
24
  next_move = moves.map do |move|
25
25
  { :move => move, :point => evaluate(move, board, 3, true) }
@@ -29,7 +29,7 @@ module Reversi::Player
29
29
 
30
30
  def evaluate(move, board, depth, color)
31
31
  put_disk(*move, color)
32
- moves = next_moves(!color).map{ |v| v[:move] }
32
+ moves = next_moves(!color)
33
33
 
34
34
  if depth == 1
35
35
  status[:mine].inject(0){ |sum, xy| sum + @evaluation_value[xy] }
@@ -19,7 +19,7 @@ module Reversi::Player
19
19
  end
20
20
 
21
21
  def move(board)
22
- moves = next_moves.map{ |v| v[:move] }
22
+ moves = next_moves
23
23
  return if moves.empty?
24
24
  next_move = moves.map do |move|
25
25
  { :move => move, :point => evaluate(move, board, 3, true) }
@@ -29,7 +29,7 @@ module Reversi::Player
29
29
 
30
30
  def evaluate(move, board, depth, color)
31
31
  put_disk(*move, color)
32
- moves = next_moves(!color).map{ |v| v[:move] }
32
+ moves = next_moves(!color)
33
33
 
34
34
  if depth == 1
35
35
  status[:mine].inject(0){ |sum, xy| sum + @evaluation_value[xy] }
@@ -2,7 +2,7 @@ module Reversi::Player
2
2
  class RandomAI < BasePlayer
3
3
 
4
4
  def move(board)
5
- moves = next_moves.map{ |v| v[:move] }
5
+ moves = next_moves
6
6
  put_disk(*moves.sample) unless moves.empty?
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Reversi
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -8,13 +8,13 @@ describe Reversi::Player::BasePlayer do
8
8
  describe "#put_disk" do
9
9
  context "when a player make a valid move" do
10
10
  it "flips the opponent's disks between a new disk and my disk" do
11
- expect{ player.put_disk(:d, 3) }.to change{ board.status[:black].size }.by(2)
11
+ expect{ player.put_disk(4, 3) }.to change{ board.status[:black].size }.by(2)
12
12
  end
13
13
  end
14
14
 
15
15
  context "when the third argument is `false`" do
16
16
  it "makes a opponent's move" do
17
- expect{ player.put_disk(:e, 3, false) }.to change{ board.status[:white].size }.by(2)
17
+ expect{ player.put_disk(5, 3, false) }.to change{ board.status[:white].size }.by(2)
18
18
  end
19
19
  end
20
20
  end
@@ -22,29 +22,15 @@ describe Reversi::Player::BasePlayer do
22
22
  describe "#next_moves" do
23
23
  context "when the first argument is omitted" do
24
24
  it do
25
- ans = [[3, 4], [4, 3], [5, 6], [6, 5]]
26
- expect(player.next_moves.map{ |move| move[:move] }).to eq ans
27
- end
28
-
29
- it do
30
- player.put_disk(:d, 3)
31
- player.put_disk(:e, 3, false)
32
- expect(player.next_moves[1][:openness]).to eq 8
33
- expect(player.next_moves[1][:result]).to eq [[5, 3], [5, 4]]
25
+ ans = [[5, 6], [6, 5], [3, 4], [4, 3]]
26
+ expect(player.next_moves).to eq ans
34
27
  end
35
28
  end
36
29
 
37
30
  context "when the first argument is `false`" do
38
31
  it do
39
- ans = [[3, 5], [4, 6], [5, 3], [6, 4]]
40
- expect(player.next_moves(false).map{ |move| move[:move] }).to eq ans
41
- end
42
-
43
- it do
44
- player.put_disk(:d, 3)
45
- player.put_disk(:e, 3, false)
46
- expect(player.next_moves(false)[0][:openness]).to eq 5
47
- expect(player.next_moves(false)[0][:result]).to eq [[4, 3]]
32
+ ans = [[4, 6], [3, 5], [6, 4], [5, 3]]
33
+ expect(player.next_moves(false)).to eq ans
48
34
  end
49
35
  end
50
36
  end
@@ -52,14 +38,14 @@ describe Reversi::Player::BasePlayer do
52
38
  describe "#count_disks" do
53
39
  context "when the first argument is omitted" do
54
40
  it do
55
- board.put_disk(:a, 1, :black)
41
+ board.put_disk(1, 1, Reversi::Board::DISK[:black])
56
42
  expect(player.count_disks).to eq 3
57
43
  end
58
44
  end
59
45
 
60
46
  context "when the first argument is `false`" do
61
47
  it do
62
- board.put_disk(:a, 1, :black)
48
+ board.put_disk(1, 1, Reversi::Board::DISK[:black])
63
49
  expect(player.count_disks(false)).to eq 2
64
50
  end
65
51
  end
@@ -67,6 +53,6 @@ describe Reversi::Player::BasePlayer do
67
53
 
68
54
  describe "#status" do
69
55
  it { expect(player.status[:mine]).to eq [[4, 5], [5, 4]] }
70
- it { expect(player.status[:opponent]).to eq [[4, 4], [5, 5]] }
56
+ it { expect(player.status[:opponent]).to eq [[5, 5], [4, 4]] }
71
57
  end
72
58
  end
data/spec/board_spec.rb CHANGED
@@ -8,8 +8,8 @@ describe Reversi::Board do
8
8
  :disk_w => "w",
9
9
  :disk_color_b => disk_color_b,
10
10
  :disk_color_w => disk_color_w,
11
- :initial_position => {:black => [[:d, 5], [:e, 4]],
12
- :white => [[:d, 4], [:e, 5]]},
11
+ :initial_position => {:black => [[4, 5], [5, 4]],
12
+ :white => [[4, 4], [5, 5]]},
13
13
  :progress => false,
14
14
  :stack_limit => 3}
15
15
  end
@@ -75,7 +75,7 @@ describe Reversi::Board do
75
75
 
76
76
  it "the deep copy operation is used" do
77
77
  board.push_stack
78
- board.put_disk(:a, 1, :black)
78
+ board.put_disk(1, 1, Reversi::Board::DISK[:black])
79
79
  board.push_stack
80
80
  expect(board.stack[0]).not_to eq board.stack[1]
81
81
  end
@@ -97,8 +97,10 @@ describe Reversi::Board do
97
97
  let(:disk_color_b) { 0 }
98
98
  let(:disk_color_w) { 0 }
99
99
  it "returns a hash containing the coordinates of each color" do
100
- expect{ board.put_disk(:a, 1, :black) }.to change{ board.status[:black].size }.by(1)
101
- expect{ board.put_disk(:b, 1, :black) }.to change{ board.status[:none].size }.by(-1)
100
+ expect{ board.put_disk(1, 1, Reversi::Board::DISK[:black]) }
101
+ .to change{ board.status[:black].size }.by(1)
102
+ expect{ board.put_disk(2, 1, Reversi::Board::DISK[:black]) }
103
+ .to change{ board.status[:none].size }.by(-1)
102
104
  end
103
105
  end
104
106
 
@@ -106,9 +108,9 @@ describe Reversi::Board do
106
108
  let(:disk_color_b) { 0 }
107
109
  let(:disk_color_w) { 0 }
108
110
  it "returns the openness of the coordinates" do
109
- expect(board.openness(:a, 1)).to eq 3
110
- expect(board.openness(:b, 2)).to eq 8
111
- expect(board.openness(:d, 4)).to eq 5
111
+ expect(board.openness(1, 1)).to eq 3
112
+ expect(board.openness(2, 2)).to eq 8
113
+ expect(board.openness(4, 4)).to eq 5
112
114
  end
113
115
  end
114
116
 
@@ -116,45 +118,40 @@ describe Reversi::Board do
116
118
  let(:disk_color_b) { 0 }
117
119
  let(:disk_color_w) { 0 }
118
120
 
119
- context "when the first argument is a number" do
120
- it do
121
- board.put_disk(:c, 3, :white)
122
- expect(board.at(3, 3)).to eq :white
123
- end
124
- end
125
-
126
- context "when the first argument is a symbol" do
127
- it do
128
- board.put_disk(7, 8, :black)
129
- expect(board.at(:g, 8)).to eq :black
130
- end
121
+ it do
122
+ board.put_disk(3, 3, Reversi::Board::DISK[:white])
123
+ expect(board.at(3, 3)).to eq :white
124
+ expect(board.at(1, 1)).to eq :none
125
+ expect(board.at(4, 5)).to eq :black
131
126
  end
132
127
  end
133
128
 
134
129
  describe "#count_disks" do
135
130
  let(:disk_color_b) { 0 }
136
131
  let(:disk_color_w) { 0 }
137
- it { expect(board.count_disks(:black)).to eq 2 }
138
- it { expect(board.count_disks(:white)).to eq 2 }
139
- it { expect(board.count_disks(:none)).to eq 60 }
132
+ it { expect(board.count_disks(Reversi::Board::DISK[:black])).to eq 2 }
133
+ it { expect(board.count_disks(Reversi::Board::DISK[:white])).to eq 2 }
134
+ it { expect(board.count_disks(Reversi::Board::DISK[:none])).to eq 60 }
140
135
  end
141
136
 
142
137
  describe "#next_moves" do
143
138
  let(:disk_color_b) { 0 }
144
139
  let(:disk_color_w) { 0 }
145
- it { expect(board.next_moves(:black)).to eq [[3, 4], [4, 3], [5, 6], [6, 5]] }
146
- it { expect(board.next_moves(:white)).to eq [[3, 5], [4, 6], [5, 3], [6, 4]] }
140
+ it { expect(board.next_moves(Reversi::Board::DISK[:black]))
141
+ .to eq [[5, 6], [6, 5], [3, 4], [4, 3]] }
142
+ it { expect(board.next_moves(Reversi::Board::DISK[:white]))
143
+ .to eq [[4, 6], [3, 5], [6, 4], [5, 3]] }
147
144
  end
148
145
 
149
146
  describe "#put_disk, #flip_disks" do
150
147
  let(:disk_color_b) { 0 }
151
148
  let(:disk_color_w) { 0 }
152
149
  it "flips the opponent's disks between a new disk and another disk of my color" do
153
- board.put_disk(:d, 6, :white)
154
- board.put_disk(:e, 3, :white)
155
- board.put_disk(:f, 3, :black)
156
- board.put_disk(:d, 3, :black)
157
- expect{ board.flip_disks(:d, 3, :black) }.to change{ board.status[:black].size }.by(2)
150
+ board.put_disk(4, 6, Reversi::Board::DISK[:white])
151
+ board.put_disk(5, 3, Reversi::Board::DISK[:white])
152
+ board.put_disk(6, 3, Reversi::Board::DISK[:black])
153
+ expect{ board.flip_disks(4, 3, Reversi::Board::DISK[:black]) }
154
+ .to change{ board.status[:black].size }.by(3)
158
155
  end
159
156
  end
160
157
  end
data/spec/game_spec.rb CHANGED
@@ -4,18 +4,18 @@ describe Reversi::Game do
4
4
  describe "next moves" do
5
5
  before do
6
6
  @game = Reversi::Game.new
7
- @game.board.put_disk(6, 3, :black)
8
- @game.board.put_disk(6, 5, :black)
9
- @game.board.put_disk(6, 6, :black)
10
- @game.board.put_disk(6, 7, :white)
11
- @game.board.put_disk(7, 4, :black)
12
- @game.board.put_disk(8, 4, :black)
7
+ @game.board.put_disk(6, 3, Reversi::Board::DISK[:black])
8
+ @game.board.put_disk(6, 5, Reversi::Board::DISK[:black])
9
+ @game.board.put_disk(6, 6, Reversi::Board::DISK[:black])
10
+ @game.board.put_disk(6, 7, Reversi::Board::DISK[:white])
11
+ @game.board.put_disk(7, 4, Reversi::Board::DISK[:black])
12
+ @game.board.put_disk(8, 4, Reversi::Board::DISK[:black])
13
13
  end
14
14
 
15
15
  context "before `player_w` places a piece on position [f4]" do
16
16
  it do
17
- ans = [[3, 5], [4, 6], [5, 3], [6, 4], [7, 5], [7, 7]]
18
- expect(@game.player_w.next_moves.map{ |move| move[:move] }).to eq ans
17
+ ans = [[7, 7], [4, 6], [7, 5], [3, 5], [6, 4], [5, 3]]
18
+ expect(@game.player_w.next_moves).to eq ans
19
19
  end
20
20
  it { expect(@game.player_w.count_disks).to eq 3 }
21
21
  it { expect(@game.player_b.count_disks).to eq 7 }
@@ -23,11 +23,11 @@ describe Reversi::Game do
23
23
 
24
24
  context "after `player_w` places a piece on position [f4]" do
25
25
  before do
26
- @game.player_w.put_disk(:f, 4)
26
+ @game.player_w.put_disk(6, 4)
27
27
  end
28
28
  it do
29
- ans = [[3, 5], [3, 6], [4, 6], [6, 2], [7, 2], [8, 3]]
30
- expect(@game.player_w.next_moves.map{ |move| move[:move] }).to eq ans
29
+ ans = [[4, 6], [3, 6], [3, 5], [8, 3], [7, 2], [6, 2]]
30
+ expect(@game.player_w.next_moves).to eq ans
31
31
  end
32
32
  it { expect(@game.player_w.count_disks).to eq 7 }
33
33
  it { expect(@game.player_b.count_disks).to eq 4 }
@@ -37,17 +37,17 @@ describe Reversi::Game do
37
37
  describe "initial position" do
38
38
  it "default" do
39
39
  game = Reversi::Game.new
40
- expect(game.board.at(:e, 4)).to eq :black
41
- expect(game.board.at(:d, 4)).to eq :white
40
+ expect(game.board.at(5, 4)).to eq :black
41
+ expect(game.board.at(4, 4)).to eq :white
42
42
  end
43
43
 
44
44
  it "original position" do
45
- initial = {:black => [[:a, 1]], :white => [[:h, 8]]}
45
+ initial = {:black => [[1, 1]], :white => [[8, 8]]}
46
46
  options = {:initial_position => initial}
47
47
  game = Reversi::Game.new(options)
48
- expect(game.board.at(:d, 4)).to eq :none
49
- expect(game.board.at(:a, 1)).to eq :black
50
- expect(game.board.at(:h, 8)).to eq :white
48
+ expect(game.board.at(4, 4)).to eq :none
49
+ expect(game.board.at(1, 1)).to eq :black
50
+ expect(game.board.at(8, 8)).to eq :white
51
51
  end
52
52
  end
53
53
 
@@ -65,49 +65,44 @@ describe Reversi::Game do
65
65
 
66
66
  describe "from a record of a reversi game" do
67
67
  game = Reversi::Game.new
68
- game.player_b.put_disk(:c, 4); game.player_w.put_disk(:e, 3)
69
- game.player_b.put_disk(:f, 6); game.player_w.put_disk(:e, 6)
70
- game.player_b.put_disk(:f, 5); game.player_w.put_disk(:c, 5)
71
- game.player_b.put_disk(:f, 4); game.player_w.put_disk(:g, 6)
72
- game.player_b.put_disk(:f, 7); game.player_w.put_disk(:d, 3)
73
- game.player_b.put_disk(:f, 3); game.player_w.put_disk(:g, 5)
74
- game.player_b.put_disk(:g, 4); game.player_w.put_disk(:e, 7)
75
- game.player_b.put_disk(:d, 6); game.player_w.put_disk(:h, 3)
76
- game.player_b.put_disk(:f, 8); game.player_w.put_disk(:g, 3)
77
- game.player_b.put_disk(:c, 6); game.player_w.put_disk(:c, 3)
78
- game.player_b.put_disk(:c, 2); game.player_w.put_disk(:d, 7)
79
- game.player_b.put_disk(:e, 8); game.player_w.put_disk(:c, 8)
80
- game.player_b.put_disk(:h, 4); game.player_w.put_disk(:h, 5)
81
- game.player_b.put_disk(:d, 2); game.player_w.put_disk(:d, 8)
82
- game.player_b.put_disk(:b, 8); game.player_w.put_disk(:b, 3)
83
- game.player_b.put_disk(:c, 7); game.player_w.put_disk(:e, 2)
84
- game.player_b.put_disk(:a, 4); game.player_w.put_disk(:d, 1)
85
- game.player_b.put_disk(:c, 1); game.player_w.put_disk(:f, 2)
86
- game.player_b.put_disk(:e, 1); game.player_w.put_disk(:f, 1)
87
- game.player_b.put_disk(:g, 1); game.player_w.put_disk(:a, 3)
88
- game.player_b.put_disk(:b, 5); game.player_w.put_disk(:b, 4)
89
- game.player_b.put_disk(:a, 5); game.player_w.put_disk(:a, 6)
90
- game.player_b.put_disk(:b, 6); game.player_w.put_disk(:a, 7)
91
- game.player_b.put_disk(:g, 2); game.player_w.put_disk(:h, 1)
92
- game.player_b.put_disk(:b, 2); game.player_w.put_disk(:b, 7)
93
- game.player_b.put_disk(:h, 2); game.player_w.put_disk(:g, 7)
94
- game.player_b.put_disk(:a, 8); game.player_w.put_disk(:a, 2)
95
- game.player_b.put_disk(:h, 7); game.player_w.put_disk(:h, 6)
96
- game.player_b.put_disk(:a, 1); game.player_w.put_disk(:b, 1)
97
- game.player_w.put_disk(:g, 8)
98
- game.player_b.put_disk(:h, 8)
99
- ans = [
100
- [2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
101
- [2, -1, -1, -1, -1, -1, -1, -1, -1, 2],
102
- [2, 1, 1, 1, -1, -1, 1, -1, -1, 2],
103
- [2, 1, 1, -1, 1, 1, -1, -1, -1, 2],
104
- [2, 1, -1, 1, 1, -1, -1, -1, -1, 2],
105
- [2, 1, -1, -1, 1, -1, 1, -1, -1, 2],
106
- [2, 1, -1, -1, -1, 1, -1, 1, -1, 2],
107
- [2, 1, -1, -1, 1, 1, 1, -1, -1, 2],
108
- [2, 1, -1, 1, 1, 1, 1, -1, -1, 2],
109
- [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
110
- ]
111
- it { expect(game.board.columns).to eq ans }
68
+ game.player_b.put_disk(3, 4); game.player_w.put_disk(5, 3)
69
+ game.player_b.put_disk(6, 6); game.player_w.put_disk(5, 6)
70
+ game.player_b.put_disk(6, 5); game.player_w.put_disk(3, 5)
71
+ game.player_b.put_disk(6, 4); game.player_w.put_disk(7, 6)
72
+ game.player_b.put_disk(6, 7); game.player_w.put_disk(4, 3)
73
+ game.player_b.put_disk(6, 3); game.player_w.put_disk(7, 5)
74
+ game.player_b.put_disk(7, 4); game.player_w.put_disk(5, 7)
75
+ game.player_b.put_disk(4, 6); game.player_w.put_disk(8, 3)
76
+ game.player_b.put_disk(6, 8); game.player_w.put_disk(7, 3)
77
+ game.player_b.put_disk(3, 6); game.player_w.put_disk(3, 3)
78
+ game.player_b.put_disk(3, 2); game.player_w.put_disk(4, 7)
79
+ game.player_b.put_disk(5, 8); game.player_w.put_disk(3, 8)
80
+ game.player_b.put_disk(8, 4); game.player_w.put_disk(8, 5)
81
+ game.player_b.put_disk(4, 2); game.player_w.put_disk(4, 8)
82
+ game.player_b.put_disk(2, 8); game.player_w.put_disk(2, 3)
83
+ game.player_b.put_disk(3, 7); game.player_w.put_disk(5, 2)
84
+ game.player_b.put_disk(1, 4); game.player_w.put_disk(4, 1)
85
+ game.player_b.put_disk(3, 1); game.player_w.put_disk(6, 2)
86
+ game.player_b.put_disk(5, 1); game.player_w.put_disk(6, 1)
87
+ game.player_b.put_disk(7, 1); game.player_w.put_disk(1, 3)
88
+ game.player_b.put_disk(2, 5); game.player_w.put_disk(2, 4)
89
+ game.player_b.put_disk(1, 5); game.player_w.put_disk(1, 6)
90
+ game.player_b.put_disk(2, 6); game.player_w.put_disk(1, 7)
91
+ game.player_b.put_disk(7, 2); game.player_w.put_disk(8, 1)
92
+ game.player_b.put_disk(2, 2); game.player_w.put_disk(2, 7)
93
+ game.player_b.put_disk(8, 2); game.player_w.put_disk(7, 7)
94
+ game.player_b.put_disk(1, 8); game.player_w.put_disk(1, 2)
95
+ game.player_b.put_disk(8, 7); game.player_w.put_disk(8, 6)
96
+ game.player_b.put_disk(1, 1); game.player_w.put_disk(2, 1)
97
+ game.player_w.put_disk(7, 8)
98
+ game.player_b.put_disk(8, 8)
99
+ ans = {
100
+ :black =>0x809F_AEC4_D8B4_FBFF,
101
+ :white =>0x7F60_513B_274B_0400
102
+ }
103
+ it do
104
+ expect(game.board.send(:black_getter)).to eq ans[:black]
105
+ expect(game.board.send(:white_getter)).to eq ans[:white]
106
+ end
112
107
  end
113
108
  end
data/spec/player_spec.rb CHANGED
@@ -2,27 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  class ValidPlayer < Reversi::Player::BasePlayer
4
4
  def move(board)
5
- moves = next_moves.map{ |v| v[:move] }
5
+ moves = next_moves
6
6
  put_disk(*moves.sample) unless moves.empty?
7
7
  end
8
8
  end
9
9
 
10
10
  class InvalidPlayer1 < Reversi::Player::BasePlayer
11
11
  def move(board)
12
- put_disk(:a, 1)
12
+ put_disk(1, 1)
13
13
  end
14
14
  end
15
15
 
16
16
  class InvalidPlayer2 < Reversi::Player::BasePlayer
17
17
  def move(board)
18
- put_disk(:d, 4)
18
+ put_disk(4, 4)
19
19
  end
20
20
  end
21
21
 
22
22
  class InvalidPlayer3 < Reversi::Player::BasePlayer
23
23
  def move(board)
24
- put_disk(:a, 1)
25
- put_disk(:a, 2)
24
+ put_disk(1, 1)
25
+ put_disk(1, 2)
26
26
  end
27
27
  end
28
28
 
data/white ADDED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reversi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - seinosuke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-17 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,6 +41,11 @@ files:
41
41
  - LICENSE.txt
42
42
  - README.md
43
43
  - Rakefile
44
+ - black
45
+ - ext/reversi/bit_board_functions.c
46
+ - ext/reversi/bit_board_functions.h
47
+ - ext/reversi/board.c
48
+ - ext/reversi/board.h
44
49
  - ext/reversi/extconf.rb
45
50
  - ext/reversi/reversi.c
46
51
  - ext/reversi/reversi.h
@@ -63,6 +68,7 @@ files:
63
68
  - spec/game_spec.rb
64
69
  - spec/player_spec.rb
65
70
  - spec/spec_helper.rb
71
+ - white
66
72
  homepage: https://github.com/seinosuke/reversi
67
73
  licenses:
68
74
  - MIT