OSDN Git Service

Fix some lint warnings
authorDaigo Moriwaki <daigo@debian.org>
Sun, 3 Apr 2016 09:55:16 +0000 (09:55 +0000)
committerDaigo Moriwaki <daigo@debian.org>
Sun, 3 Apr 2016 09:55:16 +0000 (09:55 +0000)
changelog
shogi_server/command.rb
shogi_server/game.rb
shogi_server/league/floodgate.rb
shogi_server/league/floodgate_thread.rb
shogi_server/login.rb
test/TC_command.rb

index c7c1c52..db12f16 100644 (file)
--- a/changelog
+++ b/changelog
@@ -20,6 +20,7 @@
          - Kifu files can include the following comment for Fischer Time
            Control:
            - "'Increment:<n>"
          - Kifu files can include the following comment for Fischer Time
            Control:
            - "'Increment:<n>"
+       * [shogi-server] Fix some lint warnings.
 
 2015-12-13  Daigo Moriwaki <daigo at debian dot org>
 
 
 2015-12-13  Daigo Moriwaki <daigo at debian dot org>
 
index b3e5ca2..dedbaae 100644 (file)
@@ -552,7 +552,7 @@ module ShogiServer
             board = Board.new
             begin
               board.set_from_moves(moves_array)
             board = Board.new
             begin
               board.set_from_moves(moves_array)
-            rescue => err
+            rescue
               # it will never happen since moves have already been checked
               log_error "Failed to set up a buoy game: #{moves}"
               return :continue
               # it will never happen since moves have already been checked
               log_error "Failed to set up a buoy game: #{moves}"
               return :continue
@@ -775,7 +775,7 @@ module ShogiServer
       # found two players: p1 and p2
       log_info("Starting a buoy game: %s with %s and %s" % [@game_name, p1.name, p2.name])
       buoy.decrement_count(buoy_game)
       # found two players: p1 and p2
       log_info("Starting a buoy game: %s with %s and %s" % [@game_name, p1.name, p2.name])
       buoy.decrement_count(buoy_game)
-      game = Game::new(@game_name, p1, p2, board)
+      Game::new(@game_name, p1, p2, board)
       return :continue
 
     rescue WrongMoves => e
       return :continue
 
     rescue WrongMoves => e
index 9bcecfb..cd7c41a 100644 (file)
@@ -267,6 +267,8 @@ class Game
       return false            # time isn't expired. players aren't swapped. continue game
     else
       t = @time_clock.process_time(@current_player, @start_time, @end_time)
       return false            # time isn't expired. players aren't swapped. continue game
     else
       t = @time_clock.process_time(@current_player, @start_time, @end_time)
+      log_info(sprintf("+++ DEBUG %s consumed %d sec. remain %d sec",
+                @current_player.name, t, @current_player.mytime))
       move_status = @board.handle_one_move(str, @sente == @current_player)
       # log_debug("move_status: %s for %s's %s" % [move_status, @sente == @current_player ? "BLACK" : "WHITE", str])
 
       move_status = @board.handle_one_move(str, @sente == @current_player)
       # log_debug("move_status: %s for %s's %s" % [move_status, @sente == @current_player ? "BLACK" : "WHITE", str])
 
index c184738..da46a8a 100644 (file)
@@ -388,12 +388,12 @@ class League
         @@mutex.synchronize do
           records = @records.reverse
         end
         @@mutex.synchronize do
           records = @records.reverse
         end
-        rc = records.find do |rc|
+        ret = records.find do |rc|
           rc[:winner] && 
           rc[:loser]  && 
           (rc[:black] == player_id || rc[:white] == player_id)
         end
           rc[:winner] && 
           rc[:loser]  && 
           (rc[:black] == player_id || rc[:white] == player_id)
         end
-        return rc
+        return ret
       end
 
       def win_games(player_id)
       end
 
       def win_games(player_id)
@@ -401,10 +401,10 @@ class League
         @@mutex.synchronize do
           records = @records.reverse
         end
         @@mutex.synchronize do
           records = @records.reverse
         end
-        rc = records.find_all do |rc|
+        ret = records.find_all do |rc|
           rc[:winner] == player_id && rc[:loser]
         end
           rc[:winner] == player_id && rc[:loser]
         end
