Skip to content

Commit 9a03291

Browse files
committedMar 17, 2019
Initial implementation of Turkish rules.
refs #26.
1 parent f7f5252 commit 9a03291

14 files changed

+281
-52
lines changed
 

‎python/hcheckers/common.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ def get_ok_button(self):
237237
("brazilian", _("Brazilian draughts")),
238238
("canadian", _("Canadian draughts")),
239239
("spancirety", _("Spancirety draughts")),
240-
("diagonal", _("Diagonal draughts"))
240+
("diagonal", _("Diagonal draughts")),
241+
("turkish", _("Turkish draughts"))
241242
]
242243

243244
rules_dict = dict(supported_rules)

‎src/Core/Board.hs

+88-35
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ boardDirection Bottom ForwardLeft = UpLeft
7373
boardDirection Bottom ForwardRight = UpRight
7474
boardDirection Bottom BackwardLeft = DownLeft
7575
boardDirection Bottom BackwardRight = DownRight
76+
boardDirection Bottom Forward = Up
77+
boardDirection Bottom Backward = Down
7678
boardDirection Top ForwardLeft = DownRight
7779
boardDirection Top ForwardRight = DownLeft
7880
boardDirection Top BackwardLeft = UpRight
7981
boardDirection Top BackwardRight = UpLeft
82+
boardDirection Top Backward = Up
83+
boardDirection Top Forward = Down
84+
boardDirection _ PRight = ToRight
85+
boardDirection _ PLeft = ToLeft
8086

8187
boardSide :: BoardOrientation -> Side -> BoardSide
8288
boardSide FirstAtBottom First = Bottom
@@ -98,22 +104,36 @@ playerDirection First UpLeft = ForwardLeft
98104
playerDirection First UpRight = ForwardRight
99105
playerDirection First DownLeft = BackwardLeft
100106
playerDirection First DownRight = BackwardRight
107+
playerDirection First Up = Forward
108+
playerDirection First Down = Backward
101109
playerDirection Second UpLeft = BackwardRight
102110
playerDirection Second UpRight = BackwardLeft
103111
playerDirection Second DownLeft = ForwardRight
104112
playerDirection Second DownRight = ForwardLeft
113+
playerDirection Second Down = Forward
114+
playerDirection Second Up = Backward
115+
playerDirection _ ToRight = PRight
116+
playerDirection _ ToLeft = PLeft
105117

106118
oppositeDirection :: PlayerDirection -> PlayerDirection
107119
oppositeDirection ForwardLeft = BackwardRight
108120
oppositeDirection ForwardRight = BackwardLeft
109121
oppositeDirection BackwardLeft = ForwardRight
110122
oppositeDirection BackwardRight = ForwardLeft
123+
oppositeDirection Forward = Backward
124+
oppositeDirection Backward = Forward
125+
oppositeDirection PRight = PLeft
126+
oppositeDirection PLeft = PRight
111127

112128
neighbour :: BoardDirection -> Address -> Maybe Address
113129
neighbour UpLeft a = aUpLeft a
114130
neighbour UpRight a = aUpRight a
115131
neighbour DownLeft a = aDownLeft a
116132
neighbour DownRight a = aDownRight a
133+
neighbour Up a = aUp a
134+
neighbour ToRight a = aRight a
135+
neighbour Down a = aDown a
136+
neighbour ToLeft a = aLeft a
117137

118138
myNeighbour :: HasBoardOrientation rules => rules -> Side -> PlayerDirection -> Address -> Maybe Address
119139
myNeighbour rules side dir a = neighbour (myDirection rules side dir) a
@@ -124,6 +144,10 @@ getNeighbourDirection src dst
124144
| aUpRight src == Just dst = Just UpRight
125145
| aDownLeft src == Just dst = Just DownLeft
126146
| aDownRight src == Just dst = Just DownRight
147+
| aUp src == Just dst = Just Up
148+
| aRight src == Just dst = Just ToRight
149+
| aDown src == Just dst = Just Down
150+
| aLeft src == Just dst = Just ToLeft
127151
| otherwise = Nothing
128152

129153
getNeighbourDirection' :: Board -> Address -> Label -> Maybe BoardDirection
@@ -432,33 +456,6 @@ kingMove side src dir n = Move src $ replicate n (Step dir False False)
432456
firstMoveDirection :: Move -> PlayerDirection
433457
firstMoveDirection move = sDirection $ head $ moveSteps move
434458

