Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import collections
- import copy
- from db import db
- # Sides
- F = 0
- L = 1
- R = 2
- D = 3
- # Moves
- MOVES = {
- 'U': [[[F, 0], [L, 0], [R, 0]],
- [[F, 1], [L, 1], [R, 1]],
- [[F, 2], [L, 2], [R, 2]],
- [[F, 3], [L, 3], [R, 3]]],
- 'L': [[[F, 4], [D, 0], [L, 8]],
- [[F, 1], [D, 2], [L, 6]],
- [[F, 5], [D, 1], [L, 7]],
- [[F, 6], [D, 5], [L, 3]]],
- 'R': [[[R, 4], [D, 4], [F, 8]],
- [[R, 1], [D, 7], [F, 6]],
- [[R, 5], [D, 3], [F, 7]],
- [[R, 6], [D, 2], [F, 3]]],
- 'B': [[[L, 4], [D, 8], [R, 8]],
- [[L, 1], [D, 5], [R, 6]],
- [[L, 5], [D, 6], [R, 7]],
- [[L, 6], [D, 7], [R, 3]]],
- }
- SOLVED = [[F] * 9, [L] * 9, [R] * 9, [D] * 9]
- ALL_MOVES = list(MOVES.keys()) + [x + '\'' for x in MOVES.keys()]
- def applyMove(position, move):
- subMove = move[0]
- transformations = None
- if subMove in MOVES:
- transformations = MOVES[subMove]
- elif subMove.upper() in MOVES:
- return
- #transformations = MOVES[subMove.upper()][0]
- if not transformations:
- print('ERROR: Unknown move ' + move)
- return
- if '\'' in move:
- transformations = [list(reversed(x)) for x in transformations]
- for transformation in transformations:
- saved = position[transformation[-1][0]][transformation[-1][1]]
- for i in reversed(range(len(transformation) - 1)):
- from_ = transformation[i]
- to_ = transformation[i + 1]
- position[to_[0]][to_[1]] = position[from_[0]][from_[1]]
- position[transformation[0][0]][transformation[0][1]] = saved
- def executeScramble(moves):
- position = copy.deepcopy(SOLVED)
- for move in moves:
- applyMove(position, move)
- return position
- def toStr(position):
- return ''.join([''.join([str(y) for y in x]) for x in position])
- def positionsWithMaxDepth(num):
- scrambles = [[]]
- for i in range(num):
- for scramble in scrambles:
- if len(scramble) != i:
- continue
- for move in ALL_MOVES:
- if scramble and scramble[-1][0] == move[0]:
- continue
- scrambles += [scramble + [move]]
- out = {}
- for scramble in scrambles:
- position = toStr(executeScramble(scramble))
- if position not in out:
- out[position] = len(scramble)
- return out
- positions = positionsWithMaxDepth(6)
- cursor = db.cursor()
- cursor.execute("SELECT competitionId, roundTypeId, groupId, isExtra, scrambleNum, scramble FROM Scrambles WHERE eventId='pyram'")
- tipCounts = collections.defaultdict(lambda: 0)
- for row in cursor.fetchall():
- scr = row[5].split(' ')
- numTips = len([x for x in scr if x[0] in ('u', 'l', 'r', 'b')])
- pos = toStr(executeScramble(scr))
- if pos in positions:
- if positions[pos] + numTips == 6:
- tipCounts[numTips] += 1
- if positions[pos] < 3:
- print(row)
- print(tipCounts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement