-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Only suggest moves for the active color for a position instead o…
…f for both Fixes #5
- Loading branch information
Showing
5 changed files
with
161 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
from typing import NewType | ||
from typing import NewType, Union, Literal | ||
|
||
|
||
TpsSymmetry = NewType("TpsSymmetry", int) | ||
TpsString = NewType("TpsString", str) # with xn collapsed (x,x,x,... -> xn) | ||
TpsStringExpanded = NewType("TpsStringExpanded", str) # with xn expanded to x,x,x... | ||
NormalizedTpsString = NewType("NormalizedTpsString", str) | ||
BoardSize = NewType("BoardSize", int) | ||
PlayerToMove = Union[Literal["white"], Literal["black"]] | ||
|
||
def color_to_place_from_tps(tps: str) -> PlayerToMove: | ||
""" | ||
The color of the next piece to place. | ||
After move 1 this equals the player that makes the move. | ||
""" | ||
[_tps_str, player_to_move, move_counter] = tps.split(" ") | ||
player_to_move = "white" if player_to_move == "1" else "black" | ||
if int(move_counter) == 1: # first move -> apply swap | ||
player_to_move = get_opponent(player_to_move) | ||
|
||
return player_to_move | ||
|
||
def get_opponent(player_to_move: PlayerToMove) -> PlayerToMove: | ||
if player_to_move == "black": | ||
return "white" | ||
return "black" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.