• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shogi-server source


Commit MetaInfo

修订版728a7894c2ec33a0a339d905249f5c3751bec7d7 (tree)
时间2008-10-19 23:02:29
作者beatles <beatles@b8c6...>
Commiterbeatles

Log Message

Did some refactorings.

更改概述

差异

--- a/utils/eval_graph.rb
+++ b/utils/eval_graph.rb
@@ -1,29 +1,32 @@
1-#!/usr/bin/env ruby
2-# This generates graphs of evaluation values from comments in CSA files.
3-# Ruby libraries that are required:
4-# - RubyGems: http://rubyforge.org/projects/rubygems/
5-# - rgplot: http://rubyforge.org/projects/rgplot/
6-# OS librariles that is required:
7-# - Gnuplot: http://www.gnuplot.info/
8-# On Debian, $ sudo apt-get install gnuplot
9-#
10-# Copyright (C) 2006 Daigo Moriwaki <daigo@debian.org>
1+#!/usr/bin/ruby
2+# This generates graphs of evaluation values from comments in CSA files.
3+# Ruby libraries that are required:
4+# * RubyGems: http://rubyforge.org/projects/rubygems/
5+# * rgplot: http://rubyforge.org/projects/rgplot/
6+# OS librariles that is required:
7+# * Gnuplot: http://www.gnuplot.info/
8+# * On Debian, $ sudo apt-get install gnuplot
119 #
12-# Version: $Id$
10+# Author:: Daigo Moriwaki <daigo at debian dot org>
11+# Copyright:: Copyright (C) 2006-2008 Daigo Moriwaki <daigo at debian dot org>
1312 #
14-# This program is free software; you can redistribute it and/or modify
15-# it under the terms of the GNU General Public License as published by
16-# the Free Software Foundation; either version 2 of the License, or
17-# (at your option) any later version.
13+# $Id$
1814 #
19-# This program is distributed in the hope that it will be useful,
20-# but WITHOUT ANY WARRANTY; without even the implied warranty of
21-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22-# GNU General Public License for more details.
15+#--
16+# This program is free software; you can redistribute it and/or modify
17+# it under the terms of the GNU General Public License as published by
18+# the Free Software Foundation; either version 2 of the License, or
19+# (at your option) any later version.
2320 #
24-# You should have received a copy of the GNU General Public License
25-# along with this program; if not, write to the Free Software
26-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21+# This program is distributed in the hope that it will be useful,
22+# but WITHOUT ANY WARRANTY; without even the implied warranty of
23+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+# GNU General Public License for more details.
25+#
26+# You should have received a copy of the GNU General Public License
27+# along with this program; if not, write to the Free Software
28+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29+#++
2730
2831 require 'pathname'
2932 require 'getoptlong'
@@ -40,6 +43,16 @@ def reformat_svg(str)
4043 END
4144 end
4245
46+# Parse play time from the game_name, then return it. If the game_name is
47+# not valid, return 0.
48+#
49+def play_time(game_name)
50+ if /.*?\+.*?\-(\d*?)\-/ =~ game_name
51+ return $1.to_i
52+ end
53+ return 0
54+end
55+
4356 module EvalGraph
4457 def parse_comment(str)
4558 return nil unless str
@@ -62,9 +75,10 @@ module EvalGraph
6275 @comments = []
6376 @times = []
6477 @type = type
65- @regexp_move = Regexp.new("^\\#{@type}\\d{4}\\w{2}")
66- @regexp_name = Regexp.new("^N\\#{@type}(.*)")
67- @regexp_time = Regexp.new(/^T(\d+)/)
78+ @regexp_move = Regexp.new("^\\#{@type}\\d{4}\\w{2}")
79+ @regexp_name = Regexp.new("^N\\#{@type}(.*)")
80+ @regexp_time = Regexp.new(/^T(\d+)/)
81+ @regexp_comment = Regexp.new(/^'\*\*(.*)/)
6882 @flag = false
6983 @name = nil
7084 end
@@ -85,7 +99,7 @@ module EvalGraph
8599 if @flag
86100 @times << $1.to_i
87101 end
88- when /^'\*\*(.*)/
102+ when @regexp_comment
89103 if @flag
90104 @comments << EvalGraph::parse_comment($1)
91105 @flag = false
@@ -97,10 +111,13 @@ module EvalGraph
97111 end
98112 end
99113
100- def time_values(y_max, full_time)
101- consume = full_time
114+ # Return times for each move which the player played.
115+ # return[0] is the initial play_time.
116+ #
117+ def time_values(y_max, play_time)
118+ consume = play_time
102119 values = []
103- values << 1.0*y_max/full_time*consume
120+ values << 1.0*y_max/play_time*consume
104121 @times.each do |t|
105122 if consume == 0
106123 break
@@ -109,12 +126,11 @@ module EvalGraph
109126 if consume < 0
110127 consume = 0
111128 end
112- values << 1.0*y_max/full_time*consume
129+ values << 1.0*y_max/play_time*consume
113130 end
114131 return values
115132 end
116-
117- end
133+ end # Player
118134
119135 class Black < Player
120136 def name
@@ -132,7 +148,8 @@ module EvalGraph
132148 [moves, comments.compact.unshift(0)]
133149 end
134150
135- def time_values(y_max, full_time)
151+ # Return moves and times. For example, [[0,1,3], [900, 899, 898]]
152+ def time_values(y_max, play_time)
136153 values = super
137154 moves = [0]
138155 return [moves, values] if values.size <= 1
@@ -144,7 +161,7 @@ module EvalGraph
144161 end
145162 return [moves, values]
146163 end
147- end
164+ end # Black
148165
149166 class White < Player
150167 def name
@@ -160,7 +177,7 @@ module EvalGraph
160177 [moves, comments.compact.unshift(0)]
161178 end
162179
163- def time_values(y_max, full_time)
180+ def time_values(y_max, play_time)
164181 values = super
165182 moves = [0]
166183 return [moves, values] if values.size <= 1
@@ -171,8 +188,8 @@ module EvalGraph
171188 i += 2
172189 end
173190 return [moves, values]
174- end
175- end
191+ end
192+ end # White
176193
177194
178195 def create_players
@@ -183,14 +200,8 @@ module EvalGraph
183200 return black,white
184201 end
185202 module_function :create_players
186-end
203+end # module EvalGraph
187204
188-def max_time(game_name)
189- if /.*?\+.*?\-(\d*?)\-/ =~ game_name
190- return $1.to_i
191- end
192- return 0
193-end
194205
195206 def plot(csa_file, title, black, white)
196207 width = [black.comments.size, white.comments.size].max * 2 + 1
@@ -214,7 +225,7 @@ def plot(csa_file, title, black, white)
214225 plot.key "left"
215226
216227 plot.style "line 1 linewidth 5 linetype 0 linecolor rgbcolor \"red\""
217- plot.style "line 2 linewidth 5 linetype 0 linecolor rgbcolor \"blue\""
228+ plot.style "line 2 linewidth 4 linetype 0 linecolor rgbcolor \"blue\""
218229
219230 plot.data << Gnuplot::DataSet.new( black.eval_values ) do |ds|
220231 ds.with = "lines ls 1"
@@ -226,20 +237,21 @@ def plot(csa_file, title, black, white)
226237 ds.title = white.name
227238 end
228239
229- full_time = max_time(csa_file)
230- if full_time > 0
240+ a_play_time = play_time(csa_file)
241+ if a_play_time > 0
231242 plot.style "line 5 linewidth 1 linetype 0 linecolor rgbcolor \"red\""
232243 plot.style "line 6 linewidth 1 linetype 0 linecolor rgbcolor \"blue\""
233244 plot.style "fill solid 0.25 noborder"
234245
235- plot.data << Gnuplot::DataSet.new( black.time_values(2000, full_time) ) do |ds|
246+ plot.data << Gnuplot::DataSet.new( black.time_values(2000, a_play_time) ) do |ds|
236247 ds.with = "boxes notitle ls 5"
237248 end
238249
239- plot.data << Gnuplot::DataSet.new( white.time_values(-2000, full_time) ) do |ds|
250+ plot.data << Gnuplot::DataSet.new( white.time_values(-2000, a_play_time) ) do |ds|
240251 ds.with = "boxes notitle ls 6"
241252 end
242- end
253+ end # if
254+
243255 end
244256 end
245257 end