shogi-server source
Revisão | 0e15a0c82b0e16fab234e3ce00b4e296262577d5 (tree) |
---|---|
Hora | 2014-07-26 16:01:03 |
Autor | Daigo Moriwaki <daigo@debi...> |
Commiter | Daigo Moriwaki |
Merge branch '201407-abnormal'
@@ -1,3 +1,12 @@ | ||
1 | +2014-07-19 Daigo Moriwaki <daigo at debian dot org> | |
2 | + | |
3 | + * [mk_rate] | |
4 | + - Added a new option, --abnormal-threshold n: | |
5 | + Games that end with the 'abnormal' status are counted in | |
6 | + win/lost games for the rating calculation if a game plays more | |
7 | + than n plies. Otherwise (or if n is zero), abnormal games are | |
8 | + counted out of rating games. | |
9 | + | |
1 | 10 | 2013-12-29 Daigo Moriwaki <daigo at debian dot org> |
2 | 11 | |
3 | 12 | * [shogi-server] |
@@ -35,12 +35,18 @@ | ||
35 | 35 | # ./mk_rate [options] |
36 | 36 | # |
37 | 37 | # GAME_RESULTS_FILE:: |
38 | -# a path to a file listing results of games, which is genrated by the | |
38 | +# a path to a file listing results of games, which is generated by the | |
39 | 39 | # mk_game_results command. |
40 | 40 | # In the second style above, the file content can be read from the stdin. |
41 | 41 | # |
42 | +# --abnormal-threshold:: | |
43 | +# n [plies] (default 30) | |
44 | +# Games that end with the 'abnormal' status are counted in win/lost games | |
45 | +# for the rating calculation if a game plays more than n plies. Otherwise | |
46 | +# (or if n is zero), abnormal games are counted out of rating games. | |
47 | +# | |
42 | 48 | # --base-date:: |
43 | -# a base time point for this calicuration (default now). Ex. '2009-10-31' | |
49 | +# a base time point for this calculation (default now). Ex. '2009-10-31' | |
44 | 50 | # |
45 | 51 | # --half-life:: |
46 | 52 | # n [days] (default 60) |
@@ -68,7 +74,7 @@ | ||
68 | 74 | # |
69 | 75 | # == PREREQUIRE |
70 | 76 | # |
71 | -# Sample Command lines that isntall prerequires will work on Debian. | |
77 | +# Sample Command lines that install prerequires will work on Debian. | |
72 | 78 | # |
73 | 79 | # * Ruby 1.9.3 or 1.8.7 (including Rubygems) |
74 | 80 | # |
@@ -101,6 +107,8 @@ | ||
101 | 107 | # * (Rated) players, who played more than $GAMES_LIMIT [15] (rated) games. |
102 | 108 | # |
103 | 109 | |
110 | +$:.unshift(File.dirname(File.expand_path(__FILE__))) | |
111 | +require 'utils/csa-filter' | |
104 | 112 | require 'yaml' |
105 | 113 | require 'time' |
106 | 114 | require 'getoptlong' |
@@ -670,7 +678,12 @@ def parse(line) | ||
670 | 678 | return |
671 | 679 | end |
672 | 680 | |
673 | - return if state == "abnormal" | |
681 | + if state == "abnormal" | |
682 | + csa = CsaFileReader.new(file, "EUC-JP") | |
683 | + if $options["abnormal-threshold"] == 0 || csa.ply <= $options["abnormal-threshold"] | |
684 | + return | |
685 | + end | |
686 | + end | |
674 | 687 | time = Time.parse(time) |
675 | 688 | return if $options["base-date"] < time |
676 | 689 | how_long_days = ($options["base-date"] - time)/(3600*24) |
@@ -728,14 +741,15 @@ end | ||
728 | 741 | def main |
729 | 742 | $options = Hash::new |
730 | 743 | parser = GetoptLong.new( |
731 | - ["--base-date", GetoptLong::REQUIRED_ARGUMENT], | |
732 | - ["--half-life", GetoptLong::REQUIRED_ARGUMENT], | |
733 | - ["--half-life-ignore", GetoptLong::REQUIRED_ARGUMENT], | |
734 | - ["--help", "-h", GetoptLong::NO_ARGUMENT], | |
735 | - ["--ignore", GetoptLong::REQUIRED_ARGUMENT], | |
736 | - ["--fixed-rate-player", GetoptLong::REQUIRED_ARGUMENT], | |
737 | - ["--fixed-rate", GetoptLong::REQUIRED_ARGUMENT], | |
738 | - ["--skip-draw-games", GetoptLong::NO_ARGUMENT]) | |
744 | + ["--abnormal-threshold", GetoptLong::REQUIRED_ARGUMENT], | |
745 | + ["--base-date", GetoptLong::REQUIRED_ARGUMENT], | |
746 | + ["--half-life", GetoptLong::REQUIRED_ARGUMENT], | |
747 | + ["--half-life-ignore", GetoptLong::REQUIRED_ARGUMENT], | |
748 | + ["--help", "-h", GetoptLong::NO_ARGUMENT], | |
749 | + ["--ignore", GetoptLong::REQUIRED_ARGUMENT], | |
750 | + ["--fixed-rate-player", GetoptLong::REQUIRED_ARGUMENT], | |
751 | + ["--fixed-rate", GetoptLong::REQUIRED_ARGUMENT], | |
752 | + ["--skip-draw-games", GetoptLong::NO_ARGUMENT]) | |
739 | 753 | parser.quiet = true |
740 | 754 | begin |
741 | 755 | parser.each_option do |name, arg| |
@@ -761,6 +775,8 @@ def main | ||
761 | 775 | else |
762 | 776 | $options["base-date"] = Time.now |
763 | 777 | end |
778 | + $options["abnormal-threshold"] ||= 30 | |
779 | + $options["abnormal-threshold"] = $options["abnormal-threshold"].to_i | |
764 | 780 | $options["half-life"] ||= 60 |
765 | 781 | $options["half-life"] = $options["half-life"].to_i |
766 | 782 | $options["half-life-ignore"] ||= 7 |
@@ -42,21 +42,23 @@ class CsaFileReader | ||
42 | 42 | attr_reader :winner, :loser |
43 | 43 | attr_reader :state |
44 | 44 | attr_reader :start_time, :end_time |
45 | + attr_reader :ply | |
45 | 46 | |
46 | - def initialize(file_name) | |
47 | + def initialize(file_name, encoding="Shift_JIS:EUC-JP") | |
47 | 48 | @file_name = file_name |
49 | + @encoding = encoding | |
50 | + @ply = 0 | |
48 | 51 | grep |
49 | 52 | end |
50 | 53 | |
51 | 54 | def grep |
52 | - @str = File.open(@file_name, "r:Shift_JIS:EUC-JP").read | |
55 | + @str = File.open(@file_name, "r:#{@encoding}").read | |
53 | 56 | |
54 | 57 | |
55 | 58 | if /^N\+(.*)$/ =~ @str then @black_name = $1.strip end |
56 | 59 | if /^N\-(.*)$/ =~ @str then @white_name = $1.strip end |
57 | 60 | if /^'summary:(.*)$/ =~ @str |
58 | 61 | @state, p1, p2 = $1.split(":").map {|a| a.strip} |
59 | - return if @state == "abnormal" | |
60 | 62 | p1_name, p1_mark = p1.split(" ") |
61 | 63 | p2_name, p2_mark = p2.split(" ") |
62 | 64 | if p1_name == @black_name |
@@ -92,6 +94,12 @@ class CsaFileReader | ||
92 | 94 | end |
93 | 95 | end |
94 | 96 | end |
97 | + | |
98 | + @str.each_line do |line| | |
99 | + if /^[\+\-]\d{4}[A-Z]{2}/ =~ line | |
100 | + @ply += 1 | |
101 | + end | |
102 | + end | |
95 | 103 | end |
96 | 104 | |
97 | 105 | def movetimes |
@@ -107,7 +115,8 @@ class CsaFileReader | ||
107 | 115 | "BlackName #{@black_name}, WhiteName #{@white_name}\n" + |
108 | 116 | "BlackId #{@black_id}, WhiteId #{@white_id}\n" + |
109 | 117 | "Winner #{@winner}, Loser #{@loser}\n" + |
110 | - "Start #{@start_time}, End #{@end_time}\n" | |
118 | + "Start #{@start_time}, End #{@end_time}\n" + | |
119 | + "Ply #{@ply}" | |
111 | 120 | end |
112 | 121 | |
113 | 122 | def identify_id(id) |