Files
trueskill/src/Player.php

63 lines
2.1 KiB
PHP
Raw Normal View History

2022-07-05 15:55:47 +02:00
<?php
declare(strict_types=1);
2022-07-05 15:55:47 +02:00
namespace DNW\Skills;
/**
* Represents a player who has a Rating.
*/
2024-03-19 14:10:19 +00:00
class Player implements ISupportPartialPlay, ISupportPartialUpdate
{
private const DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time
2022-07-05 15:55:47 +02:00
private const DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0;
2022-07-05 15:55:47 +02:00
private readonly float $PartialPlayPercentage;
2022-07-05 15:55:47 +02:00
private readonly float $PartialUpdatePercentage;
/**
* Constructs a player.
*
2024-03-19 14:10:19 +00:00
* @param mixed $Id The identifier for the player, such as a name.
2023-08-02 10:10:57 +00:00
* @param float $partialPlayPercentage The weight percentage to give this player when calculating a new rank.
* @param float $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
*/
2023-08-01 13:53:19 +00:00
public function __construct(
private readonly mixed $Id,
2023-08-02 10:10:57 +00:00
float $partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE,
float $partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE
)
{
2022-07-05 15:55:47 +02:00
Guard::argumentInRangeInclusive($partialPlayPercentage, 0.0, 1.0, 'partialPlayPercentage');
Guard::argumentInRangeInclusive($partialUpdatePercentage, 0, 1.0, 'partialUpdatePercentage');
$this->PartialPlayPercentage = $partialPlayPercentage;
$this->PartialUpdatePercentage = $partialUpdatePercentage;
}
/**
* The identifier for the player, such as a name.
*/
2023-08-02 10:10:57 +00:00
public function getId(): mixed
{
return $this->Id;
}
/**
* Indicates the percent of the time the player should be weighted where 0.0 indicates the player didn't play and 1.0 indicates the player played 100% of the time.
*/
2023-08-02 10:10:57 +00:00
public function getPartialPlayPercentage(): float
{
return $this->PartialPlayPercentage;
}
/**
* Indicated how much of a skill update a player should receive where 0.0 represents no update and 1.0 represents 100% of the update.
*/
2023-08-02 10:10:57 +00:00
public function getPartialUpdatePercentage(): float
{
return $this->PartialUpdatePercentage;
}
2022-07-05 15:55:47 +02:00
}