Exemplo n.º 1
0
def fumenize(matrix, showPreview):
    # Prepare result image
    blank = np.zeros((200, 100, 3), np.uint8)
    frame = fumen.Frame()
    cell = 10

    for row in range(20):
        for col in range(10):
            if matrix[row][col]:
                # Draw gray rectangles where blocks are
                cv2.rectangle(blank, (col * 10 + 2, 190 - row * 10),
                              (col * 10 + 5 + 2, 190 - row * 10 + 5), (105, 105, 105), cv2.FILLED)
            if matrix[19 - row][col]:
                frame.field[cell] = 8
            else:
                frame.field[cell] = 0
            cell += 1

    fumen_url = fumen.make([frame], 0)
    print(fumen_url)
    try:
        pyperclip.copy(fumen_url)
    except NameError:
        pass

    if showPreview:
        # Show result image
        cv2.imshow('d', blank)
        cv2.waitKey()
        cv2.destroyAllWindows()
Exemplo n.º 2
0
def fumenize(matrix, showPreview):
	#prepare result image
	blank = np.zeros((200, 100, 3), np.uint8)
	frame = fumen.Frame()
	cell = 10

	for row in range(20):
		for col in range(10):
			if matrix[row][col]:
				#draw gray rectangles where blocks are
				cv2.rectangle(blank, (col * 10 + 2, 190 - row * 10),
					(col * 10 + 5 + 2, 190 - row * 10 + 5), (105, 105, 105), cv2.FILLED)
			if matrix[19 - row][col]:
				frame.field[cell] = 8
			else:
				frame.field[cell] = 0
			cell += 1

	fumen_url = fumen.make([frame], 0)
	print(fumen_url)
	pyperclip.copy(fumen_url)

	if showPreview:
		#show result image
		cv2.imshow('d', blank)
		cv2.waitKey()
		cv2.destroyAllWindows()
Exemplo n.º 3
0
def main():
    with open("/dev/shm/tgm2p_data", "r+b") as f:
        vSize = DATA_BLOCK_SIZE * 13
        mm = mmap.mmap(f.fileno(), vSize)

        frameList = []
        frame = fumen.Frame()

        creditReset = False

        prevState = state = 0
        prevLevel = level = 0
        prevGametime = gametime = 0
        while True:
            # We want to detect /changes/ in game state, so we should keep track
            # of the previous game state...
            prevState = state

            # At the end of a game, we'll be clearing level and time data, we
            # should store a copy of it for output.
            prevLevel = level
            prevGametime = gametime

            state = unpack_mmap_block(mm, 0)
            level = unpack_mmap_block(mm, 1)
            gametime = unpack_mmap_block(mm, 2)
            # mrollFlags = unpack_mmap_block(mm, 5)
            inCreditRoll = unpack_mmap_block(mm, 6)
            currentBlock = TapToFumenMapping[unpack_mmap_block(mm, 8)]
            currentX = unpack_mmap_block(mm, 10)
            currentY = unpack_mmap_block(mm, 11)
            rotState = unpack_mmap_block(mm, 12)

            # When inspecting the game's memory, I found that currentX
            # underflows for the I tetromino, so let's "fix" that.
            if currentX > 10:
                currentX = -1

            # Coordinates from TAP do not perfectly align with fumen's
            # coordinates.
            offsetX, offsetY = calculateFumenOffset(currentBlock, rotState)

            # Set the current frame's tetromino + location
            frame.willlock = True
            frame.piece.kind = currentBlock
            frame.piece.rot = rotState
            frame.piece.setPosition(currentX + offsetX, currentY + offsetY)

            # If we've entered the M-Roll, clear the field. This doesn't test
            # for a specific mode yet, only if the M-Roll conditions have been
            # met.
            if not creditReset and inCreditRoll:
                frameList.append(frame.copy())
                frame = frame.next()
                frame = fumen.Frame()
                creditReset = True

            # If a piece is locked in...
            if inPlayingState(state) and prevState == TapState.Active and state == TapState.Locking:
                frameList.append(frame.copy())
                frame = frame.next()

            # If the game is over...
            if inPlayingState(prevState) and not inPlayingState(state):
                # Lock the previous piece and place the killing piece. It's
                # state is not set, so the above lock check will not be run.
                frameList.append(frame.copy())
                frame = frame.next()

                fumenURL = fumen.make(frameList, 0)
                print("level %03d @ %02d:%02d\n%s\n" % (prevLevel, prevGametime / 60 / 60, prevGametime / 60 % 60, fumenURL))
                pyperclip.copy(fumenURL)

                frameList = []
                frame = fumen.Frame()
                creditReset = False

            time.sleep(0.01)
        mm.close()
Exemplo n.º 4
0
def main():
    with open("/dev/shm/tgm2p_data", "r+b") as f:
        vSize = DATA_BLOCK_SIZE * 13
        mm = mmap.mmap(f.fileno(), vSize)

        frameList = []
        frame = fumen.Frame()

        creditReset = False

        prevState = state = 0
        prevLevel = level = 0
        prevGametime = gametime = 0
        while True:
            # We want to detect /changes/ in game state, so we should keep track
            # of the previous game state...
            prevState = state

            # At the end of a game, we'll be clearing level and time data, we
            # should store a copy of it for output.
            prevLevel = level
            prevGametime = gametime

            state = unpack_mmap_block(mm, 0)
            level = unpack_mmap_block(mm, 1)
            gametime = unpack_mmap_block(mm, 2)
            # mrollFlags = unpack_mmap_block(mm, 5)
            inCreditRoll = unpack_mmap_block(mm, 6)
            currentBlock = TapToFumenMapping[unpack_mmap_block(mm, 8)]
            currentX = unpack_mmap_block(mm, 10)
            currentY = unpack_mmap_block(mm, 11)
            rotState = unpack_mmap_block(mm, 12)

            # When inspecting the game's memory, I found that currentX
            # underflows for the I tetromino, so let's "fix" that.
            if currentX > 10:
                currentX = -1

            # Coordinates from TAP do not perfectly align with fumen's
            # coordinates.
            offsetX, offsetY = calculateFumenOffset(currentBlock, rotState)

            # Set the current frame's tetromino + location
            frame.willlock = True
            frame.piece.kind = currentBlock
            frame.piece.rot = rotState
            frame.piece.setPosition(currentX + offsetX, currentY + offsetY)

            # If we've entered the M-Roll, clear the field. This doesn't test
            # for a specific mode yet, only if the M-Roll conditions have been
            # met.
            if not creditReset and inCreditRoll:
                frameList.append(frame.copy())
                frame = frame.next()
                frame = fumen.Frame()
                creditReset = True

            # If a piece is locked in...
            if inPlayingState(
                    state
            ) and prevState == TapState.Active and state == TapState.Locking:
                frameList.append(frame.copy())
                frame = frame.next()

            # If the game is over...
            if inPlayingState(prevState) and not inPlayingState(state):
                # Lock the previous piece and place the killing piece. It's
                # state is not set, so the above lock check will not be run.
                frameList.append(frame.copy())
                frame = frame.next()

                fumenURL = fumen.make(frameList, 0)
                print("level %03d @ %02d:%02d\n%s\n" %
                      (prevLevel, prevGametime / 60 / 60,
                       prevGametime / 60 % 60, fumenURL))
                pyperclip.copy(fumenURL)

                frameList = []
                frame = fumen.Frame()
                creditReset = False

            time.sleep(0.01)
        mm.close()