Changeset 101

Show
Ignore:
Timestamp:
03/20/04 18:14:04 (5 years ago)
Author:
ug
Message:

Misc. changes (Export position; Pattern, PatternList?)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/devel/aglPY.py

    r83 r101  
    2222 
    2323from searchPY import * 
     24from patternPY import * 
    2425 
    2526class abstractGameList: 
     
    548549 
    549550        print nextMoveVar 
    550         patternList = PatternList(pattern, fixedColorVar, nextMoveVar
     551        patternList = PatternList(pattern, fixedColorVar, nextMoveVar, self.boardsize
    551552 
    552553        if contLabels is None: 
  • 06/devel/algosPY.py

    r81 r101  
    2020##   The GNU GPL is also currently available at 
    2121##   http://www.gnu.org/copyleft/gpl.html 
     22 
     23import os 
     24from array import * 
     25from string import lower, join 
    2226 
    2327class Algorithm: # virtual 
     
    501505 
    502506                contList[m] = [] 
    503                 for x, y, color in patternList.get(m[0]).contList: 
    504                     contList[m].append((x+m[1][0], y+m[1][1], color)) 
     507                cL = patternList.get(m[0]).contList.split('/') 
     508                for t in cL: 
     509                    if t: contList[m].append((ord(t[0])+m[1][0], ord(t[1])+m[1][1], t[2])) 
    505510 
    506511                contListIndex[m] = 0 
     
    809814        for i in range(a0,a1+1): 
    810815            for j in range(b0,b1+1): 
    811                 if pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] in ['x', 'o', '*']: 
     816                if pattern.getFinal(i-pattern.anchors[0][0],j-pattern.anchors[0][1]) in ['x', 'o', '*']: 
    812817                    return 
    813                 elif pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] == 'X': 
     818                elif pattern.getFinal(i-pattern.anchors[0][0],j-pattern.anchors[0][1]) == 'X': 
    814819                    hashkey += hashTable.hash_value[(i,j)] 
    815820                    numOfStones += 1 
    816                 elif pattern.data[i-pattern.anchors[0][0]][j-pattern.anchors[0][1]] == 'O': 
     821                elif pattern.getFinal(i-pattern.anchors[0][0],j-pattern.anchors[0][1]) == 'O': 
    817822                    hashkey -= hashTable.hash_value[(i,j)] 
    818823                    numOfStones += 1 
     
    13301335                while i < p.sizeX and not currentUInterv.isEmpty(): 
    13311336 
    1332                     if p.data[i][j] == '*': 
     1337                    if p.getFinal(i,j) == '*': 
    13331338                        Bint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 
    13341339                        if Bint.data: cont.extend([(x,i,j) for x in [z[0] for z in Bint.data]]) 
    13351340                        Wint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'O')[1] 
    13361341                        if Wint.data: cont.extend([(x,i,j) for x in [z[0] for z in Wint.data]]) 
    1337                     elif p.data[i][j] == 'x': print 'oops' # FIXME 
    1338                     elif p.data[i][j] == 'o': print 'oops' # FIXME 
     1342                    elif p.getFinal(i,j) == 'x': print 'oops' # FIXME 
     1343                    elif p.getFinal(i,j) == 'o': print 'oops' # FIXME 
    13391344                         
    13401345                    else: 
    1341                         typeInt, nextInt = self.getUInterv(moves, moves1, index, i+a0, j+a1, p.data[i][j]
     1346                        typeInt, nextInt = self.getUInterv(moves, moves1, index, i+a0, j+a1, p.getFinal(i,j)
    13421347                         
    13431348                        if typeInt == -1: # nextInt = [0, MAXNOMOVES), so no need to take intersection 
     
    13461351                            currentUInterv = UIntervals() 
    13471352                        elif typeInt == 1: 
    1348                             if p.data[i][j] == '.' and cont[0][0] > nextInt.data[0][1]: 
     1353                            if p.getFinal(i,j) == '.' and cont[0][0] > nextInt.data[0][1]: 
    13491354                                Bi = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 
    13501355                                Wi = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'O')[1] 
     
    13731378                    if currentUInterv.isEmpty(): break 
    13741379                     
    1375                     if p.data[i][j] == 'X': 
     1380                    if p.getFinal(i,j) == 'X': 
    13761381                        Bint = nextInt 
    13771382                    else: 
    13781383                        Bint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 
    13791384                    if Bint.data: cont.extend([(x,i,j) for x in [z[0] for z in Bint.data]]) 
    1380                     if p.data[i][j] == 'O': 
     1385                    if p.getFinal(i,j) == 'O': 
    13811386                        Wint = nextInt 
    13821387                    else: 
     
    14521457              ALGO_HASH_FULL_CORNERS: Algo_hash_full_corners, 
    14531458              ALGO_INTERVALS: Algo_intervals} 
     1459 
     1460 
     1461# -------------------------------------------------------------------------- 
     1462 
     1463class hashTable: 
     1464 
     1465    def __init__(self, noOfGames, filename): 
     1466         self.data = array('l', [0]*(2*130*noOfGames)) 
     1467         self.currentCtr = -1 
     1468         self.dataIndex = 0 
     1469         self.filename = filename 
     1470          
     1471 
     1472    def newCtr(self, ctr): 
     1473        if ctr == self.currentCtr: 
     1474            while self.dataIndex > 0 and self.data[self.dataIndex-1] == ctr: 
     1475                self.dataIndex -= 2 
     1476        self.currentCtr = ctr 
     1477        self.currentCtrL = [] 
     1478 
     1479          
     1480    def append(self, i): 
     1481         
     1482        ctr = self.currentCtr 
     1483             
     1484        if i not in self.currentCtrL: 
     1485            if self.dataIndex >= len(self.data)-1: 
     1486                self.data.extend(array('l', [0]*1000)) 
     1487            self.data[self.dataIndex] = i 
     1488            self.dataIndex += 1 
     1489            self.data[self.dataIndex] = ctr 
     1490            self.dataIndex += 1 
     1491            self.currentCtrL.append(i) 
     1492 
     1493 
     1494    def swap(self, l, r): 
     1495        help1 = self.data[2*l] 
     1496        help2 = self.data[2*l+1] 
     1497        self.data[2*l] = self.data[2*r] 
     1498        self.data[2*l+1] = self.data[2*r+1] 
     1499        self.data[2*r] = help1 
     1500        self.data[2*r+1] = help2 
     1501 
     1502             
     1503    def sort(self): 
     1504 
     1505        l = 0 
     1506        r = self.dataIndex/2 - 1 
     1507        stack = [(l, r)] 
     1508 
     1509        while stack: 
     1510            if r > l: 
     1511                if r-l == 1: 
     1512                    if self.data[2*l] > self.data[2*r]: 
     1513                        self.swap(l,r) 
     1514                    l, r = stack.pop() 
     1515                else: 
     1516                    li = [(self.data[2*l], l), (self.data[2*r], r), (self.data[2*((r+l)/2)], (r+l)/2)] 
     1517                    li.sort() 
     1518 
     1519                    self.swap(li[1][1], r) 
     1520                    help1 = self.data[2*r] 
     1521 
     1522                    left = l 
     1523                    right = r-1 
     1524 
     1525                    while 1:  
     1526                        while self.data[2*left] < help1: left += 1 
     1527                        while self.data[2*right] > help1: right -= 1 
     1528 
     1529                        if right <= left: break 
     1530                             
     1531                        self.swap(left, right) 
     1532 
     1533                        left += 1 
     1534                        right -= 1 
     1535                             
     1536                    self.swap(left, r) 
     1537 
     1538                    if left-l > r-left: 
     1539                        stack.append((l, left-1)) 
     1540                        l = left+1 
     1541                    else: 
     1542                        stack.append((left+1, r)) 
     1543                        r = left-1                     
     1544            else: 
     1545                l, r = stack.pop() 
     1546 
     1547 
     1548    def sortedOutput(self, path): 
     1549        self.sort() 
     1550 
     1551        dataX = array('l') 
     1552        data1X = array('B') 
     1553 
     1554        currentCode = self.data[0] - 1  # != self.data[0] ! 
     1555        currentValues = [] 
     1556         
     1557        for i in xrange(self.dataIndex/2): 
     1558            if self.data[2*i] != currentCode: 
     1559                currentValues.sort() 
     1560                for v in currentValues: 
     1561                    data1X.append(v/256) 
     1562                    data1X.append(v%256) 
     1563                currentValues = [] 
     1564                currentCode = self.data[2*i] 
     1565                dataX.append(currentCode) 
     1566                dataX.append(len(data1X)) 
     1567 
     1568            currentValues.append(self.data[2*i+1]) 
     1569             
     1570        currentValues.sort() 
     1571        for v in currentValues: 
     1572            data1X.append(v/256) 
     1573            data1X.append(v%256) 
     1574             
     1575        file = open(os.path.join(path[0], self.filename + 'T' + path[1] + '.db'), 'wb') 
     1576        dataX.tofile(file) 
     1577        file.close() 
     1578        file = open(os.path.join(path[0], self.filename + path[1] + '.db'), 'wb') 
     1579        data1X.tofile(file) 
     1580        file.close() 
     1581             
     1582 
     1583    hash_value = { 
     1584        ( 0 ,  0 ):  9149491, ( 0 ,  1 ):  4143844, ( 0 ,  2 ):  8452911,  
     1585        ( 0 ,  3 ):  3100691, ( 0 ,  4 ):  3196613, ( 0 ,  5 ):  7210416,  
     1586        ( 0 ,  6 ):  6086509, ( 0 ,  7 ):  7957641, ( 0 ,  8 ):  131916,  
     1587        ( 0 ,  9 ):  6918136, ( 0 ,  10 ):  3016410, ( 0 ,  11 ):  3288711,  
     1588        ( 0 ,  12 ):  8539380, ( 0 ,  13 ):  758094, ( 0 ,  14 ):  7179238,  
     1589        ( 0 ,  15 ):  7718041, ( 0 ,  16 ):  5204153, ( 0 ,  17 ):  6711869,  
     1590        ( 0 ,  18 ):  8411491, ( 1 ,  0 ):  2434388, ( 1 ,  1 ):  1162683,  
     1591        ( 1 ,  2 ):  927102, ( 1 ,  3 ):  197419, ( 1 ,  4 ):  9435893,  
     1592        ( 1 ,  5 ):  2149216, ( 1 ,  6 ):  2967038, ( 1 ,  7 ):  5557593,  
     1593        ( 1 ,  8 ):  4044723, ( 1 ,  9 ):  4077413, ( 1 ,  10 ):  8810194,  
     1594        ( 1 ,  11 ):  7673830, ( 1 ,  12 ):  1290402, ( 1 ,  13 ):  704914,  
     1595        ( 1 ,  14 ):  2782252, ( 1 ,  15 ):  6972890, ( 1 ,  16 ):  2649162,  
     1596        ( 1 ,  17 ):  8444272, ( 1 ,  18 ):  5863711, ( 2 ,  0 ):  8701652,  
     1597        ( 2 ,  1 ):  9073146, ( 2 ,  2 ):  796709, ( 2 ,  3 ):  3071327,  
     1598        ( 2 ,  4 ):  81078, ( 2 ,  5 ):  413463, ( 2 ,  6 ):  9899215,  
     1599        ( 2 ,  7 ):  3900485, ( 2 ,  8 ):  4258038, ( 2 ,  9 ):  9853936,  
     1600        ( 2 ,  10 ):  5479882, ( 2 ,  11 ):  4613169, ( 2 ,  12 ):  7404562,  
     1601        ( 2 ,  13 ):  5251570, ( 2 ,  14 ):  1932628, ( 2 ,  15 ):  9394001,  
     1602        ( 2 ,  16 ):  6022071, ( 2 ,  17 ):  216105, ( 2 ,  18 ):  4278005,  
     1603        ( 3 ,  0 ):  7136853, ( 3 ,  1 ):  2500566, ( 3 ,  2 ):  4107671, 
     1604        ( 3 ,  3 ):  4081838, ( 3 ,  4 ):  1785699, ( 3 ,  5 ):  1424534,  
     1605        ( 3 ,  6 ):  3024969, ( 3 ,  7 ):  5734282, ( 3 ,  8 ):  4175470, 
     1606        ( 3 ,  9 ):  9404994, ( 3 ,  10 ):  8430123, ( 3 ,  11 ):  1255451, 
     1607        ( 3 ,  12 ):  5986866, ( 3 ,  13 ):  7055240, ( 3 ,  14 ):  6371620, 
     1608        ( 3 ,  15 ):  9283568, ( 3 ,  16 ):  7313682, ( 3 ,  17 ):  7717289,  
     1609        ( 3 ,  18 ):  2299204, ( 4 ,  0 ):  6500542, ( 4 ,  1 ):  1976702,  
     1610        ( 4 ,  2 ):  7553422, ( 4 ,  3 ):  5187929, ( 4 ,  4 ):  3201058,  
     1611        ( 4 ,  5 ):  2222174, ( 4 ,  6 ):  3817451, ( 4 ,  7 ):  7344416,  
     1612        ( 4 ,  8 ):  4960530, ( 4 ,  9 ):  6786163, ( 4 ,  10 ):  8006227, 
     1613        ( 4 ,  11 ):  442411, ( 4 ,  12 ):  4688575, ( 4 ,  13 ):  5012537, 
     1614        ( 4 ,  14 ):  3651243, ( 4 ,  15 ):  7062230, ( 4 ,  16 ):  6716660, 
     1615        ( 4 ,  17 ):  4891547, ( 4 ,  18 ):  5702153, ( 5 ,  0 ):  8827952, 
     1616        ( 5 ,  1 ):  7097129, ( 5 ,  2 ):  9410525, ( 5 ,  3 ):  1319909, 
     1617        ( 5 ,  4 ):  6697319, ( 5 ,  5 ):  6008737, ( 5 ,  6 ):  9209372, 
     1618        ( 5 ,  7 ):  1708104, ( 5 ,  8 ):  8930801, ( 5 ,  9 ):  3357765, 
     1619        ( 5 ,  10 ):  4158639, ( 5 ,  11 ):  8563534, ( 5 ,  12 ):  1000997, 
     1620        ( 5 ,  13 ):  4582316, ( 5 ,  14 ):  6276028, ( 5 ,  15 ):  9658685, 
     1621        ( 5 ,  16 ):  4453094, ( 5 ,  17 ):  9081939, ( 5 ,  18 ):  6565077, 
     1622        ( 6 ,  0 ):  3029400, ( 6 ,  1 ):  3036923, ( 6 ,  2 ):  2527385, 
     1623        ( 6 ,  3 ):  3663094, ( 6 ,  4 ):  1261450, ( 6 ,  5 ):  9321901, 
     1624        ( 6 ,  6 ):  4118265, ( 6 ,  7 ):  7506223, ( 6 ,  8 ):  8638174, 
     1625        ( 6 ,  9 ):  1830356, ( 6 ,  10 ):  9269438, ( 6 ,  11 ):  379190, 
     1626        ( 6 ,  12 ):  5190162, ( 6 ,  13 ):  4415341, ( 6 ,  14 ):  455343, 
     1627        ( 6 ,  15 ):  2706427, ( 6 ,  16 ):  374332, ( 6 ,  17 ):  4806453, 
     1628        ( 6 ,  18 ):  3940651, ( 7 ,  0 ):  7845245, ( 7 ,  1 ):  2132422, 
     1629        ( 7 ,  2 ):  313121, ( 7 ,  3 ):  1581806, ( 7 ,  4 ):  4042198, 
     1630        ( 7 ,  5 ):  4890562, ( 7 ,  6 ):  4352418, ( 7 ,  7 ):  5580773, 
     1631        ( 7 ,  8 ):  9938852, ( 7 ,  9 ):  6930891, ( 7 ,  10 ):  8376253, 
     1632        ( 7 ,  11 ):  5737628, ( 7 ,  12 ):  8471297, ( 7 ,  13 ):  1142249, 
     1633        ( 7 ,  14 ):  848865, ( 7 ,  15 ):  883348, ( 7 ,  16 ):  9812485, 
     1634        ( 7 ,  17 ):  5717034, ( 7 ,  18 ):  7432763, ( 8 ,  0 ):  2354745, 
     1635        ( 8 ,  1 ):  4069809, ( 8 ,  2 ):  9707233, ( 8 ,  3 ):  9588944, 
     1636        ( 8 ,  4 ):  3016914, ( 8 ,  5 ):  554095, ( 8 ,  6 ):  1638369, 
     1637        ( 8 ,  7 ):  9162618, ( 8 ,  8 ):  611584, ( 8 ,  9 ):  5407576, 
     1638        ( 8 ,  10 ):  3543495, ( 8 ,  11 ):  640558, ( 8 ,  12 ):  5662155, 
     1639        ( 8 ,  13 ):  3501725, ( 8 ,  14 ):  7560991, ( 8 ,  15 ):  3133362, 
     1640        ( 8 ,  16 ):  9084840, ( 8 ,  17 ):  6812692, ( 8 ,  18 ):  1594571, 
     1641        ( 9 ,  0 ):  9306451, ( 9 ,  1 ):  238482, ( 9 ,  2 ):  609444, 
     1642        ( 9 ,  3 ):  1700604, ( 9 ,  4 ):  3082475, ( 9 ,  5 ):  5804654, 
     1643        ( 9 ,  6 ):  6738079, ( 9 ,  7 ):  2956313, ( 9 ,  8 ):  3546729, 
     1644        ( 9 ,  9 ):  3491719, ( 9 ,  10 ):  1214856, ( 9 ,  11 ):  888594, 
     1645        ( 9 ,  12 ):  4911844, ( 9 ,  13 ):  315409, ( 9 ,  14 ):  983871, 
     1646        ( 9 ,  15 ):  5306260, ( 9 ,  16 ):  7005661, ( 9 ,  17 ):  4089903, 
     1647        ( 9 ,  18 ):  2599372, ( 10 ,  0 ):  7376553, ( 10 ,  1 ):  5249330, 
     1648        ( 10 ,  2 ):  1810656,( 10 ,  3 ):  765893, ( 10 ,  4 ):  2667106,  
     1649        ( 10 ,  5 ):  7557868, ( 10 ,  6 ):  9214606, ( 10 ,  7 ):  5347135, 
     1650        ( 10 ,  8 ):  6166404, ( 10 ,  9 ):  1400859, ( 10 ,  10 ):  1919455, 
     1651        ( 10 ,  11 ):  8828173, ( 10 ,  12 ):  6251839, ( 10 ,  13 ):  4004673,  
     1652        ( 10 ,  14 ):  2006377, ( 10 ,  15 ):  9013385, ( 10 ,  16 ):  6847406, 
     1653        ( 10 ,  17 ):  7019454, ( 10 ,  18 ):  1408057, ( 11 ,  0 ):  6063976, 
     1654        ( 11 ,  1 ):  4380230, ( 11 ,  2 ):  8034820, ( 11 ,  3 ):  1813992, 
     1655        ( 11 ,  4 ):  9773930, ( 11 ,  5 ):  2520157, ( 11 ,  6 ):  1124498, 
     1656        ( 11 ,  7 ):  9369992, ( 11 ,  8 ):  1110455, ( 11 ,  9 ):  1395733, 
     1657        ( 11 ,  10 ):  2582409, ( 11 ,  11 ):  1697715, ( 11 ,  12 ):  2368383, 
     1658        ( 11 ,  13 ):  745577, ( 11 ,  14 ):  8857326, ( 11 ,  15 ):  2179278, 
     1659        ( 11 ,  16 ):  4267432, ( 11 ,  17 ):  6892826, ( 11 ,  18 ):  6099809,  
     1660        ( 12 ,  0 ):  9973299, ( 12 ,  1 ):  5025252, ( 12 ,  2 ):  3632262, 
     1661        ( 12 ,  3 ):  3081860, ( 12 ,  4 ):  2809085, ( 12 ,  5 ):  1683429, 
     1662        ( 12 ,  6 ):  8369333, ( 12 ,  7 ):  7991628, ( 12 ,  8 ):  8365980, 
     1663        ( 12 ,  9 ):  465773, ( 12 ,  10 ):  1820067, ( 12 ,  11 ):  1457115, 
     1664        ( 12 ,  12 ):  2753928, ( 12 ,  13 ):  282741, ( 12 ,  14 ):  8546560, 
     1665        ( 12 ,  15 ):  6233640, ( 12 ,  16 ):  3079605, ( 12 ,  17 ):  4697340, 
     1666        ( 12 ,  18 ):  4846782, ( 13 ,  0 ):  5022954, ( 13 ,  1 ):  9875417, 
     1667        ( 13 ,  2 ):  9168302, ( 13 ,  3 ):  6618946, ( 13 ,  4 ):  6928618, 
     1668        ( 13 ,  5 ):  8503198, ( 13 ,  6 ):  5052403, ( 13 ,  7 ):  2078686, 
     1669        ( 13 ,  8 ):  2995926, ( 13 ,  9 ):  2194938, ( 13 ,  10 ):  820379, 
     1670        ( 13 ,  11 ):  7612996, ( 13 ,  12 ):  1375726, ( 13 ,  13 ):  8614873, 
     1671        ( 13 ,  14 ):  5945335, ( 13 ,  15 ):  4672767, ( 13 ,  16 ):  3036307, 
     1672        ( 13 ,  17 ):  6840821, ( 13 ,  18 ):  3921566, ( 14 ,  0 ):  9316769, 
     1673        ( 14 ,  1 ):  5099779, ( 14 ,  2 ):  1957262, ( 14 ,  3 ):  82550, 
     1674        ( 14 ,  4 ):  8061649, ( 14 ,  5 ):  5685904, ( 14 ,  6 ):  7357125, 
     1675        ( 14 ,  7 ):  3158126, ( 14 ,  8 ):  9681206, ( 14 ,  9 ):  9939320, 
     1676        ( 14 ,  10 ):  1416538, ( 14 ,  11 ):  9680390, ( 14 ,  12 ):  4083051, 
     1677        ( 14 ,  13 ):  1970772, ( 14 ,  14 ):  8454640, ( 14 ,  15 ):  8443104, 
     1678        ( 14 ,  16 ):  4061492, ( 14 ,  17 ):  6778512, ( 14 ,  18 ):  5077238, 
     1679        ( 15 ,  0 ):  5263977, ( 15 ,  1 ):  6837884, ( 15 ,  2 ):  4767983, 
     1680        ( 15 ,  3 ):  1402914, ( 15 ,  4 ):  1063494, ( 15 ,  5 ):  8805596, 
     1681        ( 15 ,  6 ):  2899665, ( 15 ,  7 ):  5717105, ( 15 ,  8 ):  5032108, 
     1682        ( 15 ,  9 ):  7482452, ( 15 ,  10 ):  95784, ( 15 ,  11 ):  6793965, 
     1683        ( 15 ,  12 ):  7138721, ( 15 ,  13 ):  7934664, ( 15 ,  14 ):  6505269, 
     1684        ( 15 ,  15 ):  6678380, ( 15 ,  16 ):  2901608, ( 15 ,  17 ):  5665651, 
     1685        ( 15 ,  18 ):  3599459, ( 16 ,  0 ):  5070383, ( 16 ,  1 ):  1714950, 
     1686        ( 16 ,  2 ):  8047561, ( 16 ,  3 ):  8205607, ( 16 ,  4 ):  67238, 
     1687        ( 16 ,  5 ):  2156761, ( 16 ,  6 ):  5827686, ( 16 ,  7 ):  1391658, 
     1688        ( 16 ,  8 ):  3591582, ( 16 ,  9 ):  7018330, ( 16 ,  10 ):  9232127, 
     1689        ( 16 ,  11 ):  8849431, ( 16 ,  12 ):  820043, ( 16 ,  13 ):  7847325,  
     1690        ( 16 ,  14 ):  3583231, ( 16 ,  15 ):  2966011, ( 16 ,  16 ):  5159425, 
     1691        ( 16 ,  17 ):  4855713, ( 16 ,  18 ):  1079091, ( 17 ,  0 ):  2870996,  
     1692        ( 17 ,  1 ):  5867619, ( 17 ,  2 ):  9327733, ( 17 ,  3 ):  4398712, 
     1693        ( 17 ,  4 ):  9371591, ( 17 ,  5 ):  2182067, ( 17 ,  6 ):  2409473, 
     1694        ( 17 ,  7 ):  709735, ( 17 ,  8 ):  4862464, ( 17 ,  9 ):  8833884, 
     1695        ( 17 ,  10 ):  1260720, ( 17 ,  11 ):  37637, ( 17 ,  12 ):  2367746, 
     1696        ( 17 ,  13 ):  8087960, ( 17 ,  14 ):  4198525, ( 17 ,  15 ):  82482,  
     1697        ( 17 ,  16 ):  4389571, ( 17 ,  17 ):  787391, ( 17 ,  18 ):  8032185, 
     1698        ( 18 ,  0 ):  2095647, ( 18 ,  1 ):  5448853, ( 18 ,  2 ):  850526, 
     1699        ( 18 ,  3 ):  2278124, ( 18 ,  4 ):  6280764, ( 18 ,  5 ):  4617893, 
     1700        ( 18 ,  6 ):  2879123, ( 18 ,  7 ):  806861, ( 18 ,  8 ):  4007840, 
     1701        ( 18 ,  9 ):  9545335, ( 18 ,  10 ):  9072999, ( 18 ,  11 ):  1446181, 
     1702        ( 18 ,  12 ):  7946775, ( 18 ,  13 ):  6118313, ( 18 ,  14 ):  5073149, 
     1703        ( 18 ,  15 ):  8222792, ( 18 ,  16 ):  4448444, ( 18 ,  17 ):  4579004, 
     1704        ( 18 ,  18 ):  5179082 
     1705        } 
     1706         
  • 06/devel/kombilo.py

    r94 r101  
    6363from searchPY import * 
    6464from aglPY import * 
     65from algosPY import * 
    6566 
    6667try: 
     
    15961597        for i in range(sel[0][1], sel[1][1]+1): 
    15971598            for j in range(sel[0][0], sel[1][0]+1): 
    1598                 if not self.master.board.status.has_key((j,i)): d[(i-1,j-1)] = '.' 
    1599                 elif self.master.board.status[(j,i)] == 'black': d[(i-1,j-1)] = 'X' 
     1599                # FIXME j,i versus i,j ?!?!?! 
     1600                if self.master.board.getStatus(j,i)==' ': d[(i-1,j-1)] = '.' 
     1601                elif self.master.board.getStatus(j,i) == 'black': d[(i-1,j-1)] = 'X' 
    16001602                else:                                    d[(i-1,j-1)] = 'O' 
    16011603                if self.master.board.wildcards.has_key((j,i)): 
     
    18421844 
    18431845        boardData = self.board.snapshot() 
    1844         boardData2 = (copy(self.board.status), copy(self.board.wildcards), self.board.selection) 
     1846        boardData2 = (None, None, None) # FIXME, was (copy(self.board.status), copy(self.board.wildcards), self.board.selection) 
    18451847 
    18461848        self.progBar.clear() 
     
    18581860 
    18591861        if self.currentInitialPattern: 
    1860             d = {} 
     1862            d = [] 
    18611863            for i in range(self.sel[0][0], self.sel[1][0]+1): 
    18621864                for j in range(self.sel[0][1], self.sel[1][1]+1): 
    1863                     d[(i, j)] = self.currentInitialPattern[(i, j)] 
    1864  
    1865             self.currentSearchPattern = Pattern(anchors, d, self.currentContList, self.moveOne) 
     1865                    d.append(self.currentInitialPattern[i+self.boardsize*j]) 
    18661866        else: 
    18671867            d = self.getPatternFromBoard(self.sel) 
    1868             self.currentSearchPattern = Pattern(anchors, d) 
    1869  
     1868        cls = [] 
     1869        for c in self.currentContList: 
     1870            cls.append(chr(c[0]-self.sel[0][0]) + chr(c[1]-self.sel[0][1]) + c[2] + '/') 
     1871        contListString = join(cls, '') 
     1872        self.currentSearchPattern = Pattern(anchors[0][0], anchors[0][1], anchors[1][0], anchors[1][1], 
     1873                                            self.sel[1][0]-self.sel[0][0]+1, self.sel[1][1]-self.sel[0][1]+1, 
     1874                                            join(d, ''), contListString, len(self.currentContList), self.moveOne) 
     1875         
    18701876        self.continuations = {} 
    18711877        self.statistics = {} 
     
    19371943        results = [join(l.results, '|%') for l in self.gamelist.DBlist[`self.boardsize`]] 
    19381944        cursorSn = [self.cursor, self.cursor.currentGame, self.cursor.currentN.pathToNode()] 
    1939         self.prevSearches.append([boardData, games, results, copy(self.continuations), 
    1940                                self.noMatches, self.noSwitched, self.Bwins, self.Wwins, 
    1941                                self.modeVar.get(), self.fixedColorVar.get(), self.fixedAnchorVar.get(), 
    1942                                self.moveLimit.get(), self.nextMoveVar.get(), cursorSn], boardData2) 
     1945 
     1946 
     1947        # see FIXME above (boardData = ...) 
     1948        #self.prevSearches.append([boardData, games, results, copy(self.continuations), 
     1949        #                       self.noMatches, self.noSwitched, self.Bwins, self.Wwins, 
     1950        #                       self.modeVar.get(), self.fixedColorVar.get(), self.fixedAnchorVar.get(), 
     1951        #                       self.moveLimit.get(), self.nextMoveVar.get(), cursorSn], boardData2) 
    19431952 
    19441953        self.configButtons(NORMAL) 
     
    24682477    def getPatternFromBoard(self, region): 
    24692478         
    2470         d = {} 
     2479        d = [] 
    24712480 
    24722481        for i in range(region[0][0], region[1][0]+1): 
    24732482            for j in range(region[0][1], region[1][1]+1): 
    2474                 if not self.board.status.has_key((i,j)):  d[(i,j)] = '.' 
    2475                 elif self.board.status[(i,j)] == 'black': d[(i,j)] = 'X' 
    2476                 else:                                     d[(i,j)] = 'O' 
    24772483                if self.board.wildcards.has_key((i,j)): 
    2478                     d[(i,j)] = wildcolor_to_char(self.board.wildcards[(i,j)]) 
     2484                    d.append(wildcolor_to_char(self.board.wildcards[(i,j)])) 
     2485                else: 
     2486                    if self.board.getStatus(i,j) == ' ':   d.append('.') 
     2487                    elif self.board.getStatus(i,j) == 'B': d.append('X') 
     2488                    else:                                  d.append('O') 
     2489 
    24792490        return d 
    24802491     
     
    25042515            anchors = [(1, 1), (self.boardsize-2 -self.sel[1][0]+self.sel[0][0], 
    25052516                                self.boardsize-2 -self.sel[1][1]+self.sel[0][1])] 
    2506  
     2517        anchors.sort() # FIXME: is this necessary? 
    25072518        return anchors 
    25082519 
     
    25222533            self.board.delMSLabels() 
    25232534            self.currentInitialPattern = None 
    2524             self.currentContList = None 
     2535            self.currentContList = [] 
    25252536 
    25262537 
     
    25652576        t = [] 
    25662577 
    2567         for i in range(19): l.append(['. ']*19) 
    2568  
    2569         for i in range(1,20): 
    2570             for j in range(1,20): 
    2571                 if not self.board.status.has_key((j,i)): pass 
    2572                 elif self.board.status[(j,i)] == 'black': l[i-1][j-1] = 'X ' 
    2573                 else:                                    l[i-1][j-1] = 'O ' 
    2574                 if self.board.wildcards.has_key((j,i)): l[i-1][j-1] = '* ' 
    2575  
     2578        for i in range(self.boardsize): 
     2579            for j in range(self.boardsize): 
     2580                if self.board.getStatus(j,i) == ' ':    l.append('. ') 
     2581                elif self.board.getStatus(j,i) == 'B':  l.append('X ') 
     2582                else:                                   l.append('O ') 
     2583                if self.board.wildcards.has_key((j,i)): l.append('* ') 
     2584                # FIXME: colored wildcards! 
     2585             
    25762586        # mark hoshis with ,'s 
    25772587 
    2578         for i in range(3): 
    2579             for j in range(3): 
    2580                 ii = 3 + 6*i  
    2581                 jj = 3 + 6*j  
    2582                 if l[ii][jj] == '. ': l[ii][jj] = ', ' 
    2583  
     2588        if self.boardsize == 19: 
     2589            for i in range(3): 
     2590                for j in range(3): 
     2591                    ii = 3 + 6*i  
     2592                    jj = 3 + 6*j  
     2593                    if l[ii*self.boardsize+jj] == '. ': l[ii*self.boardsize+jj] = ', ' 
     2594        elif self.boardsize == 13: 
     2595            for i in range(3): 
     2596                for j in range(3): 
     2597                    ii = 3 + 3*i  
     2598                    jj = 3 + 3*j  
     2599                    if l[ii*self.boardsize+jj] == '. ': l[ii*self.boardsize+jj] = ', ' 
     2600        elif self.boardsize == 9: 
     2601            if l[4*self.boardsize+4] == '. ': l[4*self.boardsize+4] = ', ' 
     2602             
    25842603        remarks = [] 
    25852604        nextMove = 'B' 
     
    26042623                if not pos: continue 
    26052624             
    2606                 if l[pos[0]][pos[1]] in ['. ', ', ']: l[pos[0]][pos[1]] = ii 
    2607                 elif l[pos[0]][pos[1]] in [`i`+' ' for i in range(10)]: 
    2608                     remarks.append(ii + 'at ' + l[pos[0]][pos[1]] + '\n') 
    2609                 elif l[pos[0]][pos[1]] in ['X ', 'O ']: 
     2625                if l[pos[0]*self.boardsize+pos[1]] in ['. ', ', ']: l[pos[0]*self.boardsize+pos[1]] = ii 
     2626                elif l[pos[0]*self.boardsize+pos[1]] in [`i`+' ' for i in range(10)]: 
     2627                    remarks.append(ii + 'at ' + l[pos[0]*self.boardsize+pos[1]] + '\n') 
     2628                elif l[pos[0]*self.boardsize+pos[1]] in ['X ', 'O ']: 
    26102629                    remarks.append(ii + 'at ' + 'ABCDEFGHJKLMNOPQRST'[pos[1]] + `pos[0]+1` + '\n') 
    26112630 
     
    26142633        if not exportMode.get(): 
    26152634            for i in range(self.boardsize): 
    2616                 l[i].insert(0, '%2d  ' % (self.boardsize-i)) 
    2617  
    2618             l.insert(0, '') 
    2619             l.insert(0, '    A B C D E F G H J K L M N O P Q R S T') # FIXME boardsize 
     2635                l.insert((self.boardsize-i-1)*self.boardsize, '\n%2d  ' % (i+1)) 
     2636 
     2637            l.insert(0, '    A B C D E F G H J K L M N O P Q R S T'[:4+2*self.boardsize] + '\n')  
    26202638 
    26212639            if n: 
     
    26232641                elif nextMove == 'W': remarks.append('White = 1\n') 
    26242642        else: 
    2625             for i in range(19): 
    2626                 l[i].insert(0, '$$ | ') 
    2627                 l[i].append('|') 
    2628          
    2629             l.insert(0, '$$  ---------------------------------------') 
    2630             l.insert(0, '$$' + nextMove) 
    2631             l.append('$$  ---------------------------------------') 
    2632  
    2633         for line in l: 
    2634             t.append(join(line, '') + '\n') 
     2643            for i in range(self.boardsize-1): 
     2644                l.insert((self.boardsize-i-1)*self.boardsize, '|\n$$ | ') 
     2645            l.insert(0, '\n$$' + nextMove + '\n$$  '  + '-'*(2*self.boardsize+1) + '\n$$ | ') 
     2646            l.append('|\n$$  '  + '-'*(2*self.boardsize+1) + '\n') 
     2647        t.append(join(l, '') + '\n') 
    26352648 
    26362649        t.append('\n') 
     
    39553968        self.currentSearchPattern = None 
    39563969        self.currentInitialPattern = None 
    3957         self.currentContList = None 
     3970        self.currentContList = [] 
    39583971        self.moveOne = 'B' 
    39593972        self.balloonHelp() 
  • 06/devel/patternPY.py

    r83 r101  
    2121##   http://www.gnu.org/copyleft/gpl.html 
    2222 
     23from string import join 
     24from array import * 
    2325 
    2426class Pattern: 
     
    3941        if self.moveOne != p.moveOne: return 1 
    4042        for i in range(self.sizeX): 
    41             if self.initialData[i] != p.initialData[i]: return 1 
     43            if self.initialPos[i] != p.initialPos[i]: return 1 
    4244        if self.contList != p.contList: return 1 
    4345        return 0 
     
    7476        if self.moveOne == 'X': self.moveTwo = 'O' 
    7577        else: self.moveTwo = 'X' 
    76          
     78 
     79        self.left = left 
     80        self.top = top 
     81        self.right = right 
     82        self.bottom = bottom 
    7783        self.anchors = [(left, top), (right, bottom)] 
    78         self.anchors.sort()               # important for __cmp__ 
     84        # self.anchors.sort()               # important for __cmp__ (but already sorted ...) 
    7985 
    8086        self.sizeX = sizeX 
     
    8490 
    8591        helpFinalPos = list(initialPos) 
     92 
    8693        for t in contList.split('/'): 
    87             helpFinalPos[ord(t[0]) + sizeX*ord(t[1])] = BW2XO(t[2]) # ignore captures ... 
     94            if t: 
     95                print ord(t[0]), ord(t[1]), t[2] 
     96                helpFinalPos[ord(t[0]) + sizeX*ord(t[1])] = self.BW2XO(t[2]) # ignore captures ... 
    8897 
    8998        self.finalPos = join(helpFinalPos, '') 
    9099 
    91         self.contList = contList # [(x-start[0], y-start[1], self.BW2XO(co)) for x, y, co in contList] 
     100        self.contList = contList 
    92101        self.lenContList = lenContList 
    93102         
     
    153162    def invertColor(self,co): 
    154163        try: 
    155             return {'X': 'O', 'x': 'o', 'O': 'X', 'o': 'x', '.': '.', '*': '*'}[co] 
     164            return {'X': 'O', 'x': 'o', 'O': 'X', 'o': 'x', '.': '.', '*': '*', 'B':'W', 'W':'B'}[co] 
    156165        except: 
    157             print 'oops' # FIXME 
     166            print 'oops invertColor', co # FIXME 
    158167            return co 
    159168 
     
    195204            for i in range(self.pattern.sizeX): 
    196205                for j in range(self.pattern.sizeY): 
    197                     newPd[f(i,j)] = self.pattern.getInitial(i, j) 
    198  
    199             newContList = [f(i,j)+(co,) for i,j,co in self.pattern.contList] 
    200             pNew = Pattern(newAnchors, newPd, newContList, self.pattern.moveOne) 
     206                    newPd[f(i,j, self.pattern.sizeX-1, self.pattern.sizeY-1)] = self.pattern.getInitial(i, j) 
     207 
     208            print newPd 
     209            cl = self.pattern.contList.split('/') 
     210            for c in cl: 
     211                if c: print ord(c[0]), ord(c[1]), c[2] 
     212            ncl =[chr(f(ord(t[0]),ord(t[1]),self.pattern.sizeX-1,self.pattern.sizeY-1)[0]) +\ 
     213                  chr(f(ord(t[0]),ord(t[1]),self.pattern.sizeX-1,self.pattern.sizeY-1)[1]) + t[2] + '/'\ 
     214                  for t in cl if t] 
     215            for c in ncl: 
     216                if c: print ord(c[0]), ord(c[1]), c[2] 
     217            newContList = join(ncl, '') 
     218 
     219            newSizeL = [ f(0,0,1,1), f(0,1,1,1) ] 
     220            newSizeL.sort() 
     221            if newSizeL[1][0] == newSizeL[0][0]: 
     222                newSizeX = self.pattern.sizeX 
     223                newSizeY = self.pattern.sizeY 
     224            else: 
     225                newSizeX = self.pattern.sizeY 
     226                newSizeY = self.pattern.sizeX 
     227 
     228            print self.pattern.sizeX, self.pattern.sizeY, newSizeX, newSizeY 
     229 
     230            npdl = [] 
     231            for i in range(newSizeX): 
     232                for j in range(newSizeY): 
     233                    npdl.append(newPd[(i,j)]) 
     234            newPdString = join(npdl, '') 
     235                               
     236            pNew = Pattern(newAnchors[0][0], newAnchors[0][1], newAnchors[1][0], newAnchors[1][1], 
     237                           newSizeX, newSizeY, 
     238                           newPdString, newContList, self.pattern.lenContList, self.pattern.moveOne) 
    201239            pNew.flip = ii 
    202240 
     
    208246                for i in range(self.pattern.sizeX): 
    209247                    for j in range(self.pattern.sizeY): 
    210                         newPd1[f(i,j)] = self.invertColor(self.pattern.getInitial(i, j)) 
     248                        newPd1[f(i,j, self.pattern.sizeX-1, self.pattern.sizeY-1)] \ 
     249                                      = self.invertColor(self.pattern.getInitial(i, j)) 
     250                npdl = [] 
     251                for i in range(newSizeX): 
     252                    for j in range(newSizeY): 
     253                        npdl.append(newPd[(i,j)]) 
     254                newPd1String = join(npdl, '') 
    211255                         
    212                 newContList1 = [f(i,j)+(self.invertColor(co),) for i,j,co in self.pattern.contList] 
    213                 pNew1 = Pattern(newAnchors, newPd1, newContList1, self.pattern.moveTwo) 
     256                newContList1 = join([t[0]+t[1]+self.invertColor(t[2])+'/' for t in ncl], '') 
     257                 
     258                pNew1 = Pattern(newAnchors[0][0], newAnchors[0][1], newAnchors[1][0], newAnchors[1][1], 
     259                                newSizeX, newSizeY, 
     260                                newPd1String, newContList1, self.pattern.lenContList, self.pattern.moveTwo) 
    214261                pNew1.flip = ii 
    215262                pNew1.colorSwitch = 1 
     
    273320                            winner): 
    274321 
    275         xx, yy = Pattern.flips[PatternInvFlip(self.data[index].flip)](x, y
     322        xx, yy = Pattern.flips[PatternInvFlip(self.data[index].flip)](x, y, self.boardsize-1, self.boardsize-1
    276323                                 
    277         XX1, YY1 = Pattern.flips[PatternInvFlip(self.data[index].flip)](Xint[0], Yint[0]) 
    278         XX2, YY2 = Pattern.flips[PatternInvFlip(self.data[index].flip)](Xint[1]-1, Yint[1]-1) 
     324        XX1, YY1 = Pattern.flips[PatternInvFlip(self.data[index].flip)](Xint[0], Yint[0], 
     325                                                                        self.boardsize-1, self.boardsize-1) 
     326        XX2, YY2 = Pattern.flips[PatternInvFlip(self.data[index].flip)](Xint[1]-1, Yint[1]-1, 
     327                                                                        self.boardsize-1, self.boardsize-1) 
    279328        XX = min(XX1, XX2) 
    280329        YY = min(YY1, YY2) 
     
    304353                    yy += YY 
    305354 
    306                     xx, yy = Pattern.flips[self.symmetries[-1]](xx, yy
     355                    xx, yy = Pattern.flips[self.symmetries[-1]](xx, yy, self.boardsize-1, self.boardsize-1
    307356                                     
    308                     XX1, YY1 = Pattern.flips[self.symmetries[-1]](XX1, YY1
    309                     XX2, YY2 = Pattern.flips[self.symmetries[-1]](XX2, YY2
     357                    XX1, YY1 = Pattern.flips[self.symmetries[-1]](XX1, YY1,self.boardsize-1, self.boardsize-1
     358                    XX2, YY2 = Pattern.flips[self.symmetries[-1]](XX2, YY2,self.boardsize-1, self.boardsize-1
    310359 
    311360                    XX = min(XX1, XX2) 
  • 06/devel/searchPY.py

    r83 r101  
    3434    from abstractBoardPY import * 
    3535 
     36from patternPY import * 
     37from algosPY import * 
    3638 
    3739try: 
     
    379381                    while len(signature2) < 6: signature2 += '??' 
    380382                    signature = signature1 + signature2 
    381                     signature = symmetrizeSig(signature
     383                    signature = symmetrizeSig(signature, self.boardsize
    382384 
    383385                    # Now check for duplicates; first in the currently processed database, 
     
    432434                    siglist.append(signature) 
    433435 
    434                 except:  
     436                except ImportError:  
    435437                    messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n') 
    436438                    signature = '????????????' 
     
    577579 
    578580 
    579 class hashTable: 
    580  
    581     def __init__(self, noOfGames, filename): 
    582          self.data = array('l', [0]*(2*130*noOfGames)) 
    583          self.currentCtr = -1 
    584          self.dataIndex = 0 
    585          self.filename = filename 
    586           
    587  
    588     def newCtr(self, ctr): 
    589         if ctr == self.currentCtr: 
    590             while self.dataIndex > 0 and self.data[self.dataIndex-1] == ctr: 
    591                 self.dataIndex -= 2 
    592         self.currentCtr = ctr 
    593         self.currentCtrL = [] 
    594  
    595           
    596     def append(self, i): 
    597          
    598         ctr = self.currentCtr 
    599              
    600         if i not in self.currentCtrL: 
    601             if self.dataIndex >= len(self.data)-1: 
    602                 self.data.extend(array('l', [0]*1000)) 
    603             self.data[self.dataIndex] = i 
    604             self.dataIndex += 1 
    605             self.data[self.dataIndex] = ctr 
    606             self.dataIndex += 1 
    607             self.currentCtrL.append(i) 
    608  
    609  
    610     def swap(self, l, r): 
    611         help1 = self.data[2*l] 
    612         help2 = self.data[2*l+1] 
    613         self.data[2*l] = self.data[2*r] 
    614         self.data[2*l+1] = self.data[2*r+1] 
    615         self.data[2*r] = help1 
    616         self.data[2*r+1] = help2 
    617  
    618              
    619     def sort(self): 
    620  
    621         l = 0 
    622         r = self.dataIndex/2 - 1 
    623         stack = [(l, r)] 
    624  
    625         while stack: 
    626             if r > l: 
    627                 if r-l == 1: 
    628                     if self.data[2*l] > self.data[2*r]: 
    629                         self.swap(l,r) 
    630                     l, r = stack.pop() 
    631                 else: 
    632                     li = [(self.data[2*l], l), (self.data[2*r], r), (self.data[2*((r+l)/2)], (r+l)/2)] 
    633                     li.sort() 
    634  
    635                     self.swap(li[1][1], r) 
    636                     help1 = self.data[2*r] 
    637  
    638                     left = l 
    639                     right = r-1 
    640  
    641                     while 1:  
    642                         while self.data[2*left] < help1: left += 1 
    643                         while self.data[2*right] > help1: right -= 1 
    644  
    645                         if right <= left: break 
    646                              
    647                         self.swap(left, right) 
    648  
    649                         left += 1 
    650                         right -= 1 
    651                              
    652                     self.swap(left, r) 
    653  
    654                     if left-l > r-left: 
    655                         stack.append((l, left-1)) 
    656                         l = left+1 
    657                     else: 
    658                         stack.append((left+1, r)) 
    659                         r = left-1                     
    660             else: 
    661                 l, r = stack.pop() 
    662  
    663  
    664     def sortedOutput(self, path): 
    665         self.sort() 
    666  
    667         dataX = array('l') 
    668         data1X = array('B') 
    669  
    670         currentCode = self.data[0] - 1  # != self.data[0] ! 
    671         curre