diff --git a/src/icepool/evaluator/__init__.py b/src/icepool/evaluator/__init__.py index 197c82fe..c2f8bda5 100644 --- a/src/icepool/evaluator/__init__.py +++ b/src/icepool/evaluator/__init__.py @@ -19,7 +19,6 @@ from icepool.evaluator.constant import ConstantEvaluator from icepool.evaluator.keep import KeepEvaluator from icepool.evaluator.argsort import ArgsortEvaluator -from icepool.evaluator.compair import CompairEvalautor from icepool.evaluator.expression import ExpressionEvaluator __all__ = [ @@ -33,6 +32,5 @@ 'IsSubsetEvaluator', 'IsProperSubsetEvaluator', 'IsSupersetEvaluator', 'IsProperSupersetEvaluator', 'IsEqualSetEvaluator', 'IsNotEqualSetEvaluator', 'IsDisjointSetEvaluator', 'ConstantEvaluator', - 'KeepEvaluator', 'ArgsortEvaluator', 'CompairEvalautor', - 'ExpressionEvaluator' + 'KeepEvaluator', 'ArgsortEvaluator', 'ExpressionEvaluator' ] diff --git a/src/icepool/evaluator/compair.py b/src/icepool/evaluator/compair.py deleted file mode 100644 index f54a10d4..00000000 --- a/src/icepool/evaluator/compair.py +++ /dev/null @@ -1,81 +0,0 @@ -__docformat__ = 'google' - -import icepool -from icepool.evaluator.multiset_evaluator import MultisetEvaluator - -from abc import abstractmethod - -from icepool.typing import Order -from typing import Any, Hashable, Literal - - -class CompairEvalautor(MultisetEvaluator[Any, int]): - """Compares sorted pairs of two multisets and scores wins, ties, and extra elements. - - This can be used for e.g. RISK-like mechanics. - """ - - def __init__(self, - *, - order: Order = Order.Descending, - tie: int = 0, - left_greater: int = 0, - right_greater: int = 0): - """Compares sorted pairs of two multisets and scores wins, ties, and extra elements. - - For example, `left=1` would count how many pairs were won by the left - side, and `left=1, right=-1` would give the difference in the number of - pairs won by each side. - - Args: - order: If descending (default), pairs are made in descending order - and the higher element wins. If ascending, pairs are made in - ascending order and the lower element wins. - - tie: The score for each pair that is a tie. - left: The score for each pair that left has a higher outcome. - right: The score for each pair that right has a higher outcome. - """ - if order == Order.Any: - order = Order.Descending - self._order = order - - self._tie = tie - # Internally we find outcomes that were reached first. - # For ascending order this results in a swap. - if order < 0: - self._left = left_greater - self._right = right_greater - else: - self._left = right_greater - self._right = left_greater - - def next_state(self, state, _, left, right): - if left < 0 or right < 0: - raise ValueError('Negative counts not supported.') - # positive advantage favors left, negative favors right - score, advantage = state or (0, 0) - if advantage > 0: - # How many left wins. - wins = min(advantage, right) - score += wins * self._left - advantage -= wins - right -= wins - else: - # How many right wins. - wins = min(-advantage, left) - score += wins * self._right - advantage += wins - left -= wins - ties = min(left, right) - score += ties * self._tie - # Rest goes into advantage. - advantage += left - right - return score, advantage - - def final_outcome(self, final_state): - score, advantage = final_state or (0, 0) - return score - - def order(self) -> Order: - return self._order diff --git a/src/icepool/expression/multiset_expression.py b/src/icepool/expression/multiset_expression.py index 6a244de0..89b7dd4a 100644 --- a/src/icepool/expression/multiset_expression.py +++ b/src/icepool/expression/multiset_expression.py @@ -1234,153 +1234,3 @@ def isdisjoint( which both multisets have positive count, and `True` if there is not. """ return self._compare(other, icepool.evaluator.IsDisjointSetEvaluator) - - def compair_lt( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is < `other`. - - Any extra unpaired elements do not affect the result. - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=0, - left_greater=0, - right_greater=1)) - - def compair_le( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is <= `other`. - - Any extra unpaired elements do not affect the result. - - Example: number of armies destroyed by the defender in a - 3v2 attack in *RISK*: - ```python - d6.pool(3).compair_le(d6.pool(2)) - ``` - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=1, - left_greater=0, - right_greater=1)) - - def compair_gt( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is > `other`. - - Any extra unpaired elements do not affect the result. - - Example: number of armies destroyed by the attacker in a - 3v2 attack in *RISK*: - ```python - d6.pool(3).compair_gt(d6.pool(2)) - ``` - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=0, - left_greater=1, - right_greater=0)) - - def compair_ge( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is >= `other`. - - Any extra unpaired elements do not affect the result. - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=1, - left_greater=1, - right_greater=0)) - - def compair_eq( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is >= `other`. - - Any extra unpaired elements do not affect the result. - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=1, - left_greater=0, - right_greater=0)) - - def compair_ne( - self, - other: - 'MultisetExpression[T_contra] | Mapping[T_contra, int] | Sequence[T_contra]', - *, - order: Order = Order.Descending): - """Evaluation: EXPERIMENTAL: Compare pairs of elements in sorted order, counting how many pairs `self` is >= `other`. - - Any extra unpaired elements do not affect the result. - - Args: - other: The other multiset to compare. - order: Which order elements will be matched in. - Default is descending. - """ - other = implicit_convert_to_expression(other) - return self.evaluate(other, - evaluator=icepool.evaluator.CompairEvalautor( - order=order, - tie=0, - left_greater=1, - right_greater=1))