Changeset 101
- Timestamp:
- 03/20/04 18:14:04 (5 years ago)
- Files:
-
- 06/devel/aglPY.py (modified) (2 diffs)
- 06/devel/algosPY.py (modified) (7 diffs)
- 06/devel/kombilo.py (modified) (13 diffs)
- 06/devel/patternPY.py (modified) (9 diffs)
- 06/devel/searchPY.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/devel/aglPY.py
r83 r101 22 22 23 23 from searchPY import * 24 from patternPY import * 24 25 25 26 class abstractGameList: … … 548 549 549 550 print nextMoveVar 550 patternList = PatternList(pattern, fixedColorVar, nextMoveVar )551 patternList = PatternList(pattern, fixedColorVar, nextMoveVar, self.boardsize) 551 552 552 553 if contLabels is None: 06/devel/algosPY.py
r81 r101 20 20 ## The GNU GPL is also currently available at 21 21 ## http://www.gnu.org/copyleft/gpl.html 22 23 import os 24 from array import * 25 from string import lower, join 22 26 23 27 class Algorithm: # virtual … … 501 505 502 506 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])) 505 510 506 511 contListIndex[m] = 0 … … 809 814 for i in range(a0,a1+1): 810 815 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', '*']: 812 817 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': 814 819 hashkey += hashTable.hash_value[(i,j)] 815 820 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': 817 822 hashkey -= hashTable.hash_value[(i,j)] 818 823 numOfStones += 1 … … 1330 1335 while i < p.sizeX and not currentUInterv.isEmpty(): 1331 1336 1332 if p. data[i][j]== '*':1337 if p.getFinal(i,j) == '*': 1333 1338 Bint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 1334 1339 if Bint.data: cont.extend([(x,i,j) for x in [z[0] for z in Bint.data]]) 1335 1340 Wint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'O')[1] 1336 1341 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' # FIXME1338 elif p. data[i][j]== 'o': print 'oops' # FIXME1342 elif p.getFinal(i,j) == 'x': print 'oops' # FIXME 1343 elif p.getFinal(i,j) == 'o': print 'oops' # FIXME 1339 1344 1340 1345 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)) 1342 1347 1343 1348 if typeInt == -1: # nextInt = [0, MAXNOMOVES), so no need to take intersection … … 1346 1351 currentUInterv = UIntervals() 1347 1352 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]: 1349 1354 Bi = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 1350 1355 Wi = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'O')[1] … … 1373 1378 if currentUInterv.isEmpty(): break 1374 1379 1375 if p. data[i][j]== 'X':1380 if p.getFinal(i,j) == 'X': 1376 1381 Bint = nextInt 1377 1382 else: 1378 1383 Bint = self.getUInterv(moves, moves1, index, i+a0, j+a1, 'X')[1] 1379 1384 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': 1381 1386 Wint = nextInt 1382 1387 else: … … 1452 1457 ALGO_HASH_FULL_CORNERS: Algo_hash_full_corners, 1453 1458 ALGO_INTERVALS: Algo_intervals} 1459 1460 1461 # -------------------------------------------------------------------------- 1462 1463 class 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 63 63 from searchPY import * 64 64 from aglPY import * 65 from algosPY import * 65 66 66 67 try: … … 1596 1597 for i in range(sel[0][1], sel[1][1]+1): 1597 1598 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' 1600 1602 else: d[(i-1,j-1)] = 'O' 1601 1603 if self.master.board.wildcards.has_key((j,i)): … … 1842 1844 1843 1845 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) 1845 1847 1846 1848 self.progBar.clear() … … 1858 1860 1859 1861 if self.currentInitialPattern: 1860 d = {}1862 d = [] 1861 1863 for i in range(self.sel[0][0], self.sel[1][0]+1): 1862 1864 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]) 1866 1866 else: 1867 1867 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 1870 1876 self.continuations = {} 1871 1877 self.statistics = {} … … 1937 1943 results = [join(l.results, '|%') for l in self.gamelist.DBlist[`self.boardsize`]] 1938 1944 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) 1943 1952 1944 1953 self.configButtons(NORMAL) … … 2468 2477 def getPatternFromBoard(self, region): 2469 2478 2470 d = {}2479 d = [] 2471 2480 2472 2481 for i in range(region[0][0], region[1][0]+1): 2473 2482 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'2477 2483 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 2479 2490 return d 2480 2491 … … 2504 2515 anchors = [(1, 1), (self.boardsize-2 -self.sel[1][0]+self.sel[0][0], 2505 2516 self.boardsize-2 -self.sel[1][1]+self.sel[0][1])] 2506 2517 anchors.sort() # FIXME: is this necessary? 2507 2518 return anchors 2508 2519 … … 2522 2533 self.board.delMSLabels() 2523 2534 self.currentInitialPattern = None 2524 self.currentContList = None2535 self.currentContList = [] 2525 2536 2526 2537 … … 2565 2576 t = [] 2566 2577 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 2576 2586 # mark hoshis with ,'s 2577 2587 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 2584 2603 remarks = [] 2585 2604 nextMove = 'B' … … 2604 2623 if not pos: continue 2605 2624 2606 if l[pos[0] ][pos[1]] in ['. ', ', ']: l[pos[0]][pos[1]] = ii2607 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 ']: 2610 2629 remarks.append(ii + 'at ' + 'ABCDEFGHJKLMNOPQRST'[pos[1]] + `pos[0]+1` + '\n') 2611 2630 … … 2614 2633 if not exportMode.get(): 2615 2634 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') 2620 2638 2621 2639 if n: … … 2623 2641 elif nextMove == 'W': remarks.append('White = 1\n') 2624 2642 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') 2635 2648 2636 2649 t.append('\n') … … 3955 3968 self.currentSearchPattern = None 3956 3969 self.currentInitialPattern = None 3957 self.currentContList = None3970 self.currentContList = [] 3958 3971 self.moveOne = 'B' 3959 3972 self.balloonHelp() 06/devel/patternPY.py
r83 r101 21 21 ## http://www.gnu.org/copyleft/gpl.html 22 22 23 from string import join 24 from array import * 23 25 24 26 class Pattern: … … 39 41 if self.moveOne != p.moveOne: return 1 40 42 for i in range(self.sizeX): 41 if self.initial Data[i] != p.initialData[i]: return 143 if self.initialPos[i] != p.initialPos[i]: return 1 42 44 if self.contList != p.contList: return 1 43 45 return 0 … … 74 76 if self.moveOne == 'X': self.moveTwo = 'O' 75 77 else: self.moveTwo = 'X' 76 78 79 self.left = left 80 self.top = top 81 self.right = right 82 self.bottom = bottom 77 83 self.anchors = [(left, top), (right, bottom)] 78 self.anchors.sort() # important for __cmp__84 # self.anchors.sort() # important for __cmp__ (but already sorted ...) 79 85 80 86 self.sizeX = sizeX … … 84 90 85 91 helpFinalPos = list(initialPos) 92 86 93 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 ... 88 97 89 98 self.finalPos = join(helpFinalPos, '') 90 99 91 self.contList = contList # [(x-start[0], y-start[1], self.BW2XO(co)) for x, y, co in contList]100 self.contList = contList 92 101 self.lenContList = lenContList 93 102 … … 153 162 def invertColor(self,co): 154 163 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] 156 165 except: 157 print 'oops '# FIXME166 print 'oops invertColor', co # FIXME 158 167 return co 159 168 … … 195 204 for i in range(self.pattern.sizeX): 196 205 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) 201 239 pNew.flip = ii 202 240 … … 208 246 for i in range(self.pattern.sizeX): 209 247 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, '') 211 255 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) 214 261 pNew1.flip = ii 215 262 pNew1.colorSwitch = 1 … … 273 320 winner): 274 321 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) 276 323 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) 279 328 XX = min(XX1, XX2) 280 329 YY = min(YY1, YY2) … … 304 353 yy += YY 305 354 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) 307 356 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) 310 359 311 360 XX = min(XX1, XX2) 06/devel/searchPY.py
r83 r101 34 34 from abstractBoardPY import * 35 35 36 from patternPY import * 37 from algosPY import * 36 38 37 39 try: … … 379 381 while len(signature2) < 6: signature2 += '??' 380 382 signature = signature1 + signature2 381 signature = symmetrizeSig(signature )383 signature = symmetrizeSig(signature, self.boardsize) 382 384 383 385 # Now check for duplicates; first in the currently processed database, … … 432 434 siglist.append(signature) 433 435 434 except :436 except ImportError: 435 437 messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n') 436 438 signature = '????????????' … … 577 579 578 580 579 class hashTable:580 581 def __init__(self, noOfGames, filename):582 self.data = array('l', [0]*(2*130*noOfGames))583 self.currentCtr = -1584 self.dataIndex = 0585 self.filename = filename586 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 -= 2592 self.currentCtr = ctr593 self.currentCtrL = []594 595 596 def append(self, i):597 598 ctr = self.currentCtr599 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] = i604 self.dataIndex += 1605 self.data[self.dataIndex] = ctr606 self.dataIndex += 1607 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] = help1616 self.data[2*r+1] = help2617 618 619 def sort(self):620 621 l = 0622 r = self.dataIndex/2 - 1623 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 = l639 right = r-1640 641 while 1:642 while self.data[2*left] < help1: left += 1643 while self.data[2*right] > help1: right -= 1644 645 if right <= left: break646 647 self.swap(left, right)648 649 left += 1650 right -= 1651 652 self.swap(left, r)653 654 if left-l > r-left:655 stack.append((l, left-1))656 l = left+1657 else:658 stack.append((left+1, r))659 r = left-1660 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
