OSDN Git Service

enabled ExcludeSacrifice by default
[shogi-server/shogi-server.git] / mk_rate
diff --git a/mk_rate b/mk_rate
index 9982ce8..f8046f0 100755 (executable)
--- a/mk_rate
+++ b/mk_rate
@@ -1,7 +1,7 @@
 #!/usr/bin/ruby
 ## $Id$
 
-## Copyright (C) 2006 Daigo Moriwaki <daigo at debian dot org>
+## Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
 ##
 ## This program is free software; you can redistribute it and/or modify
 ## it under the terms of the GNU General Public License as published by
@@ -23,6 +23,7 @@
 #
 # Sample:
 #   $ ./mk_rate . > players.yaml
+#   $ ./mk_rate . && ./mk_rate . > players.yaml
 #
 # The conditions that games and players are rated as following:
 #   * Rated games, which were played by both rated players.
@@ -619,6 +620,19 @@ USAGE: #{$0} dir [...]
   exit 1
 end
 
+def validate(yaml)
+  yaml["players"].each do |group_key, group|
+    group.each do |player_key, player|
+      rate = player['rate']
+      next unless rate
+      if rate > 10000 || rate < -10000
+        return false
+      end
+    end
+  end
+  return true
+end
+
 def main
   usage if ARGV.empty?
   while dir = ARGV.shift do
@@ -677,6 +691,10 @@ def main
         'win'  => v[0],
         'loss' => v[1]}
   end
+  unless validate(yaml)
+    $stderr.puts "Aborted. It did not result in valid ratings."
+    exit 10
+  end
   puts yaml.to_yaml
 end