<commit_before><?php

namespace EM\Tests\PHPUnit\GameBundle\Service\AI;

use EM\GameBundle\Entity\Cell;
use EM\GameBundle\Model\CellModel;
use EM\GameBundle\Service\AI\AIStrategyProcessor;
use EM\GameBundle\Service\CoordinateSystem\PathProcessor;
use EM\Tests\Environment\IntegrationTestSuite;
use EM\Tests\Environment\MockFactory;

/**
 * @see AIStrategyProcessor
 */
class AIStrategyProcessorTest extends IntegrationTestSuite
{
    /**
     * @var AIStrategyProcessor
     */
    protected static $strategyProcessor;

    public static function setUpBeforeClass()
    {
        static::$strategyProcessor = static::$container->get('battleship_game.service.ai_strategy_processor');
    }

    /**
     * @see AIStrategyProcessor::processCoordinates
     * @test
     */
    public function processCoordinates()
    {
        $battlefield = MockFactory::getBattlefieldMock();
        $battlefield->getCellByCoordinate('B2')->setFlags(CellModel::FLAG_DEAD_SHIP);

        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        /** as battlefield is mocked having all cells STATE_WATER_LIVE state */
        $this->assertCount(4, $cells);
        $this->assertContainsOnlyInstancesOf(Cell::class, $cells);

        /** as LEFT (A1) cell is dead */
        $battlefield->getCellByCoordinate('A2')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(3, $cells);

        /** as entire horizontal row is dead (A1-J10) cell is dead */
        for ($letter = 'C'; $letter < 'G'; $letter++) {
            $battlefield->getCellByCoordinate("{$letter}2")->setFlags(CellModel::FLAG_DEAD_SHIP);
            $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
            $this->assertCount(3, $cells);
        }
        /** left for explanation purposes */
//        $battlefield->getCellByCoordinate('C2')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
//        ...
//        $battlefield->getCellByCoordinate('F2')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
        $battlefield->getCellByCoordinate('G2')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(2, $cells);

        /** as top (B1) cell is dead also */
        $battlefield->getCellByCoordinate('B1')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(1, $cells);

        /** as vertical (B1-B10) and horizontal (A1-J10) rows contains only dead cells */
        for ($digit = 3; $digit < 7; $digit++) {
            $battlefield->getCellByCoordinate("B{$digit}")->setFlags(CellModel::FLAG_DEAD_SHIP);
            $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
            $this->assertCount(1, $cells);
        }
        /** left for explanation purposes */
//        $battlefield->getCellByCoordinate('B3')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
//        ...
//        $battlefield->getCellByCoordinate('B6')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
        $battlefield->getCellByCoordinate('B7')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertEmpty($cells);
    }

    private function invokeProcessPathsMethod(array $args) : array
    {
        return $this->invokeMethod(static::$strategyProcessor, 'processPaths', $args);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processCoordinates
     */
    public function processHorizontalStrategy()
    {
        $this->iterateCells(['A2', 'C2'], AIStrategyProcessor::STRATEGY_VERTICAL);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processCoordinates
     */
    public function processVerticalStrategy()
    {
        $this->iterateCells(['B1', 'B3'], AIStrategyProcessor::STRATEGY_VERTICAL);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processHorizontalStrategy<commit_msg>fix typo<commit_after><?php

namespace EM\Tests\PHPUnit\GameBundle\Service\AI;

use EM\GameBundle\Entity\Cell;
use EM\GameBundle\Model\CellModel;
use EM\GameBundle\Service\AI\AIStrategyProcessor;
use EM\GameBundle\Service\CoordinateSystem\PathProcessor;
use EM\Tests\Environment\IntegrationTestSuite;
use EM\Tests\Environment\MockFactory;

/**
 * @see AIStrategyProcessor
 */
class AIStrategyProcessorTest extends IntegrationTestSuite
{
    /**
     * @var AIStrategyProcessor
     */
    protected static $strategyProcessor;

    public static function setUpBeforeClass()
    {
        static::$strategyProcessor = static::$container->get('battleship_game.service.ai_strategy_processor');
    }

    /**
     * @see AIStrategyProcessor::processCoordinates
     * @test
     */
    public function processCoordinates()
    {
        $battlefield = MockFactory::getBattlefieldMock();
        $battlefield->getCellByCoordinate('B2')->setFlags(CellModel::FLAG_DEAD_SHIP);

        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        /** as battlefield is mocked having all cells STATE_WATER_LIVE state */
        $this->assertCount(4, $cells);
        $this->assertContainsOnlyInstancesOf(Cell::class, $cells);

        /** as LEFT (A1) cell is dead */
        $battlefield->getCellByCoordinate('A2')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(3, $cells);

        /** as entire horizontal row is dead (A1-J10) cell is dead */
        for ($letter = 'C'; $letter < 'G'; $letter++) {
            $battlefield->getCellByCoordinate("{$letter}2")->setFlags(CellModel::FLAG_DEAD_SHIP);
            $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
            $this->assertCount(3, $cells);
        }
        /** left for explanation purposes */
//        $battlefield->getCellByCoordinate('C2')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
//        ...
//        $battlefield->getCellByCoordinate('F2')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
        $battlefield->getCellByCoordinate('G2')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(2, $cells);

        /** as top (B1) cell is dead also */
        $battlefield->getCellByCoordinate('B1')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertCount(1, $cells);

        /** as vertical (B1-B10) and horizontal (A1-J10) rows contains only dead cells */
        for ($digit = 3; $digit < 7; $digit++) {
            $battlefield->getCellByCoordinate("B{$digit}")->setFlags(CellModel::FLAG_DEAD_SHIP);
            $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
            $this->assertCount(1, $cells);
        }
        /** left for explanation purposes */
//        $battlefield->getCellByCoordinate('B3')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
//        ...
//        $battlefield->getCellByCoordinate('B6')->setState($cellStates[CellModel::STATE_SHIP_DIED]);
        $battlefield->getCellByCoordinate('B7')->setFlags(CellModel::FLAG_DEAD_SHIP);
        $cells = $this->invokeProcessPathsMethod([$battlefield->getCellByCoordinate('B2'), PathProcessor::PRIMARY_PATHS]);
        $this->assertEmpty($cells);
    }

    private function invokeProcessPathsMethod(array $args) : array
    {
        return $this->invokeMethod(static::$strategyProcessor, 'processPaths', $args);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processCoordinates
     */
    public function processHorizontalStrategy()
    {
        $this->iterateCells(['A2', 'C2'], AIStrategyProcessor::STRATEGY_HORIZONTAL);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processCoordinates
     */
    public function processVerticalStrategy()
    {
        $this->iterateCells(['B1', 'B3'], AIStrategyProcessor::STRATEGY_VERTICAL);
    }

    /**
     * @see     AIStrategyProcessor::process
     * @test
     *
     * @depends processHorizontalStrategy
{'fraction_non_alphanumeric': 0.14822200066467264, 'fraction_numerical': 0.008862301982940069, 'mean_word_length': 3.6923076923076925, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823156', 'n_tokens_mistral': 2828, 'n_tokens_neox': 2701, 'n_words': 372}