435-
makeLine :: [Label] -> [Address]
436-
makeLine labels = map (\l -> Address l Nothing Nothing Nothing Nothing Nothing) labels
437-
438-
line1labels :: [Label]
439-
line1labels = ["a1", "c1", "e1", "g1"]
440-
441-
line2labels :: [Label]
442-
line2labels = ["b2", "d2", "f2", "h2"]
443-
444-
line3labels :: [Label]
445-
line3labels = ["a3", "c3", "e3", "g3"]
446-
447-
line4labels :: [Label]
448-
line4labels = ["b4", "d4", "f4", "h4"]
449-
450-
line5labels :: [Label]
451-
line5labels = ["a5", "c5", "e5", "g5"]
452-
453-
line6labels :: [Label]
454-
line6labels = ["b6", "d6", "f6", "h6"]
455-
456-
line7labels :: [Label]
457-
line7labels = ["a7", "c7", "e7", "g7"]
458-
459-
line8labels :: [Label]
460-
line8labels = ["b8", "d8", "f8", "h8"]
461-
462459
calcBoardHash :: Board -> BoardHash
463460
calcBoardHash board = foldr update 0 (boardAssocs board)
464461
where
@@ -473,11 +470,24 @@ updateBoardHash :: Board -> Label -> Piece -> BoardHash
473470
updateBoardHash board label piece =
474471
updateBoardHash' (randomTable board) (boardHash board) label piece
475472

476-
buildBoard :: RandomTableProvider rnd => rnd -> BoardOrientation -> BoardSize -> Board
477-
buildBoard rnd orient bsize@(nrows, ncols) =
478-
let mkAddress p = Address (label p) (promote p) (upLeft p) (upRight p) (downLeft p) (downRight p)
473+
buildBoard :: (RandomTableProvider rnd, HasTopology rules) => rnd -> rules -> BoardOrientation -> BoardSize -> Board
474+
buildBoard rnd rules orient bsize@(nrows, ncols) =
475+
let mkAddress p = Address {
476+
aLabel = label p
477+
, aPromotionSide = promote p
478+
, aUpLeft = upLeft p
479+
, aUpRight = upRight p
480+
, aDownLeft = downLeft p
481+
, aDownRight = downRight p
482+
, aUp = up p
483+
, aRight = right p
484+
, aDown = down p
485+
, aLeft = left p
486+
}
479487
label (r,c) = Label (c-1) (r-1)
480488

489+
diagonal = boardTopology rules == Diagonal
490+
481491
promote (r,_)
482492
| r == 1 = Just $ playerSide orient Top
483493
| r == nrows = Just $ playerSide orient Bottom
@@ -499,11 +509,30 @@ buildBoard rnd orient bsize@(nrows, ncols) =
499509
| r-1 < 1 || c+1 > ncols = Nothing
500510
| otherwise = M.lookup (r-1, c+1) addresses
501511

512+
up (r,c)
513+
| r+1 > nrows = Nothing
514+
| otherwise = M.lookup (r+1, c) addresses
515+
516+
down (r,c)
517+
| r-1 < 1 = Nothing
518+
| otherwise = M.lookup (r-1, c) addresses
519+
520+
right (r,c)
521+
| c+1 > ncols = Nothing
522+
| otherwise = M.lookup (r, c+1) addresses
523+
524+
left (r,c)
525+
| c-1 < 1 = Nothing
526+
| otherwise = M.lookup (r, c-1) addresses
527+
502528
addresses = M.fromList [(p, mkAddress p) | p <- coordinates]
503529

504530
odds n = [1, 3 .. n]
505531
evens n = [2, 4 .. n]
506-
coordinates = [(r, c) | r <- odds nrows, c <- odds ncols] ++ [(r, c) | r <- evens nrows, c <- evens ncols]
532+
533+
coordinates
534+
| diagonal = [(r, c) | r <- odds nrows, c <- odds ncols] ++ [(r, c) | r <- evens nrows, c <- evens ncols]
535+
| otherwise = [(r, c) | r <- [1..nrows], c <- [1..ncols]]
507536

