@@ -327,21 +327,48 @@ abstractRules =
327
327
cPromote = False
328
328
}
329
329
330
+ -- Skip as many empty fields before piece to be captured, as we need
330
331
search :: PlayerDirection -> Address -> Maybe (Address , Int )
331
332
search dir a =
333
+ -- make one step in given direction
332
334
case myNeighbour rules side dir a of
335
+ -- if there is no way in this direction (board border) - no capture possible
333
336
Nothing -> Nothing
337
+ -- otherwise check piece
334
338
Just a' -> case getPiece a' ctBoard of
339
+ -- empty field
340
+ -- check the field after this one
335
341
Nothing -> case search dir a' of
336
342
Nothing -> Nothing
343
+ -- found something
337
344
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
345
372
346
373
-- This is most popular implementation, which fits most rules
347
374
-- except for english / checkers
0 commit comments