public function findProblemSquares() { $pt = $this->puzzle_template; $blackSquares = $pt->blackSquares(); $puzzle_squares = $this->puzzle_squares(true); $impossibles = array(); $problems = array(); for ($row = 1; $row <= $pt->height; $row++) { for ($col = 1; $col <= $pt->width; $col++) { if (!in_array($row . '-' . $col, $blackSquares)) { if ($puzzle_squares[$row . '-' . $col]['letter'] == '') { $sugg = PuzzleSquare::findSuggestion($this, $row, $col); if (count($sugg['suggestions']) == 0) { $impossibles[] = $row . '-' . $col; } else { $total = 0; foreach ($sugg['suggestions'] as $s) { $total += $s->score; } if ($sugg['suggestions'][0]->score / $total > 0.4) { $problems[$row . '-' . $col] = 100 * $sugg['suggestions'][0]->score / $total; } } } } } } return compact('impossibles', 'problems'); }
public function getSuggestion($slug, $row, $col) { $user = Auth::user(); if (!$user) { $msg = 'Please log in'; $returnData = array('errors' => array($msg)); return response()->json($returnData, 401); } $p = Puzzle::findBySlug($slug); if ($p->user_id != $user->id) { $msg = 'This isn\'t your puzzle'; $returnData = array('errors' => array($msg)); return response()->json($returnData, 401); } return PuzzleSquare::findSuggestion($p, $row, $col); }