508537
addressByLabel = buildLabelMap nrows ncols [(label p, address) | (p, address) <- M.assocs addresses]
509538

@@ -612,9 +641,33 @@ setManyPieces addresses piece board = foldr (\a b -> setPiece a piece b) board a
612641
setManyPieces' :: [Label] -> Piece -> Board -> Board
613642
setManyPieces' labels piece board = foldr (\l b -> setPiece' l piece b) board labels
614643

615-
board8 :: RandomTableProvider rnd => rnd -> Board
616-
board8 rnd =
617-
let board = buildBoard rnd FirstAtBottom (8, 8)
644+
line1labels :: [Label]
645+
line1labels = ["a1", "c1", "e1", "g1"]
646+
647+
line2labels :: [Label]
648+
line2labels = ["b2", "d2", "f2", "h2"]
649+
650+
line3labels :: [Label]
651+
line3labels = ["a3", "c3", "e3", "g3"]
652+
653+
line4labels :: [Label]
654+
line4labels = ["b4", "d4", "f4", "h4"]
655+
656+
line5labels :: [Label]
657+
line5labels = ["a5", "c5", "e5", "g5"]
658+
659+
line6labels :: [Label]
660+
line6labels = ["b6", "d6", "f6", "h6"]
661+
662+
line7labels :: [Label]
663+
line7labels = ["a7", "c7", "e7", "g7"]
664+
665+
line8labels :: [Label]
666+
line8labels = ["b8", "d8", "f8", "h8"]
667+
668+
board8 :: (RandomTableProvider rnd, HasTopology rules) => rnd -> rules -> Board
669+
board8 rnd rules =
670+
let board = buildBoard rnd rules FirstAtBottom (8, 8)
618671
labels1 = line1labels ++ line2labels ++ line3labels
619672
labels2 = line8labels ++ line7labels ++ line6labels
620673
in setManyPieces' labels1 (Piece Man First) $ setManyPieces' labels2 (Piece Man Second) board
@@ -660,7 +713,7 @@ boardRep :: Board -> BoardRep
660713
boardRep board = BoardRep $ boardAssocs board
661714

662715
parseBoardRep :: (GameRules rules, RandomTableProvider rnd) => rnd -> rules -> BoardRep -> Board
663-
parseBoardRep rnd rules (BoardRep list) = foldr set (buildBoard rnd orient bsize) list
716+
parseBoardRep rnd rules (BoardRep list) = foldr set (buildBoard rnd rules orient bsize) list
664717
where
665718
set (label, piece) board = setPiece' label piece board
666719
bsize = boardSize rules

‎src/Core/Supervisor.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import Rules.Brazilian
5151
import Rules.Canadian
5252
import Rules.Spancirety
5353
import Rules.Diagonal
54+
import Rules.Turkish
5455

5556
-- | Request for new game creation
5657
data NewGameRq = NewGameRq {
@@ -115,7 +116,8 @@ supportedRules =
115116
("brazilian", SomeRules brazilian),
116117
("canadian", SomeRules canadian),
117118
("spancirety", SomeRules spancirety),
118-
("diagonal", SomeRules diagonal)]
119+
("diagonal", SomeRules diagonal),
120+
("turkish", SomeRules turkish) ]
119121

120122
-- | Select rules by client request.
121123
selectRules :: NewGameRq -> Maybe SomeRules

‎src/Core/Types.hs

+25-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ data Address = Address {
139139
aUpLeft :: Maybe Address,
140140
aUpRight :: Maybe Address,
141141
aDownLeft :: Maybe Address,
142-
aDownRight :: Maybe Address
142+
aDownRight :: Maybe Address,
143+
aUp :: Maybe Address,
144+
aRight :: Maybe Address,
145+
aDown :: Maybe Address,
146+
aLeft :: Maybe Address
143147
}
144148
deriving (Typeable)
145149

@@ -239,27 +243,37 @@ type TBoardMap a = SM.Map BoardHash a
239243
data BoardDirection =
240244
UpLeft | UpRight
241245
| DownLeft | DownRight
246+
| Up | ToRight | Down | ToLeft
242247
deriving (Eq, Generic, Typeable)
243248

