root/06/libkombilo-branches/hash_center/test_hash_center2.py

Revision 243, 3.9 kB (checked in by ug, 1 year ago)

Fixed bug w.r.t. pattern anchors in hash_center search. Further small changes.

  • Property svn:executable set to *
Line 
1 #! /usr/bin/env python2.4
2
3 import os
4 import sys
5 import time
6 from libkombilo import *
7
8 def timed_search(gl, p):
9     gl.reset()
10     so = SearchOptions()
11     so.algos = ALGO_FINALPOS | ALGO_MOVELIST
12     start = time.time()
13     gl.search(p, so)
14     nohash_time = time.time() - start
15     nh_result = []
16     nh_result.append('\n'.join(gl.currentEntriesAsStrings()))
17     nh_result.append(str(gl.size()) + ' games, ' + str(gl.numHits()) + ' hits.')
18     nh_result.append(p.printPattern())
19     for y in range(p.sizeY):
20         for x in range(p.sizeX):
21             nh_result.append(gl.lookupLabel(x,y))
22         nh_result.append('\n')
23
24     nh_result.append('\n')
25     for y in range(p.sizeY):
26         for x in range(p.sizeX):
27             if gl.lookupLabel(x,y) != '.':
28                 cont = gl.lookupContinuation(x,y);
29                 nh_result.append("      %c      |   %3d (    %3d /    %3d ) |   %3d (   %3d /    %3d) |" % \
30                       (gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW))
31
32     gl.reset()
33     so.algos = ALGO_FINALPOS | ALGO_MOVELIST | ALGO_HASH_FULL | ALGO_HASH_CORNER | ALGO_HASH_CENTER
34     start = time.time()
35     gl.search(p, so)
36     hash_time = time.time() - start
37     h_result = []
38     h_result.append('\n'.join(gl.currentEntriesAsStrings()))
39     h_result.append(str(gl.size()) + ' games, ' + str(gl.numHits()) + ' hits.')
40     h_result.append(p.printPattern())
41     for y in range(p.sizeY):
42         for x in range(p.sizeX):
43             h_result.append(gl.lookupLabel(x,y))
44         h_result.append('\n')
45
46     h_result.append('\n')
47     for y in range(p.sizeY):
48         for x in range(p.sizeX):
49             if gl.lookupLabel(x,y) != '.':
50                 cont = gl.lookupContinuation(x,y);
51                 h_result.append("      %c      |   %3d (    %3d /    %3d ) |   %3d (   %3d /    %3d) |" % \
52                       (gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW))
53
54     if ''.join(nh_result) != ''.join(h_result):
55         out1 = open('nh_result', 'ab')
56         out1.write(''.join(nh_result))
57         out1.close()
58         out2 = open('h_result', 'ab')
59         out2.write(''.join(h_result))
60         out1.close()
61     return (nohash_time, hash_time)
62
63 # --------------------------------------------------------------------------------------------
64
65 pl = [
66        Pattern(CORNER_NW_PATTERN, 19, 7, 7,
67       '''.......
68          ....X..
69          ...XO..
70          ..XO...
71          ..XO...
72          .......
73          .......'''.replace(' ','').replace('\n','')),
74        Pattern(CORNER_NW_PATTERN, 19, 7, 7,
75       '''.......
76          .......
77          ..X..X.
78          .O.X...
79          .......
80          ..O....
81          .......'''.replace(' ','').replace('\n','')),
82        Pattern(CORNER_NW_PATTERN, 19, 7, 7,
83       '''.......
84          .......
85          ...O...
86          ...X...
87          .......
88          ..X....
89          .......'''.replace(' ','').replace('\n','')),
90        Pattern(CORNER_NW_PATTERN, 19, 7, 7,
91       '''.......
92          .......
93          .......
94          ...X.X.
95          .......
96          ...O.O.
97          .......'''.replace(' ','').replace('\n','')),
98        Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................'),
99        Pattern(CENTER_PATTERN, 19, 3, 3, '.X.XXXXOX'),
100        Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO'),
101        Pattern(CENTER_PATTERN, 19, 4, 5, '.X..' + '.OX.' + '.OX.' + '.OX.' + 'OXO.'),
102        Pattern(CENTER_PATTERN, 19, 5, 4, '..XOO'+ '...XX'+ '.....'+ '..X..'),
103        Pattern(CENTER_PATTERN, 19, 5, 4, "...O." + "....." + ".XOO." + "..OXO"),
104      ]
105
106 start = time.time()
107 gl = GameList(sys.argv[1] + '.db')
108 end = time.time()
109 print gl.size(), 'games in the database'
110
111 for pattern in pl:
112     print pattern.printPattern()
113     print timed_search(gl, pattern)
114     print 'num hits:', gl.num_hits
115     print '..................................................................'
116     print
117
Note: See TracBrowser for help on using the browser.