root/06/libkombilo-branches/hash_center/testsearch.py
| Revision 240, 3.0 kB (checked in by ug, 1 year ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | #! /usr/bin/env python2.4 |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | import time |
| 6 | from libkombilo import * |
| 7 | |
| 8 | start = time.time() |
| 9 | gl = GameList('t1.db') |
| 10 | end = time.time() |
| 11 | print gl.size(), 'games in the database' |
| 12 | print 'Opening the db took %.2f seconds.' % (end - start) |
| 13 | # gl.gisearch("pw = 'Cho Chikun'") |
| 14 | # print gl.size(), 'games in the database' |
| 15 | |
| 16 | # p = Pattern(CENTER_PATTERN, 19, 3,4,"..O.....OX..") |
| 17 | p = Pattern(CORNER_NW_PATTERN, 19, 7, 7, |
| 18 | '''....... |
| 19 | ....... |
| 20 | ....... |
| 21 | ...X... |
| 22 | ....... |
| 23 | ....... |
| 24 | .......'''.replace(' ','').replace('\n','')) |
| 25 | # p = Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................') |
| 26 | # p = Pattern(CENTER_PATTERN, 19, 3, 3, '.X.XXXXOX') |
| 27 | # p = Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO') |
| 28 | # p = Pattern(CENTER_PATTERN, 19, 5, 4, '..XOO'+ '...XX'+ '.....'+ '..X..') |
| 29 | so = SearchOptions() |
| 30 | # so.algos = ALGO_FINALPOS | ALGO_MOVELIST |
| 31 | # so.fixedColor = True |
| 32 | # so.nextMove = 2 |
| 33 | start = time.time() |
| 34 | gl.search(p, so) |
| 35 | end = time.time() |
| 36 | # for i in range(gl.size()): |
| 37 | # print gl.currentEntryAsString(i) |
| 38 | # print gl.getCurrentProperty(i, 'EV') |
| 39 | # print '\n'.join(gl.currentEntriesAsStrings()) |
| 40 | print gl.size(), 'games, ', gl.numHits(), 'hits.' |
| 41 | print 'Search pattern:' |
| 42 | print p.printPattern() |
| 43 | print 'Continuations:' |
| 44 | for y in range(p.sizeY): |
| 45 | for x in range(p.sizeX): |
| 46 | print gl.lookupLabel(x,y), |
| 47 | |
| 48 | |
| 49 | |
| 50 | print "Statistics:" |
| 51 | print "Continuation | Black ( B wins / W wins ) | White (B wins / W wins) |" |
| 52 | for y in range(p.sizeY): |
| 53 | for x in range(p.sizeX): |
| 54 | if gl.lookupLabel(x,y) != '.': |
| 55 | cont = gl.lookupContinuation(x,y); |
| 56 | print " %c | %3d ( %3d / %3d ) | %3d ( %3d / %3d) |" % \ |
| 57 | (gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW) |
| 58 | print 'This search took %.2f seconds.' % (end - start) |
| 59 | |
| 60 | # p = Pattern(CENTER_PATTERN, 19, 2, 2, 'XO' + 'OX') |
| 61 | # start = time.time() |
| 62 | # gl.search(p) |
| 63 | # end = time.time() |
| 64 | # print '\n'.join(gl.currentEntriesAsStrings()) |
| 65 | # print gl.size(), 'games, ', gl.numHits(), 'hits.' |
| 66 | # print 'This search took %.2f seconds.' % (end - start) |
| 67 | |
| 68 | # print gl.currentEntryAsString(gl.size()-1) |
| 69 | # print gl.getCurrentProperty(gl.size()-1, 'PW'), gl.getSGF(gl.size()-1) |
| 70 | |
| 71 | # gl.reset() |
| 72 | # gl.tagsearch(HANDI_TAG) |
| 73 | # print gl.size(), 'handicap games' |
| 74 | |
| 75 | # print gl.plSize(), 'players in the whole database.' |
| 76 | # for i in range(100,110): |
| 77 | # print 'Player %d: %s' % (i, gl.plEntry(i)) |
| 78 | |
| 79 | for sig in ['cfcgjbbeckjc', 'qfqgjbreqkjc', 'aaaaaaaaaaaa', 'dfcnfmepgkjo', 'dfcn________', 'dfcn%']: |
| 80 | # SQL-wildcards are allowed: _ for a single character, % for an arbitrary number of characters |
| 81 | gl.reset() |
| 82 | gl.sigsearch(sig, 19) |
| 83 | print gl.size(), 'games with signature', sig |
| 84 | # gl.reset() |
| 85 | # print gl.currentEntryAsString(200) |
| 86 | # print 'signature of game 200: ', gl.getSignature(200) |
| 87 | |
| 88 | # check for duplicates |
| 89 | gl.reset() |
| 90 | i = gl.find_duplicates(19) |
| 91 | for j in range(i): |
| 92 | dupl = gl.retrieve_duplicates_VI(j) |
| 93 | for x in dupl: |
| 94 | print x, gl.currentEntryAsString(x) |
| 95 |
Note: See TracBrowser for help on using the browser.
