Пример #1
0
 /**
  * Get the response based on a probability to cooperate
  *
  * The probability should be passed in as a callable that accepts one argument that acts as
  * the coefficient for the formula
  *
  * @param callable $getProbability
  * @return ResponseEnum
  */
 private function getResponseByChanceToCooperate(callable $getProbability)
 {
     $probability = $getProbability(self::PROBABILITY_COEFFICIENT);
     $max = 1 / $probability;
     $shouldCooperate = mt_rand(1, $max) === 1;
     return $shouldCooperate ? ResponseEnum::create(ResponseEnum::COOPERATE) : ResponseEnum::create(ResponseEnum::CONFESS);
 }
Пример #2
0
 /**
  * @inheritDoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $partnerPreviousResponse = null;
     $playerPreviousResponse = null;
     if (null !== $input->getArgument(self::PARTNER_PREVIOUS_RESPONSE)) {
         $partnerPreviousResponse = ResponseEnum::create($input->getArgument(self::PARTNER_PREVIOUS_RESPONSE));
     }
     if (null !== $input->getArgument(self::PLAYER_PREVIOUS_RESPONSE)) {
         $playerPreviousResponse = ResponseEnum::create($input->getArgument(self::PLAYER_PREVIOUS_RESPONSE));
     }
     $response = $this->responseProvider->getResponse($partnerPreviousResponse, $playerPreviousResponse);
     $output->writeln((string) $response);
 }