Spaces:
Sleeping
Sleeping
File size: 5,504 Bytes
e190eb7 a6b8103 e190eb7 a6b8103 c1c8771 c2e6608 27f96d4 df9abc4 c1c8771 c2e6608 c1c8771 c2e6608 6b09c13 c1c8771 6b09c13 c1c8771 df9abc4 c1c8771 df9abc4 c1c8771 df9abc4 c1c8771 6b09c13 c2e6608 df9abc4 c1c8771 df9abc4 a6b8103 df9abc4 6b09c13 df9abc4 c1c8771 df9abc4 c1c8771 df9abc4 27f96d4 c1c8771 27f96d4 df9abc4 a6b8103 c1c8771 df9abc4 c1c8771 27f96d4 df9abc4 c1c8771 a6b8103 c1c8771 e190eb7 df9abc4 e190eb7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
import gradio as gr
import numpy as np
import matplotlib.pyplot as plt
class RubiksCube2x2Solver:
def __init__(self):
self.size = 2
self.cube = np.zeros((6, 2, 2), dtype=int)
# Configurar o estado inicial específico
self.cube[0] = np.array([[1, 3], [4, 2]]) # Face 1
self.cube[1] = np.array([[1, 5], [0, 5]]) # Face 2
self.cube[2] = np.array([[2, 2], [3, 4]]) # Face 3
self.cube[3] = np.array([[1, 5], [3, 3]]) # Face 4
self.cube[4] = np.array([[4, 0], [0, 1]]) # Face 5
self.cube[5] = np.array([[2, 4], [1, 0]]) # Face 6
self.color_names = {
0: "Branco",
1: "Amarelo",
2: "Verde",
3: "Azul",
4: "Vermelho",
5: "Laranja"
}
def get_solution(self):
"""Retorna os passos para resolver o cubo"""
solution = []
# Análise inicial
solution.append("ANÁLISE INICIAL:")
solution.append("1. Face Superior (Face 1):")
solution.append(" - Amarelo, Azul, Vermelho, Verde")
solution.append("2. Face Frontal (Face 2):")
solution.append(" - Amarelo, Laranja, Branco, Laranja")
solution.append("3. Face Direita (Face 3):")
solution.append(" - Verde, Verde, Azul, Vermelho")
solution.append("4. Face Esquerda (Face 4):")
solution.append(" - Amarelo, Laranja, Azul, Azul")
solution.append("5. Face Inferior (Face 5):")
solution.append(" - Vermelho, Branco, Branco, Amarelo")
solution.append("6. Face Traseira (Face 6):")
solution.append(" - Verde, Vermelho, Amarelo, Branco")
solution.append("")
# Estratégia de solução
solution.append("ESTRATÉGIA DE SOLUÇÃO:")
solution.append("1. Resolver Face Branca:")
solution.append(" a. Reunir peças brancas (atualmente nas faces 2, 5 e 6)")
solution.append(" b. Posicionar na face inferior")
solution.append(" c. Orientar corretamente")
solution.append("")
solution.append("2. Resolver Segunda Camada:")
solution.append(" a. Alinhar arestas verdes e vermelhas")
solution.append(" b. Alinhar arestas azuis e laranjas")
solution.append("")
solution.append("3. Resolver Face Amarela:")
solution.append(" a. Posicionar peças amarelas (atualmente espalhadas)")
solution.append(" b. Orientar cantos amarelos")
solution.append(" c. Permutar cantos se necessário")
solution.append("")
solution.append("SEQUÊNCIA DE MOVIMENTOS:")
solution.append("1. R U R' U' (reunir peças brancas)")
solution.append("2. U2 R U2 R' (posicionar brancas)")
solution.append("3. R U R' U R U2 R' (orientar cantos)")
solution.append("4. U' R U R' U' R U R' (segunda camada)")
solution.append("5. U R U' R' (face amarela)")
solution.append("6. R U R' U R U2 R' (orientação final)")
solution.append("")
solution.append("OBSERVAÇÕES:")
solution.append("- Use U para giros da face superior")
solution.append("- Use R para giros da face direita")
solution.append("- O apóstrofo (') indica giro anti-horário")
solution.append("- U2 significa girar duas vezes")
return solution
def create_visualization(cube_state):
fig, ax = plt.subplots(3, 4, figsize=(12, 9))
plt.subplots_adjust(hspace=0.4, wspace=0.4)
colors = {
0: "#FFFFFF", # Branco
1: "#FFFF00", # Amarelo
2: "#00FF00", # Verde
3: "#0000FF", # Azul
4: "#FF0000", # Vermelho
5: "#FFA500" # Laranja
}
face_positions = [
(0, 1), # Face Superior
(1, 1), # Face Frontal
(1, 2), # Face Direita
(1, 0), # Face Esquerda
(2, 1), # Face Inferior
(1, 3), # Face Traseira
]
face_names = ["Superior", "Frontal", "Direita", "Esquerda", "Inferior", "Traseira"]
for face_idx, (row, col) in enumerate(face_positions):
face = cube_state[face_idx]
for i in range(2):
for j in range(2):
color = colors[face[i, j]]
ax[row, col].add_patch(plt.Rectangle(
(j/2, (1-i)/2), 1/2, 1/2,
facecolor=color,
edgecolor='black'
))
ax[row, col].set_xlim(0, 1)
ax[row, col].set_ylim(0, 1)
ax[row, col].set_xticks([])
ax[row, col].set_yticks([])
ax[row, col].set_title(f'Face {face_names[face_idx]}')
for i in range(3):
for j in range(4):
if (i, j) not in face_positions:
fig.delaxes(ax[i, j])
return fig
def show_solution():
cube = RubiksCube2x2Solver()
fig = create_visualization(cube.cube)
solution = "\n".join(cube.get_solution())
return fig, solution
# Criar interface Gradio
with gr.Blocks(title="Resolvedor de Cubo 2x2") as demo:
gr.Markdown("# Resolvedor de Cubo 2x2")
gr.Markdown("### Estado atual do cubo e solução proposta")
with gr.Row():
cube_vis = gr.Plot(label="Estado do Cubo")
solution_text = gr.Textbox(label="Passos para Solução", lines=30)
demo.load(fn=show_solution, outputs=[cube_vis, solution_text])
# Iniciar aplicação
demo.launch() |