Spaces:
Sleeping
Sleeping
show indicators
Browse files- public/logo.png +0 -0
- src/app/favicon.ico +0 -0
- src/app/layout.tsx +3 -0
- src/components/rotation-panel.tsx +10 -1
- src/components/ui-controls.tsx +16 -4
- src/contexts/control-context.tsx +7 -0
public/logo.png
ADDED
|
src/app/favicon.ico
DELETED
|
Binary file (25.9 kB)
|
|
|
src/app/layout.tsx
CHANGED
|
@@ -7,6 +7,9 @@ import './globals.css';
|
|
| 7 |
export const metadata: Metadata = {
|
| 8 |
title: "Rubik's Cube Solver - with Reinforcement Learning",
|
| 9 |
description: "A web application for solving Rubik's Cube using Reinforcement Learning techniques.",
|
|
|
|
|
|
|
|
|
|
| 10 |
};
|
| 11 |
|
| 12 |
export default function RootLayout({
|
|
|
|
| 7 |
export const metadata: Metadata = {
|
| 8 |
title: "Rubik's Cube Solver - with Reinforcement Learning",
|
| 9 |
description: "A web application for solving Rubik's Cube using Reinforcement Learning techniques.",
|
| 10 |
+
icons: {
|
| 11 |
+
icon: '/logo.png',
|
| 12 |
+
},
|
| 13 |
};
|
| 14 |
|
| 15 |
export default function RootLayout({
|
src/components/rotation-panel.tsx
CHANGED
|
@@ -4,6 +4,8 @@ import { useLoader } from '@react-three/fiber';
|
|
| 4 |
import { useState } from 'react';
|
| 5 |
import { TextureLoader } from 'three';
|
| 6 |
|
|
|
|
|
|
|
| 7 |
import { FacingDirection, RotationDirection, RotationStep, Rotations } from './consts';
|
| 8 |
|
| 9 |
type RotationPanelProps = {
|
|
@@ -13,6 +15,7 @@ type RotationPanelProps = {
|
|
| 13 |
};
|
| 14 |
|
| 15 |
export const RotationPanel = ({ facingDirection, direction, onClick }: RotationPanelProps) => {
|
|
|
|
| 16 |
const clockwise = direction === 'clockwise';
|
| 17 |
const texture = useLoader(TextureLoader, `/textures/${direction}.png`);
|
| 18 |
const [opacity, setOpacity] = useState(0);
|
|
@@ -43,7 +46,13 @@ export const RotationPanel = ({ facingDirection, direction, onClick }: RotationP
|
|
| 43 |
onClick={handleClick}
|
| 44 |
>
|
| 45 |
<planeGeometry args={[0.8, 1.6]} />
|
| 46 |
-
<meshStandardMaterial
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
</mesh>
|
| 48 |
);
|
| 49 |
};
|
|
|
|
| 4 |
import { useState } from 'react';
|
| 5 |
import { TextureLoader } from 'three';
|
| 6 |
|
| 7 |
+
import { useControlContext } from '@/contexts/control-context';
|
| 8 |
+
|
| 9 |
import { FacingDirection, RotationDirection, RotationStep, Rotations } from './consts';
|
| 10 |
|
| 11 |
type RotationPanelProps = {
|
|
|
|
| 15 |
};
|
| 16 |
|
| 17 |
export const RotationPanel = ({ facingDirection, direction, onClick }: RotationPanelProps) => {
|
| 18 |
+
const { showRotationIndicators } = useControlContext();
|
| 19 |
const clockwise = direction === 'clockwise';
|
| 20 |
const texture = useLoader(TextureLoader, `/textures/${direction}.png`);
|
| 21 |
const [opacity, setOpacity] = useState(0);
|
|
|
|
| 46 |
onClick={handleClick}
|
| 47 |
>
|
| 48 |
<planeGeometry args={[0.8, 1.6]} />
|
| 49 |
+
<meshStandardMaterial
|
| 50 |
+
color={'#aaaaaa'}
|
| 51 |
+
roughness={0.5}
|
| 52 |
+
opacity={showRotationIndicators ? 1 : opacity}
|
| 53 |
+
map={texture}
|
| 54 |
+
transparent
|
| 55 |
+
/>
|
| 56 |
</mesh>
|
| 57 |
);
|
| 58 |
};
|
src/components/ui-controls.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
-
import { Button, ButtonGroup, Card, CardBody, Slider } from '@heroui/react';
|
| 4 |
import { useState } from 'react';
|
| 5 |
|
| 6 |
import { useControlContext } from '@/contexts/control-context';
|
|
@@ -9,8 +9,16 @@ import { Actions } from './consts';
|
|
| 9 |
|
| 10 |
export const UIControls = () => {
|
| 11 |
const [isControlsOpen, setIsControlsOpen] = useState(true);
|
| 12 |
-
const {
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
const scramble = () => {
|
| 16 |
const scrambleSteps = Array.from({ length: 20 }, () => Actions[Math.floor(Math.random() * Actions.length)]);
|
|
@@ -48,6 +56,10 @@ export const UIControls = () => {
|
|
| 48 |
style={{ willChange: 'max-height, opacity' }}
|
| 49 |
>
|
| 50 |
<div className="flex flex-col gap-2 mt-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
<div className="flex items-center justify-between">
|
| 52 |
<div className="text-sm">Background</div>
|
| 53 |
<ButtonGroup size="sm">
|
|
@@ -84,7 +96,7 @@ export const UIControls = () => {
|
|
| 84 |
</Button>
|
| 85 |
</div>
|
| 86 |
<div className="text-sm italic font-bold underline text-primary cursor-pointer" onClick={train}>
|
| 87 |
-
Train
|
| 88 |
</div>
|
| 89 |
</div>
|
| 90 |
</div>
|
|
|
|
| 1 |
'use client';
|
| 2 |
|
| 3 |
+
import { Button, ButtonGroup, Card, CardBody, Checkbox, Slider } from '@heroui/react';
|
| 4 |
import { useState } from 'react';
|
| 5 |
|
| 6 |
import { useControlContext } from '@/contexts/control-context';
|
|
|
|
| 9 |
|
| 10 |
export const UIControls = () => {
|
| 11 |
const [isControlsOpen, setIsControlsOpen] = useState(true);
|
| 12 |
+
const {
|
| 13 |
+
rubiksCubeRef,
|
| 14 |
+
showRotationIndicators,
|
| 15 |
+
setShowRotationIndicators,
|
| 16 |
+
setBackground,
|
| 17 |
+
cubeRoughness,
|
| 18 |
+
setCubeRoughness,
|
| 19 |
+
cubeSpeed,
|
| 20 |
+
setCubeSpeed,
|
| 21 |
+
} = useControlContext();
|
| 22 |
|
| 23 |
const scramble = () => {
|
| 24 |
const scrambleSteps = Array.from({ length: 20 }, () => Actions[Math.floor(Math.random() * Actions.length)]);
|
|
|
|
| 56 |
style={{ willChange: 'max-height, opacity' }}
|
| 57 |
>
|
| 58 |
<div className="flex flex-col gap-2 mt-6">
|
| 59 |
+
<div className="flex items-center justify-between">
|
| 60 |
+
<div className="text-sm">Rotation Indicators</div>
|
| 61 |
+
<Checkbox isSelected={showRotationIndicators} onValueChange={setShowRotationIndicators} />
|
| 62 |
+
</div>
|
| 63 |
<div className="flex items-center justify-between">
|
| 64 |
<div className="text-sm">Background</div>
|
| 65 |
<ButtonGroup size="sm">
|
|
|
|
| 96 |
</Button>
|
| 97 |
</div>
|
| 98 |
<div className="text-sm italic font-bold underline text-primary cursor-pointer" onClick={train}>
|
| 99 |
+
Train your own model!
|
| 100 |
</div>
|
| 101 |
</div>
|
| 102 |
</div>
|
src/contexts/control-context.tsx
CHANGED
|
@@ -6,6 +6,8 @@ import { RefObject, createContext, useContext, useState } from 'react';
|
|
| 6 |
import { RubiksCubeRef } from '@/components/rubiks-cube';
|
| 7 |
|
| 8 |
type ControlContextType = {
|
|
|
|
|
|
|
| 9 |
cubeRoughness: number;
|
| 10 |
setCubeRoughness: (cubeRoughness: number) => void;
|
| 11 |
cubeSpeed: number;
|
|
@@ -17,6 +19,8 @@ type ControlContextType = {
|
|
| 17 |
};
|
| 18 |
|
| 19 |
export const ControlContext = createContext<ControlContextType>({
|
|
|
|
|
|
|
| 20 |
cubeRoughness: 0.5,
|
| 21 |
setCubeRoughness: () => {},
|
| 22 |
cubeSpeed: 2,
|
|
@@ -32,6 +36,7 @@ export const useControlContext = () => {
|
|
| 32 |
};
|
| 33 |
|
| 34 |
export const ControlProvider = ({ children }: { children: React.ReactNode }) => {
|
|
|
|
| 35 |
const [cubeRoughness, setCubeRoughness] = useState(0.5);
|
| 36 |
const [cubeSpeed, setCubeSpeed] = useState(2);
|
| 37 |
const [background, setBackground] = useState<PresetsType>('sunset');
|
|
@@ -40,6 +45,8 @@ export const ControlProvider = ({ children }: { children: React.ReactNode }) =>
|
|
| 40 |
return (
|
| 41 |
<ControlContext.Provider
|
| 42 |
value={{
|
|
|
|
|
|
|
| 43 |
cubeRoughness,
|
| 44 |
setCubeRoughness,
|
| 45 |
cubeSpeed,
|
|
|
|
| 6 |
import { RubiksCubeRef } from '@/components/rubiks-cube';
|
| 7 |
|
| 8 |
type ControlContextType = {
|
| 9 |
+
showRotationIndicators: boolean;
|
| 10 |
+
setShowRotationIndicators: (showRotationIndicators: boolean) => void;
|
| 11 |
cubeRoughness: number;
|
| 12 |
setCubeRoughness: (cubeRoughness: number) => void;
|
| 13 |
cubeSpeed: number;
|
|
|
|
| 19 |
};
|
| 20 |
|
| 21 |
export const ControlContext = createContext<ControlContextType>({
|
| 22 |
+
showRotationIndicators: false,
|
| 23 |
+
setShowRotationIndicators: () => {},
|
| 24 |
cubeRoughness: 0.5,
|
| 25 |
setCubeRoughness: () => {},
|
| 26 |
cubeSpeed: 2,
|
|
|
|
| 36 |
};
|
| 37 |
|
| 38 |
export const ControlProvider = ({ children }: { children: React.ReactNode }) => {
|
| 39 |
+
const [showRotationIndicators, setShowRotationIndicators] = useState(false);
|
| 40 |
const [cubeRoughness, setCubeRoughness] = useState(0.5);
|
| 41 |
const [cubeSpeed, setCubeSpeed] = useState(2);
|
| 42 |
const [background, setBackground] = useState<PresetsType>('sunset');
|
|
|
|
| 45 |
return (
|
| 46 |
<ControlContext.Provider
|
| 47 |
value={{
|
| 48 |
+
showRotationIndicators,
|
| 49 |
+
setShowRotationIndicators,
|
| 50 |
cubeRoughness,
|
| 51 |
setCubeRoughness,
|
| 52 |
cubeSpeed,
|