@@ -21,9 +21,10 @@ import {
2121 AuthContext ,
2222 MaiaEngineContext ,
2323} from 'src/contexts'
24- import { DrillConfiguration , AnalyzedGame } from 'src/types'
24+ import { DrillConfiguration , AnalyzedGame , OpeningSelection } from 'src/types'
2525import { GameNode } from 'src/types/base/tree'
2626import { MIN_STOCKFISH_DEPTH } from 'src/constants/analysis'
27+ import { MAIA_MODELS } from 'src/constants/common'
2728import openings from 'src/lib/openings/openings.json'
2829
2930const LazyOpeningDrillAnalysis = lazy ( ( ) =>
@@ -59,7 +60,12 @@ import {
5960const OpeningsPage : NextPage = ( ) => {
6061 const router = useRouter ( )
6162 const { user } = useContext ( AuthContext )
62- const [ showSelectionModal , setShowSelectionModal ] = useState ( true )
63+ const { mode, fen, turn, pgn } = router . query // Extract mode, fen and turn from query parameters
64+
65+ const isDrillFromPosition = mode === 'drill-from-position' && fen
66+
67+ const [ showSelectionModal , setShowSelectionModal ] =
68+ useState ( ! isDrillFromPosition )
6369 const [ isReopenedModal , setIsReopenedModal ] = useState ( false )
6470
6571 const handleCloseModal = ( ) => {
@@ -69,8 +75,49 @@ const OpeningsPage: NextPage = () => {
6975 router . push ( '/' )
7076 }
7177 }
78+
79+ // Create drill configuration for drill-from-position mode
80+ const createCustomDrillConfiguration = useCallback (
81+ ( fenPosition : string , turn : string , pgn : string ) : DrillConfiguration => {
82+ const customSelection : OpeningSelection = {
83+ id : `custom-position-${ Date . now ( ) } ` ,
84+ opening : {
85+ id : 'custom' ,
86+ name : 'Custom Position' ,
87+ description : 'Drill from analysis position' ,
88+ fen : fenPosition , // Use the custom FEN as starting position
89+ pgn : pgn , // Use the provided PGN
90+ variations : [ ] ,
91+ } ,
92+ variation : null ,
93+ playerColor : turn === 'b' ? 'black' : 'white' , // Default to white if not specified
94+ maiaVersion : MAIA_MODELS [ 0 ] , // Default Maia model
95+ targetMoveNumber : 10 , // Default target moves
96+ }
97+
98+ return {
99+ selections : [ customSelection ] ,
100+ drillCount : 1 ,
101+ drillSequence : [ customSelection ] ,
102+ }
103+ } ,
104+ [ ] ,
105+ )
106+
107+ // Initialize drill configuration based on mode
72108 const [ drillConfiguration , setDrillConfiguration ] =
73- useState < DrillConfiguration | null > ( null )
109+ useState < DrillConfiguration | null > ( ( ) => {
110+ if (
111+ isDrillFromPosition &&
112+ typeof fen === 'string' &&
113+ typeof turn === 'string' &&
114+ typeof pgn === 'string'
115+ ) {
116+ return createCustomDrillConfiguration ( fen , turn , pgn )
117+ }
118+ return null
119+ } )
120+
74121 const [ promotionFromTo , setPromotionFromTo ] = useState <
75122 [ string , string ] | null
76123 > ( null )
@@ -658,9 +705,10 @@ const OpeningsPage: NextPage = () => {
658705
659706 // Show selection modal when no drill configuration exists (after model is ready)
660707 if (
661- ! drillConfiguration ||
662- drillConfiguration . selections . length === 0 ||
663- showSelectionModal
708+ ( ! drillConfiguration ||
709+ drillConfiguration . selections . length === 0 ||
710+ showSelectionModal ) &&
711+ ! isDrillFromPosition // Don't show selection modal in drill-from-position mode
664712 ) {
665713 return (
666714 < >
@@ -1072,10 +1120,18 @@ const OpeningsPage: NextPage = () => {
10721120 return (
10731121 < >
10741122 < Head >
1075- < title > Opening Drills – Maia Chess</ title >
1123+ < title >
1124+ { isDrillFromPosition
1125+ ? 'Drill from Position – Maia Chess'
1126+ : 'Opening Drills – Maia Chess' }
1127+ </ title >
10761128 < meta
10771129 name = "description"
1078- content = "Master chess openings with interactive drills against Maia AI. Practice popular openings, learn key variations, and get performance analysis to improve your opening repertoire."
1130+ content = {
1131+ isDrillFromPosition
1132+ ? 'Practice from your analysis position with Maia AI. Continue playing from where you left off and improve your technique in real positions.'
1133+ : 'Master chess openings with interactive drills against Maia AI. Practice popular openings, learn key variations, and get performance analysis to improve your opening repertoire.'
1134+ }
10791135 />
10801136 </ Head >
10811137 < TreeControllerContext . Provider
0 commit comments