Skip to content

Commit

Permalink
option to protect both triples and tractors from pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
rbtying committed Jan 20, 2024
1 parent 38b820b commit 83a6049
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
2 changes: 2 additions & 0 deletions core/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ impl MessageVariant {
format!("{} protected longer tuples from being drawn out by shorter ones (pair does not draw triple)", n?),
TrickDrawPolicySet { policy: TrickDrawPolicy::OnlyDrawTractorOnTractor } =>
format!("{} protected tractors from being drawn out by non-tractors", n?),
TrickDrawPolicySet { policy: TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor } =>
format!("{} protected longer tuples from being drawn out by shorter ones, and tractors from being drawn out by non-tractors", n?),
ThrowEvaluationPolicySet { policy: ThrowEvaluationPolicy::All } =>
format!("{} set throws to be evaluated based on all of the cards", n?),
ThrowEvaluationPolicySet { policy: ThrowEvaluationPolicy::Highest } =>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/Credits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const contentStyle: React.CSSProperties = {
transform: "translate(-50%, -50%)",
};

const changeLogVersion: number = 22;
const changeLogVersion: number = 23;

const ChangeLog = (): JSX.Element => {
const [modalOpen, setModalOpen] = React.useState<boolean>(false);
Expand Down Expand Up @@ -66,6 +66,13 @@ const ChangeLog = (): JSX.Element => {
game
</li>
</ul>
<p>1/20/2024:</p>
<ul>
<li>
Added the ability to protect both longer tuples and tractors at the
same time.
</li>
</ul>
<p>2/24/2023:</p>
<ul>
<li>
Expand Down
73 changes: 69 additions & 4 deletions mechanics/src/trick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ pub enum TrickError {
pub enum TrickDrawPolicy {
#[default]
NoProtections,
/// Don't require longer tuples to be drawn if the original format was a
/// shorter tuple.
LongerTuplesProtected,
/// Only allow tractors to be drawn if the original format was also a tractor.
OnlyDrawTractorOnTractor,
/// Both `LongerTuplesProtected` and `OnlyDrawTractorOnTractor`
LongerTuplesProtectedAndOnlyDrawTractorOnTractor,
NoFormatBasedDraw,
}

Expand Down Expand Up @@ -205,7 +209,9 @@ impl TrickFormat {
std::iter::once_with(move || {
subsequent_decomposition_ordering(
adj_tuples,
trick_draw_policy != TrickDrawPolicy::OnlyDrawTractorOnTractor,
trick_draw_policy != TrickDrawPolicy::OnlyDrawTractorOnTractor
&& trick_draw_policy
!= TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor,
)
.into_iter()
.map(|requirements| {
Expand Down Expand Up @@ -899,7 +905,8 @@ impl UnitLike {
TrickDrawPolicy::NoFormatBasedDraw
| TrickDrawPolicy::NoProtections
| TrickDrawPolicy::OnlyDrawTractorOnTractor => true,
TrickDrawPolicy::LongerTuplesProtected => !matching
TrickDrawPolicy::LongerTuplesProtected
| TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor => !matching
.iter()
.any(|(card, count)| counts_.get(card).copied().unwrap_or_default() > *count),
};
Expand Down Expand Up @@ -1760,6 +1767,21 @@ mod tests {
&[S_3, S_3, S_5, S_5],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(!tf.is_legal_play(
&hand,
&[S_2, S_2, S_2, S_2],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_3, S_3],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_3, S_3, S_5, S_5],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_2, S_2],
Expand Down Expand Up @@ -1805,6 +1827,16 @@ mod tests {
&[S_2, S_2, S_5, S_5],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_2, S_2],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_5, S_5],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
// This play is tenuously legal, since the 2222 is protected by the 355 is not, and the
// trick-format is 2233. Normally we would expect that the 2233 is required, but the player
// has decided to break the 22 but *not* play the 55.
Expand Down Expand Up @@ -1843,6 +1875,16 @@ mod tests {
&[S_2, S_2, S_5],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_2],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_2, S_2, S_5],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
}

#[test]
Expand Down Expand Up @@ -1871,6 +1913,11 @@ mod tests {
&[S_5, S_5, S_6],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(tf.is_legal_play(
&hand,
&[S_5, S_5, S_6],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
assert!(!tf.is_legal_play(
&hand,
&[S_6, S_7, S_8],
Expand Down Expand Up @@ -1900,6 +1947,16 @@ mod tests {
&[S_5, S_6, S_7, S_8],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(!tf.is_legal_play(
&hand,
&[S_5, S_6, S_7, S_8],
TrickDrawPolicy::OnlyDrawTractorOnTractor
));
assert!(tf.is_legal_play(
&hand,
&[S_5, S_6, S_7, S_8],
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor
));
}

#[test]
Expand Down Expand Up @@ -1933,6 +1990,11 @@ mod tests {
&[S_3, S_5, S_10, S_J, S_Q],
TrickDrawPolicy::NoFormatBasedDraw
));
assert!(tf.is_legal_play(
&hand,
&[S_3, S_5, S_10, S_J, S_Q],
TrickDrawPolicy::LongerTuplesProtected
));
assert!(tf.is_legal_play(
&hand,
&[S_3, S_6, S_8, S_8, S_8],
Expand All @@ -1945,7 +2007,7 @@ mod tests {
));
assert!(tf.is_legal_play(
&hand,
&[S_3, S_5, S_10, S_J, S_Q],
&[S_3, S_6, S_8, S_8, S_8],
TrickDrawPolicy::LongerTuplesProtected
));
}
Expand Down Expand Up @@ -2001,6 +2063,8 @@ mod tests {
TrickDrawPolicy::NoProtections,
TrickDrawPolicy::LongerTuplesProtected,
TrickDrawPolicy::NoFormatBasedDraw,
TrickDrawPolicy::OnlyDrawTractorOnTractor,
TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor,
] {
let mut hands = Hands::new(vec![P1, P2, P3, P4]);

Expand Down Expand Up @@ -2035,7 +2099,8 @@ mod tests {
}
TrickDrawPolicy::LongerTuplesProtected
| TrickDrawPolicy::NoProtections
| TrickDrawPolicy::OnlyDrawTractorOnTractor => {
| TrickDrawPolicy::OnlyDrawTractorOnTractor
| TrickDrawPolicy::LongerTuplesProtectedAndOnlyDrawTractorOnTractor => {
// This play should not succeed, because P2 also has S_K, S_K which is a pair.
if let Err(TrickError::IllegalPlay) = trick.play_cards(pc!(
P2,
Expand Down

0 comments on commit 83a6049

Please sign in to comment.