diff --git a/src/components/snake/canvas.ts b/src/components/snake/canvas.ts index c73fe08..0d72cf2 100644 --- a/src/components/snake/canvas.ts +++ b/src/components/snake/canvas.ts @@ -129,7 +129,7 @@ function createLabSnapshots(labs: SnakeGameTrainerLab[]): LabSnapshot[] { export default function runCanvas(canvas: HTMLCanvasElement, pipeRef: MutableRefObject) { const ui = new UI(canvas); const keys = new Keys(); - const engine = new Engine({ stepsBeforeDelay: 1, updateDelay: 0 }); + const engine = new Engine({ stepsBeforeDelay: 5, updateDelay: 0 }); // game logic -------------------------------------------------------------- diff --git a/src/components/snake/index.scss b/src/components/snake/index.scss index 0ab1ccb..a104182 100644 --- a/src/components/snake/index.scss +++ b/src/components/snake/index.scss @@ -1,12 +1,27 @@ #snake { - svg#board { - background-color: #333333; + height: 100vh; + align-items: center; + justify-content: center; + display: flex; + flex-flow: row nowrap; - .apple { - fill: #e01851; + .ui { + display: flex; + flex-flow: row nowrap; + align-items: flex-start; + justify-content: flex-start; + + canvas#board { + margin-right: 20px; } - .snake-part { - fill: #277edb; + + .table-container { + max-height: 600px; + overflow-y: auto; + + table#snaps { + width: 450px; + } } } } diff --git a/src/components/snake/index.tsx b/src/components/snake/index.tsx index 39076df..899461f 100644 --- a/src/components/snake/index.tsx +++ b/src/components/snake/index.tsx @@ -9,6 +9,15 @@ export interface PipeRef { addTrainerSnap: (snap: TrainerSnapshot) => void; } +function tableHead(...cols: (string | number)[]) { + const elements = cols.map((col, idx) => {col}); + return {elements}; +} +function tableRow(...cols: (string | number)[]) { + const elements = cols.map((col, idx) => {col}); + return {elements}; +} + const SnakePage: FC = () => { const boardRef = useRef(null); const [snaps, setSnaps] = useState([]); @@ -29,6 +38,12 @@ const SnakePage: FC = () => { runCanvas(boardRef.current, pipeRef); }, []); + // future ideas: + // - center canvas & snap table + // - configure next iteration settings + // - save/load snakes + // - view single snake + const labSnapsTRs = useMemo( () => snaps.map(snap => { @@ -44,42 +59,22 @@ const SnakePage: FC = () => { const q95Len = labsRanked[Math.floor(labsRanked.length * 0.95)]!.snakeLength; const maxLen = Math.max(...labsRanked.map(lab => lab.snakeLength)); - return ( - - {snap.iteration} - {avgLen} - {minLen} - {q20Len} - {q40Len} - {q60Len} - {q80Len} - {q90Len} - {q95Len} - {maxLen} - - ); + return tableRow(snap.iteration, avgLen, minLen, q20Len, q40Len, q60Len, q80Len, q90Len, q95Len, maxLen); }), [snaps], ); return (
- - - - - - - - - - - - - - - {labSnapsTRs} -
ItrAvgMin20%40%60%80%90%95%Max
+
+ +
+ + {tableHead('Itr', 'Avg', 'Min', '20%', '40%', '60%', '80%', '90%', '95%', 'Max')} + {labSnapsTRs} +
+
+
); };