From a3b618c45955c7263ef580d98353487518023bf3 Mon Sep 17 00:00:00 2001 From: unknown <191808663+UltraProcessor@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:55:51 -0600 Subject: [PATCH 1/3] Change side_side = get_sides(side)[direction] to optimized version --- src/checkers/state.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/checkers/state.py b/src/checkers/state.py index a888aae..f80b9e5 100644 --- a/src/checkers/state.py +++ b/src/checkers/state.py @@ -312,7 +312,17 @@ def get_jumps( continue # Get the tile beyond the jumped piece - side_side = get_sides(side)[direction] + DIRECTIONS = { + 0: (-1, -1), + 1: (1, -1), + 2: (-1, 1), + 3: (1, 1), + } + + # (old code below, revert if solution is less optimal) + # side_side = get_sides(side)[direction] + dx, dy = DIRECTIONS[direction] + side_side = (side[0] + dx, side[1] + dy) # Validate beyond tile if not self.valid_location(side_side): From bcb1af883305106b158a80c0723dddf831116894 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Wed, 10 Dec 2025 04:13:30 -0600 Subject: [PATCH 2/3] Use tuple instead of dict and make static (final) global instead of local --- src/checkers/state.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/checkers/state.py b/src/checkers/state.py index f80b9e5..aa19440 100644 --- a/src/checkers/state.py +++ b/src/checkers/state.py @@ -27,6 +27,7 @@ import math from dataclasses import dataclass from typing import ( + Final, TYPE_CHECKING, NamedTuple, TypeAlias, @@ -57,6 +58,13 @@ Pos: TypeAlias = tuple[u8, u8] +DIRECTIONS: Final = ( + (-1, -1), + (1, -1), + (-1, 1), + (1, 1), +) + class Action(NamedTuple): """Represents an action.""" @@ -312,15 +320,6 @@ def get_jumps( continue # Get the tile beyond the jumped piece - DIRECTIONS = { - 0: (-1, -1), - 1: (1, -1), - 2: (-1, 1), - 3: (1, 1), - } - - # (old code below, revert if solution is less optimal) - # side_side = get_sides(side)[direction] dx, dy = DIRECTIONS[direction] side_side = (side[0] + dx, side[1] + dy) From d1b65d8d92142d8cb8216dc370da464f707949dc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 10 Dec 2025 10:13:39 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/checkers/state.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/checkers/state.py b/src/checkers/state.py index aa19440..4cbe145 100644 --- a/src/checkers/state.py +++ b/src/checkers/state.py @@ -27,8 +27,8 @@ import math from dataclasses import dataclass from typing import ( - Final, TYPE_CHECKING, + Final, NamedTuple, TypeAlias, TypeVar, @@ -65,6 +65,7 @@ (1, 1), ) + class Action(NamedTuple): """Represents an action."""