Skip to content

Commit c63999d

Browse files
committed
Accidentially broke non-turkish rules :)
refs #26
1 parent 430d5bb commit c63999d

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/Rules/Generic.hs

+34-7
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,48 @@ abstractRules =
327327
cPromote = False
328328
}
329329

330+
-- Skip as many empty fields before piece to be captured, as we need
330331
search :: PlayerDirection -> Address -> Maybe (Address, Int)
331332
search dir a =
333+
-- make one step in given direction
332334
case myNeighbour rules side dir a of
335+
-- if there is no way in this direction (board border) - no capture possible
333336
Nothing -> Nothing
337+
-- otherwise check piece
334338
Just a' -> case getPiece a' ctBoard of
339+
-- empty field
340+
-- check the field after this one
335341
Nothing -> case search dir a' of
336342
Nothing -> Nothing
343+
-- found something
337344
Just (victimAddr, steps) -> Just (victimAddr, steps + 1)
338-
Just p -> if isOpponentPiece side p
339-
then if gRemoveCapturedImmediately rules && aLabel a' `labelSetMember` ctCaptured
340-
then case search dir a' of
341-
Nothing -> Nothing
342-
Just (victimAddr, steps) -> Just (victimAddr, steps+1)
343-
else Just (a', 0)
344-
else Nothing
345+
Just p ->
346+
-- the field is not empty
347+
if isOpponentPiece side p
348+
then let capturedPiece = aLabel a' `labelSetMember` ctCaptured
349+
skipCapturedPiece = gRemoveCapturedImmediately rules
350+
in if skipCapturedPiece
351+
-- In some (turkish) rules, pieces are removed from the field
352+
-- during capture. So if we already have captured this piece
353+
-- during this move, we must behave as there is no piece at all
354+
-- at this field.
355+
then if capturedPiece
356+
-- there is opponent piece, but we have already captured it
357+
-- (during this move).
358+
-- Just make another step through this field as if it was empty.
359+
then case search dir a' of
360+
Nothing -> Nothing
361+
Just (victimAddr, steps) -> Just (victimAddr, steps+1)
362+
-- piece was not captured yet, we can capture it now.
363+
else Just (a', 0)
364+
-- More usual rules: pieces are removed only when capture is complete.
365+
-- In this case, opponent piece that we already captured is an obstacle:
366+
-- we cannot capture it another time and we cannot step at this field.
367+
else if capturedPiece
368+
then Nothing
369+
else Just (a', 0)
370+
-- it is our piece, no capture
371+
else Nothing
345372

346373
-- This is most popular implementation, which fits most rules
347374
-- except for english / checkers

src/Rules/Russian.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ instance GameRules Russian where
4949

5050
russianBase :: GenericRules -> GenericRules
5151
russianBase =
52-
let rules this = abstractRules this {
52+
let rules this = (abstractRules this) {
5353
gManCaptures = manCaptures this
5454
}
5555
in rules

0 commit comments

Comments
 (0)