diff --git a/src/app/lib/solveProblem.ts b/src/app/lib/solveProblem.ts index 3df08481..8ffdd04e 100644 --- a/src/app/lib/solveProblem.ts +++ b/src/app/lib/solveProblem.ts @@ -80,14 +80,15 @@ export function solveProblem(program: string): SolveProblemResult { export function isAnswerCorrect( problemProgram: string, answerCharacters: CharacterClass[], - answerBoard: BoardClass + answerBoard: BoardClass, + step?: number ): boolean { - const answer = solveProblem(problemProgram); + const correctAnswer = solveProblem(problemProgram).histories?.at(step || -1); - if (!answer.characters || !answer.board) return false; + if (!correctAnswer || !correctAnswer.characters) return false; // 順番は関係なく、id以外のキャラクターの状態が一致しているかチェック - const isCorrectCharacters: boolean = answer.characters.every((correctCharacter) => { + const isCorrectCharacters: boolean = correctAnswer.characters.every((correctCharacter) => { const character = answerCharacters.find( (answerCharacter) => answerCharacter.name === correctCharacter.name && @@ -102,7 +103,7 @@ export function isAnswerCorrect( }); // すべてのセルの色が一致しているかチェック - const isCorrectBoard: boolean = answer.board.grid.every((rows, rowIndex) => + const isCorrectBoard: boolean = correctAnswer.board.grid.every((rows, rowIndex) => rows.every((column, columnIndex) => { const cell = answerBoard.grid[rowIndex][columnIndex]; return cell.color === column.color; diff --git a/src/components/organisms/TurtleGraphics.tsx b/src/components/organisms/TurtleGraphics.tsx index f45cf6f6..7a2bf1e9 100644 --- a/src/components/organisms/TurtleGraphics.tsx +++ b/src/components/organisms/TurtleGraphics.tsx @@ -6,7 +6,7 @@ import React, { useState, forwardRef, useImperativeHandle, useEffect, useCallbac import { Board } from '../../app/lib/Board'; import { Character } from '../../app/lib/Character'; -import { isAnswerCorrect } from '../../app/lib/solveProblem'; +import { isAnswerCorrect, solveProblem } from '../../app/lib/solveProblem'; import type { CellColor, CharacterDirection, SelectedCell } from '../../types'; import { TurtleGraphicsController } from '../molecules/TurtleGraphicsController'; @@ -31,7 +31,7 @@ export interface TurtleGraphicsHandle { } export const TurtleGraphics = forwardRef( - ({ beforeCheckPointLine = 0, isEnableOperation = false, problemProgram }, ref) => { + ({ beforeCheckPointLine = 0, currentCheckPointLine, isEnableOperation = false, problemProgram }, ref) => { const [board, setBoard] = useState(new Board()); const [characters, setCharacters] = useState([]); const [selectedCharacter, setSelectedCharacter] = useState(); @@ -80,7 +80,7 @@ export const TurtleGraphics = forwardRef { - return isAnswerCorrect(problemProgram, characters, board); + return isAnswerCorrect(problemProgram, characters, board, currentCheckPointLine); }; const handleClickCharacter = (character: Character): void => {