244249
instance Show BoardDirection where
245250
show UpLeft = "UL"
246251
show UpRight = "UR"
247252
show DownLeft = "DL"
248253
show DownRight = "DR"
254+
show Up = "U"
255+
show ToRight = "R"
256+
show Down = "D"
257+
show ToLeft = "L"
249258

250259
-- | Direction from a point of view of a player.
251260
-- For example, for white, B2 is at ForwardRight of A1;
252261
-- for black, B2 is at BackwardLeft of A1.
253262
data PlayerDirection =
254263
ForwardLeft | ForwardRight
255264
| BackwardLeft | BackwardRight
265+
| Forward | PRight | Backward | PLeft
256266
deriving (Eq, Ord, Generic, Typeable)
257267

258268
instance Show PlayerDirection where
259269
show ForwardLeft = "FL"
260270
show ForwardRight = "FR"
261271
show BackwardLeft = "BL"
262272
show BackwardRight = "BR"
273+
show Forward = "F"
274+
show PRight = "R"
275+
show Backward = "B"
276+
show PLeft = "L"
263277

264278
-- | One step of the move is a movement of piece
265279
-- from one field to it's neighbour. At that moment
@@ -395,8 +409,17 @@ class HasBoardOrientation a where
395409
boardOrientation :: a -> BoardOrientation
396410
boardOrientation _ = FirstAtBottom
397411

412+
data BoardTopology =
413+
Diagonal
414+
| Orthogonal
415+
| DiagonalAndOrthogonal
416+
deriving (Eq, Show, Typeable)
417+
418+
class HasTopology a where
419+
boardTopology :: a -> BoardTopology
420+
398421
-- | Interface of game rules
399-
class (Typeable g, Show g, HasBoardOrientation g) => GameRules g where
422+
class (Typeable g, Show g, HasBoardOrientation g, HasTopology g) => GameRules g where
400423
-- | Initial board with initial pieces position
401424
initBoard :: SupervisorState -> g -> Board
402425
-- | Size of board used

‎src/Main.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ special cmd args =
5959
withCheckers cmd $ do
6060
sh <- asks csSupervisor
6161
st <- liftIO $ atomically $ readTVar sh
62-
let b = movePiece' "c3" "e5" $ board8 st
62+
let b = movePiece' "c3" "e5" $ board8 st russian
6363
b' = flipBoard b
6464
b'' = flipBoard b'
6565
liftIO $ do

‎src/Rules/Brazilian.hs

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import Rules.Russian
1515
newtype Brazilian = Brazilian GenericRules
1616
deriving (Typeable, HasBoardOrientation)
1717

18+
instance HasTopology Brazilian where
19+
boardTopology _ = Diagonal
20+
1821
instance Show Brazilian where
1922
show = rulesName
2023

‎src/Rules/Canadian.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ newtype Canadian = Canadian GenericRules
1717
instance Show Canadian where
1818
show = rulesName
1919

20+
instance HasTopology Canadian where
21+
boardTopology _ = Diagonal
22+
2023
instance GameRules Canadian where
2124
boardSize _ = (12, 12)
2225

