shogi-server source
修订版 | eed74ba8dc18b3843e263ed35eeeeab4c086f520 (tree) |
---|---|
时间 | 2012-12-28 17:44:29 |
作者 | Daigo Moriwaki <beatles@user...> |
Commiter | Daigo Moriwaki |
Applied a patch from the wdoor-stable branch: Improved the logic avoiding human-human match.
commit 81d6582813f9af7f2c23c0f056ee6960b3299e05
Author: Daigo Moriwaki <beatles@users.sourceforge.jp>
Date: Fri Dec 28 15:23:45 2012 +0900
>
- shogi_server/pairing.rb:
+ There was a bug in the logic avoiding human-human match.
This issue has been fixed.
+ Improved the logic avoiding human-human match. Human-human
matches will less likely happen.
@@ -1,3 +1,12 @@ | ||
1 | +2012-12-28 Daigo Moriwaki <daigo at debian dot org> | |
2 | + | |
3 | + * [shogi-server] | |
4 | + - shogi_server/pairing.rb: | |
5 | + + There was a bug in the logic avoiding human-human match. | |
6 | + This issue has been fixed. | |
7 | + + Improved the logic avoiding human-human match. Human-human | |
8 | + matches will less likely happen. | |
9 | + | |
1 | 10 | 2012-01-07 Daigo Moriwaki <daigo at debian dot org> |
2 | 11 | |
3 | 12 | * [shogi-server] |
@@ -163,7 +163,7 @@ module ShogiServer | ||
163 | 163 | for i in 0..(humans.size-2) # -2 |
164 | 164 | next if humans[i].odd? |
165 | 165 | if humans[i]+1 == humans[i+1] |
166 | - pairing_possible = i | |
166 | + pairing_possible = humans[i] | |
167 | 167 | break |
168 | 168 | end |
169 | 169 | end |
@@ -173,7 +173,7 @@ module ShogiServer | ||
173 | 173 | end |
174 | 174 | |
175 | 175 | current_index = pairing_possible |
176 | - j = (current_index == 0 ? current_index : current_index-1) | |
176 | + j = [0, current_index - 2].max | |
177 | 177 | while j < players.size |
178 | 178 | break if players[j].is_computer? |
179 | 179 | j += 1 |
@@ -144,6 +144,26 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase | ||
144 | 144 | @d.win = 1000 |
145 | 145 | @d.loss = 2000 |
146 | 146 | @d.rate = 2000 |
147 | + @e = ShogiServer::BasicPlayer.new | |
148 | + @e.name = "e" | |
149 | + @e.win = 3000 | |
150 | + @e.loss = 3000 | |
151 | + @e.rate = 3000 | |
152 | + @f = ShogiServer::BasicPlayer.new | |
153 | + @f.name = "f" | |
154 | + @f.win = 4000 | |
155 | + @f.loss = 4000 | |
156 | + @f.rate = 4000 | |
157 | + @g = ShogiServer::BasicPlayer.new | |
158 | + @g.name = "g" | |
159 | + @g.win = 5000 | |
160 | + @g.loss = 5000 | |
161 | + @g.rate = 5000 | |
162 | + @h = ShogiServer::BasicPlayer.new | |
163 | + @h.name = "h" | |
164 | + @h.win = 6000 | |
165 | + @h.loss = 6000 | |
166 | + @h.rate = 6000 | |
147 | 167 | end |
148 | 168 | |
149 | 169 | def test_match_one_player |
@@ -276,8 +296,8 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase | ||
276 | 296 | players = [@a,@b,@c,@d] |
277 | 297 | @pairing.match(players) |
278 | 298 | assert_equal(2, $paired.size) |
279 | - assert(same_pair?([@a,@b], $paired[0])) | |
280 | - assert(same_pair?([@c,@d], $paired[1])) | |
299 | + assert(same_pair?([@a,@c], $paired[0])) | |
300 | + assert(same_pair?([@b,@d], $paired[1])) | |
281 | 301 | end |
282 | 302 | |
283 | 303 | def test_match_four_players_abcd_human |
@@ -291,6 +311,20 @@ class TestStartGameWithoutHumans < Test::Unit::TestCase | ||
291 | 311 | assert(same_pair?([@a,@b], $paired[0])) |
292 | 312 | assert(same_pair?([@c,@d], $paired[1])) |
293 | 313 | end |
314 | + | |
315 | + def test_match_eight_players_efgh_human | |
316 | + @e.name += "_human" | |
317 | + @f.name += "_human" | |
318 | + @g.name += "_human" | |
319 | + @h.name += "_human" | |
320 | + players = [@a,@b,@c,@d,@e,@f,@g,@h] | |
321 | + @pairing.match(players) | |
322 | + assert_equal(4, $paired.size) | |
323 | + assert(same_pair?([@e,@c], $paired[0])) | |
324 | + assert(same_pair?([@d,@g], $paired[1])) | |
325 | + assert(same_pair?([@a,@f], $paired[2])) | |
326 | + assert(same_pair?([@b,@h], $paired[3])) | |
327 | + end | |
294 | 328 | end |
295 | 329 | |
296 | 330 |