src/Game.php
private function calculateMoveScore($player, array $position)
    {
        if ($this->board->getValue($position)) {
            return null;
        }

        $totalScore = 0;

        foreach ($this->positions as $row) {

            if (!in_array($position, $row)) {
                continue;
            }

            $countOpponentMoves = 0;
            $countPlayerMoves = 0;

            foreach ($row as $positionTile) {

                $positionValue = $this->board->getValue($positionTile);
                if ($positionValue) {

                    $countOpponentMoves++;

                    if ($positionValue == $player) {
                        $countPlayerMoves++;

                        $countOpponentMoves--;
                    }

                }

            }


            if (!$countOpponentMoves && $countPlayerMoves == 2) {
                $totalScore += 10;
                continue;

            }
            if (!$countOpponentMoves && $countPlayerMoves == 1) {
                $totalScore += 2;
                continue;

            }
            if (!$countOpponentMoves && !$countPlayerMoves) {
                $totalScore++;
                continue;
            }
        }
        return $totalScore;
    }
private function calculateMoveScore($player, array $position)
    {
        if ($this->board->getValue($position)) {
            return null;
        }

        $totalScore = 0;

        foreach ($this->positions as $row) {

            if (!in_array($position, $row)) {
                continue;
            }

            $countOpponentMoves = 0;
            $countPlayerMoves = 0;

            foreach ($row as $positionTile) {

                $positionValue = $this->board->getValue($positionTile);
                if ($positionValue) {

                    $countOpponentMoves++;

                    if ($positionValue == $player) {
                        $countPlayerMoves++;

                        $countOpponentMoves--;
                    }

                }

            }


            if (!$countOpponentMoves && $countPlayerMoves == 2) {
                $totalScore += 10;
                continue;

            }
            if (!$countOpponentMoves && $countPlayerMoves == 1) {
                $totalScore += 2;
                continue;

            }
            if (!$countOpponentMoves && !$countPlayerMoves) {
                $totalScore++;
                continue;
            }
        }
        return $totalScore;
    }
private function calculateMoveScore ( $ player , array $ position ) { if ( $ this -> board -> getValue ( $ position ) ) { return null ; } $ totalScore = 0 ; foreach ( $ this -> positions as $ row ) { if ( ! in_array ( $ position , $ row ) ) { continue ; } $ countOpponentMoves = 0 ; $ countPlayerMoves = 0 ; foreach ( $ row as $ positionTile ) { $ positionValue = $ this -> board -> getValue ( $ positionTile ) ; if ( $ positionValue ) { $ countOpponentMoves ++ ; if ( $ positionValue == $ player ) { $ countPlayerMoves ++ ; $ countOpponentMoves -- ; } } } if ( ! $ countOpponentMoves && $ countPlayerMoves == 2 ) { $ totalScore += 10 ; continue ; } if ( ! $ countOpponentMoves && $ countPlayerMoves == 1 ) { $ totalScore += 2 ; continue ; } if ( ! $ countOpponentMoves && ! $ countPlayerMoves ) { $ totalScore ++ ; continue ; } } return $ totalScore ; }
Get the score of a move

@param int $player The player
@param array $position

@return int The overall rating (the higher the better)
Get the score of a move