From 3d228b20abc8b692cc42cc3d5c57686269de2279 Mon Sep 17 00:00:00 2001 From: Daigo Moriwaki Date: Fri, 27 Nov 2015 23:40:28 +0900 Subject: [PATCH 1/1] Fix #35795: A time consumed could be -1 * [shogi-server] shogi_server/time_clock.rb: - A time consumed could be -1. * The start time of a move is captured after sending a move to a player of the next turn at the end of the giant lock * The end time of the move is captured at the exact time when the server receives it before the giant lock Therefore, end_time < start_time is possible when a player returns a move instantly. Thanks to Tomoyuki Kaneko for reporting this issue. (Closes: #35795) --- changelog | 13 +++++++++++++ shogi_server/time_clock.rb | 5 ----- test/TC_time_clock.rb | 2 ++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/changelog b/changelog index 2364fec..aae3085 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,16 @@ +2015-11-27 Daigo Moriwaki + + * [shogi-server] shogi_server/time_clock.rb: + - A time consumed could be -1. + * The start time of a move is captured after sending a move to a + player of the next turn at the end of the giant lock + * The end time of the move is captured at the exact time when the + server receives it before the giant lock + Therefore, end_time < start_time is possible when a player returns a + move instantly. + Thanks to Tomoyuki Kaneko for reporting this issue. + (Closes: #35795) + 2015-02-14 Daigo Moriwaki * util/statistics.rb: diff --git a/shogi_server/time_clock.rb b/shogi_server/time_clock.rb index 52a747d..06ac229 100644 --- a/shogi_server/time_clock.rb +++ b/shogi_server/time_clock.rb @@ -125,11 +125,6 @@ class ChessClockWithLeastZero < ChessClock super end - def time_duration(mytime, start_time, end_time) - t = end_time - start_time - return t.floor - end - def to_s return "ChessClockWithLeastZero: LeastTimePerMove %d; TotalTime %d; Byoyomi %d" % [@least_time_per_move, @total_time, @byoyomi] end diff --git a/test/TC_time_clock.rb b/test/TC_time_clock.rb index aa98ae7..215fef4 100644 --- a/test/TC_time_clock.rb +++ b/test/TC_time_clock.rb @@ -79,6 +79,8 @@ class TestChessClockWithLeastZero < Test::Unit::TestCase assert_equal(1, tc.time_duration(1, 100, 101)) # 1 assert_equal(2, tc.time_duration(100, 100.1, 102.9)) # 2.8 assert_equal(2, tc.time_duration(100, 100, 102)) # 2 + + assert_equal(0, tc.time_duration(100, 100, 99.9)) # -0.1 end def test_time_duration_over_thinking_time -- 2.11.0