2326
initBoard rnd r =
24-
let board = buildBoard rnd (boardOrientation r) (12, 12)
27+
let board = buildBoard rnd r (boardOrientation r) (12, 12)
2528
labels1 = ["a1", "c1", "e1", "g1", "i1", "k1",
2629
"b2", "d2", "f2", "h2", "j2", "l2",
2730
"a3", "c3", "e3", "g3", "i3", "k3",

‎src/Rules/Diagonal.hs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE DeriveDataTypeable #-}
33
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4-
module Rules.Diagonal (Diagonal, diagonal) where
4+
module Rules.Diagonal (DiagonalRussian, diagonal) where
55

66
import Data.Typeable
77

@@ -11,15 +11,18 @@ import Core.Evaluator
1111
import Rules.Russian
1212
import Rules.Generic
1313

14-
newtype Diagonal = Diagonal GenericRules
14+
newtype DiagonalRussian = DiagonalRussian GenericRules
1515
deriving (Typeable, HasBoardOrientation)
1616

17-
instance Show Diagonal where
17+
instance Show DiagonalRussian where
1818
show = rulesName
1919

20-
instance GameRules Diagonal where
20+
instance HasTopology DiagonalRussian where
21+
boardTopology _ = Core.Types.Diagonal
22+
23+
instance GameRules DiagonalRussian where
2124
initBoard rnd r =
22-
let board = buildBoard rnd (boardOrientation r) (8, 8)
25+
let board = buildBoard rnd r (boardOrientation r) (8, 8)
2326
labels1 = ["c1", "e1", "g1",
2427
"d2", "f2", "h2",
2528
"e3", "g3",
@@ -53,8 +56,8 @@ instance GameRules Diagonal where
5356

5457
pdnId _ = "42"
5558

56-
diagonal :: Diagonal
57-
diagonal = Diagonal $
59+
diagonal :: DiagonalRussian
60+
diagonal = DiagonalRussian $
5861
let rules = russianBase rules
5962
in rules
6063

‎src/Rules/English.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ newtype English = English GenericRules
1919
instance Show English where
2020
show = rulesName
2121

22+
instance HasTopology English where
23+
boardTopology _ = Diagonal
24+
2225
instance GameRules English where
2326
boardSize _ = boardSize Russian.russian
2427

2528
initBoard rnd r =
26-
let board = buildBoard rnd (boardOrientation r) (boardSize r)
29+
let board = buildBoard rnd r (boardOrientation r) (boardSize r)
2730
labels1 = line1labels ++ line2labels ++ line3labels
2831
labels2 = line8labels ++ line7labels ++ line6labels
2932
in setManyPieces' labels1 (Piece Man Second) $ setManyPieces' labels2 (Piece Man First) board

‎src/Rules/International.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ newtype International = International GenericRules
2020
instance Show International where
2121
show = rulesName
2222

23+
instance HasTopology International where
24+
boardTopology _ = Diagonal
25+
2326
instance GameRules International where
2427
boardSize _ = (10, 10)
2528

2629
initBoard rnd r =
27-
let board = buildBoard rnd (boardOrientation r) (10, 10)
30+
let board = buildBoard rnd r (boardOrientation r) (10, 10)
2831
labels1 = ["a1", "c1", "e1", "g1", "i1",
2932
"b2", "d2", "f2", "h2", "j2",
3033
"a3", "c3", "e3", "g3", "i3",

‎src/Rules/Russian.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ newtype Russian = Russian GenericRules
2020
instance Show Russian where
2121
show = rulesName
2222

23+
instance HasTopology Russian where
24+
boardTopology _ = Diagonal
25+
2326
instance GameRules Russian where
24-
initBoard rnd _ = board8 rnd
27+
initBoard rnd r = board8 rnd r
2528

2629
boardSize _ = (8, 8)
2730

‎src/Rules/Simple.hs

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ newtype Simple = Simple GenericRules
1818
instance Show Simple where
1919
show = rulesName
2020

21+
instance HasTopology Simple where
22+
boardTopology _ = Diagonal
23+
2124
instance GameRules Simple where
2225
initBoard rnd _ = initBoard rnd Russian.russian
2326
boardSize _ = boardSize Russian.russian

‎src/Rules/Spancirety.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ newtype Spancirety = Spancirety GenericRules
1717
instance Show Spancirety where
1818
show = rulesName
1919

20+
instance HasTopology Spancirety where
21+
boardTopology _ = Diagonal
22+
2023
instance GameRules Spancirety where
2124
initBoard rnd r =
22-
let board = buildBoard rnd (boardOrientation r) (8, 10)
25+
let board = buildBoard rnd r (boardOrientation r) (8, 10)
2326
labels1 = ["a1", "c1", "e1", "g1", "i1",
2427
"b2", "d2", "f2", "h2", "j2",
2528
"a3", "c3", "e3", "g3", "i3"]

‎src/Rules/Turkish.hs

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE DeriveDataTypeable #-}
3+
{-# LANGUAGE RecordWildCards #-}
4+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+
module Rules.Turkish (
6+
Turkish, turkish, turkishBase
7+
) where
8+
9+
import Data.Typeable
10+
11+
import Core.Types
12+
import Core.Board
13+
import Core.BoardMap
14+
import Core.Evaluator
15+
import Rules.Generic
16+
17+
newtype Turkish = Turkish GenericRules
18+
deriving (Typeable, HasBoardOrientation)
19+
20+
instance Show Turkish where
21+
show = rulesName
22+
23+
instance HasTopology Turkish where
24+
boardTopology _ = Orthogonal
25+
26+
instance GameRules Turkish where
27+
initBoard rnd r =
28+
let board = buildBoard rnd r (boardOrientation r) (8, 8)
29+
labels1 = ["a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
30+
"a3", "b3", "c3", "d3", "e3", "f3", "g3", "h3"]
31+
labels2 = ["a7", "b7", "c7", "d7", "e7", "f7", "g7", "h7",
32+
"a6", "b6", "c6", "d6", "e6", "f6", "g6", "h6"]
33+
in setManyPieces' labels1 (Piece Man First) $ setManyPieces' labels2 (Piece Man Second) board
34+
35+
boardSize _ = (8, 8)
36+
37+
dfltEvaluator r = SomeEval $ defaultEvaluator r
38+
39+
boardNotation _ = chessNotation
40+
41+
parseNotation _ = parseChessNotation
42+
43+
rulesName _ = "turkish"
44+
45+
possibleMoves (Turkish rules) side board = gPossibleMoves rules side board
46+
47+
updateRules r _ = r
48+
49+
getGameResult = genericGameResult
50+
51+
pdnId _ = "43"
52+
53+
turkishBase :: GenericRules -> GenericRules
54+
turkishBase =
55+
let rules this = (abstractRules this) {
56+
gManSimpleMoveDirections = [PLeft, Forward, PRight]
57+
, gManCaptureDirections = [PLeft, Forward, PRight]
58+
, gKingCaptureDirections = [Backward, PLeft, Forward, PRight]
59+
, gManCaptures = manCaptures this
60+
, gManCaptures1 = manCaptures1 this
61+
, gCaptureMax = True
62+
}
63+
in rules
64+
65+
turkish :: Turkish
66+
turkish = Turkish $
67+
let rules = turkishBase rules
68+
in rules
69+
70+
manCaptures :: GenericRules -> CaptureState -> [PossibleMove]
71+
manCaptures rules ct@(CaptureState {..}) =
72+
let side = pieceSide ctPiece
73+
captures = manCaptures1 rules ct
74+
-- when last horizontal reached, pass non-promoted piece to
75+
-- next moves check; man can capture backward, so it will
76+
-- continue capture as a man if it can.
77+
nextMoves pm = genericNextMoves rules ct False pm
78+
in concat $ flip map captures $ \capture ->
79+
let [move1] = translateCapture ctPiece capture
80+
moves2 = nextMoves move1
81+
in if null moves2
82+
then [move1]
83+
else [catPMoves move1 move2 | move2 <- moves2]
84+
85+
manCaptures1 :: GenericRules -> CaptureState -> [Capture]
86+
manCaptures1 rules ct@(CaptureState {..}) =
87+
concatMap (check ctCurrent) $ filter allowedDir (gManCaptureDirections rules)
88+
where
89+
side = pieceSide ctPiece
90+
91+
allowedDir dir =
92+
case ctPrevDirection of
93+
Nothing -> True
94+
Just prevDir -> oppositeDirection prevDir /= dir
95+
96+
check a dir =
97+
case myNeighbour rules side dir a of
98+
Just victimAddr {- | not (aLabel victimAddr `labelSetMember` ctCaptured) -} ->
99+
case getPiece victimAddr ctBoard of
100+
Nothing -> []
101+
Just victim ->
102+
if isMyPiece side victim
103+
then []
104+
else case myNeighbour rules side dir victimAddr of
105+
Nothing -> []
106+
Just freeAddr ->
107+
if isFree freeAddr ctBoard
108+
then let captured' = insertLabelSet (aLabel victimAddr) ctCaptured
109+
next = ct {
110+
ctPrevDirection = Just dir,
111+
ctCaptured = captured',
112+
ctCurrent = freeAddr
113+
}
114+
in [Capture {
115+
cSrc = a,
116+
cDirection = dir,
117+
cInitSteps = 0,
118+
cFreeSteps = 1,
119+
cVictim = victimAddr,
120+
cDst = freeAddr,
121+
cPromote = isLastHorizontal side freeAddr &&
122+
not (gCanCaptureFrom rules next)
123+
}]
124+
else []
125+
_ -> []
126+

0 commit comments

Comments
 (0)
Please sign in to comment.