initial
This commit is contained in:
248
docs/test.html
Normal file
248
docs/test.html
Normal file
@ -0,0 +1,248 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ARC Puzzle Renderer Test</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.container {
|
||||
background-color: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.section {
|
||||
margin-top: 40px;
|
||||
border-top: 2px solid #ddd;
|
||||
padding-top: 20px;
|
||||
}
|
||||
.test-output-toggle {
|
||||
margin-top: 20px;
|
||||
}
|
||||
button {
|
||||
padding: 10px 20px;
|
||||
background-color: #0074D9;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
#testOutputContainer {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.info {
|
||||
background-color: #e7f3ff;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div id="puzzleContainer"></div>
|
||||
|
||||
<div class="section test-output-toggle">
|
||||
<button onclick="loadAnotherExample()">Load Another Example</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Color mapping for ARC puzzles (0-9)
|
||||
const ARC_COLORS = {
|
||||
0: '#000000', // black
|
||||
1: '#0074D9', // blue
|
||||
2: '#FF4136', // red
|
||||
3: '#2ECC40', // green
|
||||
4: '#FFDC00', // yellow
|
||||
5: '#AAAAAA', // grey
|
||||
6: '#F012BE', // magenta
|
||||
7: '#FF851B', // orange
|
||||
8: '#7FDBFF', // light blue
|
||||
9: '#85144b' // dark red
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a single grid as HTML
|
||||
*/
|
||||
function renderGrid(grid, label) {
|
||||
if (!grid || grid.length === 0) {
|
||||
return '<div style="color: red;">Invalid grid data</div>';
|
||||
}
|
||||
|
||||
const rows = grid.length;
|
||||
const cols = grid[0].length;
|
||||
const cellSize = 20; // Fixed 20px per cell
|
||||
|
||||
let html = '<div style="display: inline-block; margin: 10px;">';
|
||||
|
||||
// Add dimension label
|
||||
if (label) {
|
||||
html += `<div style="text-align: center; margin-bottom: 5px; font-size: 12px; color: #333;">${label}</div>`;
|
||||
}
|
||||
|
||||
// Grid container with black border
|
||||
html += `<div style="display: inline-block; border: 1px solid #000000;">`;
|
||||
|
||||
// Render each row
|
||||
for (let r = 0; r < rows; r++) {
|
||||
html += '<div style="display: flex; line-height: 0;">';
|
||||
|
||||
// Render each cell in the row
|
||||
for (let c = 0; c < cols; c++) {
|
||||
const cellValue = grid[r][c];
|
||||
const color = ARC_COLORS[cellValue] || '#FFFFFF'; // Default to white if value unknown
|
||||
|
||||
html += `<div style="width: ${cellSize}px; height: ${cellSize}px; background-color: ${color}; outline: 0.5px solid rgba(200, 200, 200, 0.3); outline-offset: -0.5px;"></div>`;
|
||||
}
|
||||
|
||||
html += '</div>'; // Close row
|
||||
}
|
||||
|
||||
html += '</div>'; // Close grid container
|
||||
html += '</div>'; // Close inline-block wrapper
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a training or test pair (input and output side-by-side)
|
||||
*/
|
||||
function renderPair(inputGrid, outputGrid, exampleIndex) {
|
||||
let html = '';
|
||||
|
||||
// Add spacing between examples (except for the first one)
|
||||
if (exampleIndex > 0) {
|
||||
html += '<div style="height: 40px;"></div>'; // 2 lines spacing
|
||||
}
|
||||
|
||||
html += '<div style="display: flex; align-items: flex-start; justify-content: flex-start;">';
|
||||
|
||||
// Render input grid
|
||||
const inputRows = inputGrid.length;
|
||||
const inputCols = inputGrid[0].length;
|
||||
html += renderGrid(inputGrid, `${inputCols}×${inputRows}`);
|
||||
|
||||
// Add spacing between input and output (2 cells worth = 40px)
|
||||
html += '<div style="width: 40px;"></div>';
|
||||
|
||||
// Render output grid if provided
|
||||
if (outputGrid) {
|
||||
const outputRows = outputGrid.length;
|
||||
const outputCols = outputGrid[0].length;
|
||||
html += renderGrid(outputGrid, `${outputCols}×${outputRows}`);
|
||||
}
|
||||
|
||||
html += '</div>'; // Close pair container
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function: Renders complete ARC puzzle with training pairs and test input
|
||||
*/
|
||||
function renderArcPuzzle(jsonData) {
|
||||
// Parse JSON if string is provided
|
||||
let data = jsonData;
|
||||
if (typeof jsonData === 'string') {
|
||||
try {
|
||||
data = JSON.parse(jsonData);
|
||||
} catch (e) {
|
||||
return '<div style="color: red;">Error: Invalid JSON data</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Validate data structure
|
||||
if (!data || !data.train || !data.test) {
|
||||
return '<div style="color: red;">Error: JSON must contain "train" and "test" properties</div>';
|
||||
}
|
||||
|
||||
let html = '<div style="font-family: Arial, sans-serif;">';
|
||||
|
||||
// === TRAINING SECTION ===
|
||||
html += '<div style="margin-bottom: 60px;">';
|
||||
html += '<h3 style="margin: 0 0 20px 0; color: #333;">Training Examples</h3>';
|
||||
|
||||
data.train.forEach((example, index) => {
|
||||
html += renderPair(example.input, example.output, index);
|
||||
});
|
||||
|
||||
html += '</div>'; // Close training section
|
||||
|
||||
// === TEST SECTION ===
|
||||
html += '<div>';
|
||||
html += '<h3 style="margin: 0 0 20px 0; color: #333;">Test</h3>';
|
||||
|
||||
data.test.forEach((example, index) => {
|
||||
// Render both test input and output
|
||||
html += renderPair(example.input, example.output, index);
|
||||
});
|
||||
|
||||
html += '</div>'; // Close test section
|
||||
|
||||
html += '</div>'; // Close main container
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
// Global variables
|
||||
let arcData = null;
|
||||
let exampleIndex = 0;
|
||||
const examples = ['0a1d4ef5.json', '0a2355a6.json', '0a938d79.json', '0b148d64.json'];
|
||||
|
||||
// Load and render puzzle
|
||||
function loadPuzzle() {
|
||||
if (!arcData) {
|
||||
document.getElementById('puzzleContainer').innerHTML = '<div style="color: orange;">Loading puzzle data...</div>';
|
||||
return;
|
||||
}
|
||||
document.getElementById('puzzleContainer').innerHTML = renderArcPuzzle(arcData);
|
||||
}
|
||||
|
||||
// Load another example from files
|
||||
function loadAnotherExample() {
|
||||
exampleIndex = (exampleIndex + 1) % examples.length;
|
||||
loadExampleByIndex(exampleIndex);
|
||||
}
|
||||
|
||||
// Load specific example by index
|
||||
function loadExampleByIndex(index) {
|
||||
fetch('arc_examples/' + examples[index])
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('File not found');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
arcData = data;
|
||||
loadPuzzle();
|
||||
})
|
||||
.catch(error => {
|
||||
document.getElementById('puzzleContainer').innerHTML =
|
||||
'<div style="color: red;">Error loading puzzle file: ' + examples[index] +
|
||||
'<br>Make sure you are running a local server (e.g., python3 -m http.server)</div>';
|
||||
});
|
||||
}
|
||||
|
||||
// Initial load - load first example
|
||||
loadExampleByIndex(0);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user