Included gomill framework for SGF and GTP support, and sketched out SGF game-loading code.
This commit is contained in:
parent
700a6a2f32
commit
692dc294d6
119 changed files with 27458 additions and 3 deletions
54
gomill/examples/find_forfeits.py
Normal file
54
gomill/examples/find_forfeits.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
"""Find forfeited games in tournament results.
|
||||
|
||||
This demonstrates retrieving and processing results from a tournament.
|
||||
|
||||
"""
|
||||
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
from gomill.common import opponent_of
|
||||
from gomill.ringmasters import Ringmaster, RingmasterError
|
||||
|
||||
def show_result(matchup, result, filename):
|
||||
print "%s: %s forfeited game %s" % (
|
||||
matchup.name, result.losing_player, filename)
|
||||
|
||||
def find_forfeits(ringmaster):
|
||||
ringmaster.load_status()
|
||||
tournament_results = ringmaster.get_tournament_results()
|
||||
matchup_ids = tournament_results.get_matchup_ids()
|
||||
for matchup_id in matchup_ids:
|
||||
matchup = tournament_results.get_matchup(matchup_id)
|
||||
results = tournament_results.get_matchup_results(matchup_id)
|
||||
for result in results:
|
||||
if result.is_forfeit:
|
||||
filename = ringmaster.get_sgf_filename(result.game_id)
|
||||
show_result(matchup, result, filename)
|
||||
|
||||
|
||||
_description = """\
|
||||
Read results of a tournament and show all forfeited games.
|
||||
"""
|
||||
|
||||
def main(argv):
|
||||
parser = OptionParser(usage="%prog <filename.ctl>",
|
||||
description=_description)
|
||||
opts, args = parser.parse_args(argv)
|
||||
if not args:
|
||||
parser.error("not enough arguments")
|
||||
if len(args) > 1:
|
||||
parser.error("too many arguments")
|
||||
ctl_pathname = args[0]
|
||||
try:
|
||||
ringmaster = Ringmaster(ctl_pathname)
|
||||
find_forfeits(ringmaster)
|
||||
except RingmasterError, e:
|
||||
print >>sys.stderr, "ringmaster:"
|
||||
print >>sys.stderr, e
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue