Skip to content

Commit

Permalink
Fix is_point in ruleset.three_cushion (#173)
Browse files Browse the repository at this point in the history
* Correction of error for three cushion scoring points. Added test template.

* Added 10 test shots. Edited test_three_cushion.py. Test must be checked.

* Edited test_three_cushion.py: corrected import of System for is_point call. Added path to test shot.

* Edited test_three_cushion.py: corrected import of System for is_point call.

* fixed path to test shots, by Evan

* reformatted by pre-commit
  • Loading branch information
erdo100 authored Jan 4, 2025
1 parent cfee09e commit 899d667
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pooltool/ruleset/three_cushion.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ def is_point(shot: System) -> bool:
hit_ob_ids = set()
for event in cb_ob_collisions:
hit_ob_ids.add(_other(cue_id, event))

if len(hit_ob_ids) == 2:
# This is the first (and perhaps only) instance of the cue ball hitting the
# second object ball.
second_ob_collision = event
break
else:
# Both object balls were not contacted by the cue ball. No point.
return True
return False

# Both balls have been hit by the object ball. But were at least 3 cushions
# contacted before the second object ball was first hit? If yes, point, otherwise
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions tests/ruleset/test_three_cushion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from pathlib import Path

from pooltool.ruleset.three_cushion import is_point
from pooltool.system.datatypes import System

root = Path(__file__).parent


def test_three_cushion():
shot = System.load(root / "test_shots/01_test_shot_no_point.msgpack")
assert not is_point(shot)

shot = System.load(root / "test_shots/01a_test_shot_no_point.msgpack")
assert not is_point(shot)

shot = System.load(root / "test_shots/02_test_shot_ispoint.msgpack")
assert is_point(shot)

shot = System.load(root / "test_shots/02a_test_shot_ispoint.msgpack")
assert is_point(shot)

shot = System.load(root / "test_shots/03_test_shot_ispoint.msgpack")
assert is_point(shot)

shot = System.load(root / "test_shots/03a_test_shot_ispoint.msgpack")
assert is_point(shot)

shot = System.load(root / "test_shots/04_test_shot_no_point.msgpack")
assert not is_point(shot)

shot = System.load(root / "test_shots/04a_test_shot_no_point.msgpack")
assert not is_point(shot)

shot = System.load(root / "test_shots/05_test_shot_ispoint.msgpack")
assert is_point(shot)

shot = System.load(root / "test_shots/05a_test_shot_ispoint.msgpack")
assert is_point(shot)

0 comments on commit 899d667

Please sign in to comment.