import React, { useState } from ‘react’;
import { Card, CardHeader, CardTitle, CardContent } from ‘@/components/ui/card’;
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from ‘@/components/ui/select’;
import { Slider } from ‘@/components/ui/slider’;
import { Button } from ‘@/components/ui/button’;
const ChessOpeningRecommender = () => {
const [rating, setRating] = useState(1200);
const [style, setStyle] = useState(”);
const [goal, setGoal] = useState(”);
const [recommendation, setRecommendation] = useState(null);
// Database of openings with their characteristics
const openings = [
{
name: “Sicilian Defense”,
minRating: 1200,
styles: [“aggressive”, “tactical”],
goals: [“win”, “improve”],
description: “Sharp, double-edged positions with many tactical opportunities.”,
forBlack: true
},
{
name: “London System”,
minRating: 800,
styles: [“positional”, “solid”],
goals: [“learn”, “improve”],
description: “Solid, system-based opening that’s easy to learn and hard to refute.”,
forBlack: false
},
{
name: “King’s Indian Defense”,
minRating: 1400,
styles: [“aggressive”, “dynamic”],
goals: [“win”, “master”],
description: “Complex opening with potential for devastating kingside attacks.”,
forBlack: true
},
{
name: “Ruy Lopez”,
minRating: 1000,
styles: [“classical”, “positional”],
goals: [“improve”, “master”],
description: “Classical opening with rich strategic themes and deep theory.”,
forBlack: false
},
{
name: “French Defense”,
minRating: 1100,
styles: [“solid”, “positional”],
goals: [“learn”, “improve”],
description: “Solid opening with clear pawn structures and plans.”,
forBlack: true
},
{
name: “Vienna Game”,
minRating: 900,
styles: [“aggressive”, “tactical”],
goals: [“learn”, “win”],
description: “Aggressive opening with many tactical possibilities.”,
forBlack: false
}
];
const getRecommendation = () => {
// Filter openings based on rating and selected preferences
const suitable = openings.filter(opening =>
opening.minRating <= rating &&
opening.styles.includes(style) &&
opening.goals.includes(goal)
);
if (suitable.length === 0) {
setRecommendation({
error: true,
message: "No perfect match found. Consider adjusting your preferences."
});
return;
}
// Randomly select one of the suitable openings
const recommended = suitable[Math.floor(Math.random() * suitable.length)];
setRecommendation(recommended);
};
return (
Chess Opening Recommender
setRating(value[0])}
min={800}
max={2200}
step={100}
className=”w-full”
/>
{recommendation && (
{recommendation.error ? (
{recommendation.message}
) : (
{recommendation.name}
{recommendation.description}
For: {recommendation.forBlack ? “Black” : “White”}
Minimum Rating: {recommendation.minRating}
)}
)}
);
};
export default ChessOpeningRecommender;