-        return rc
+        return ret
       end
 
       def loss_games(player_id)
       end
 
       def loss_games(player_id)
@@ -412,10 +412,10 @@ class League
         @@mutex.synchronize do
           records = @records.reverse
         end
         @@mutex.synchronize do
           records = @records.reverse
         end
-        rc = records.find_all do |rc|
+        ret = records.find_all do |rc|
           rc[:winner] && rc[:loser] == player_id
         end
           rc[:winner] && rc[:loser] == player_id
         end
-        return rc
+        return ret
       end
     end # class History
 
       end
     end # class History
 
index b1d9bf7..0c1759b 100644 (file)
@@ -79,6 +79,7 @@ module ShogiServer
                       {:game_name       => prev.game_name,       :next_time => prev.next_time,
                        :pairing_factory => prev.pairing_factory, :sacrifice => prev.sacrifice,
                        :max_moves       => prev.max_moves,       :least_time_per_move => prev.least_time_per_move})
                       {:game_name       => prev.game_name,       :next_time => prev.next_time,
                        :pairing_factory => prev.pairing_factory, :sacrifice => prev.sacrifice,
                        :max_moves       => prev.max_moves,       :least_time_per_move => prev.least_time_per_move})
+        floodgate
       end
       floodgate_reload_log(leagues)
       return leagues
       end
       floodgate_reload_log(leagues)
       return leagues
@@ -100,12 +101,12 @@ module ShogiServer
             floodgate = next_league(leagues)
             next if wait_next_floodgate(floodgate)
 
             floodgate = next_league(leagues)
             next if wait_next_floodgate(floodgate)
 
-            next_instances = leagues.collect do |floodgate|
-              unless (floodgate.next_time - Time.now) > 0
-                start_games(floodgate)
-                floodgate.charge # updates next_time
+            next_instances = leagues.collect do |fg|
+              unless (fg.next_time - Time.now) > 0
+                start_games(fg)
+                fg.charge # updates next_time
               end
               end
-              floodgate
+              fg
             end
 
             reload_shogi_server
             end
 
             reload_shogi_server
index 54e8c25..1f6f47f 100644 (file)
@@ -87,7 +87,7 @@ class Login
   end
 
   def Login.factory(str, player)
   end
 
   def Login.factory(str, player)
-    (login, player.name, password, ext) = str.chomp.split
+    (_, player.name, password, ext) = str.chomp.split
     if ext
       return Loginx1.new(player, password)
     else
     if ext
       return Loginx1.new(player, password)
     else
index 3487b94..440ec34 100644 (file)
@@ -287,29 +287,29 @@ class TestFactoryMethod < Test::Unit::TestCase
     cmd = ShogiServer::Command.factory("should_be_error", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
     cmd = ShogiServer::Command.factory("should_be_error", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
-    assert_match /unknown command: should_be_error/, cmd.msg
+    assert_match(/unknown command: should_be_error/, cmd.msg)
   end
 
   def test_error_login
     cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
   end
 
   def test_error_login
     cmd = ShogiServer::Command.factory("LOGIN hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
-    assert_no_match /unknown command: LOGIN hoge foo/, cmd.msg
+    assert_no_match( /unknown command: LOGIN hoge foo/, cmd.msg)
 
     cmd = ShogiServer::Command.factory("LOGin hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
 
     cmd = ShogiServer::Command.factory("LOGin hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
-    assert_no_match /unknown command: LOGIN hoge foo/, cmd.msg
+    assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
 
     cmd = ShogiServer::Command.factory("LOGIN  hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
 
     cmd = ShogiServer::Command.factory("LOGIN  hoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
-    assert_no_match /unknown command: LOGIN hoge foo/, cmd.msg
+    assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
 
     cmd = ShogiServer::Command.factory("LOGINhoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
 
     cmd = ShogiServer::Command.factory("LOGINhoge foo", @p)
     assert_instance_of(ShogiServer::ErrorCommand, cmd)
     cmd.call
-    assert_no_match /unknown command: LOGIN hoge foo/, cmd.msg
+    assert_no_match(/unknown command: LOGIN hoge foo/, cmd.msg)
   end
 end
 
   end
 end