-
-
Save grondilu/39bcb969f7aaca7c38ae2533a1289049 to your computer and use it in GitHub Desktop.
trying to reproduce an annoying warning in raku
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
unit module Chess; | |
subset file of Str where 'a'..'h'; | |
subset rank of Int where 1..8; | |
class Square { | |
has (file $.file, rank $.rank); | |
method up { self.new: :$!file, rank => $!rank.succ } | |
method down { self.new: :$!file, rank => $!rank.pred } | |
method left { self.new: :$!rank, file => $!file.pred } | |
method right { self.new: :$!rank, file => $!file.succ } | |
method Str { $!file ~ $!rank } | |
} | |
enum color <white black>; | |
role Piece[Str $symbol] { | |
has color $.color; | |
method steps {...} | |
method Str { $!color ~~ white ?? $symbol.uc !! $symbol.lc } | |
} | |
class Knight does Piece['n'] { | |
method steps { | |
*.up.up.right, *.up.up.left, | |
*.right.right.up, *.right.right.down, | |
*.left.left.up, *.left.left.down, | |
*.down.down.left, *.down.down.right | |
} | |
} | |
class Position { | |
has Piece %.pieces{Square}; | |
method moves { | |
gather for %!pieces { | |
my ($square, $piece) = .kv; | |
for $piece.steps -> $step { | |
my Square $to; | |
try { $to = $step($square); } | |
take $square => $to unless $! or %!pieces{$to}; | |
#unless $! { take $square => $to unless %!pieces{$to}; } | |
} | |
} | |
} | |
} | |
my $n = Knight.new: color => white; | |
my Piece %pieces{Square} = Square.new(:file<b>,:rank(1)), $n; | |
say Position.new(:%pieces).moves; | |
#`{{{ | |
(Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "c", rank => 3) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "a", rank => 3) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "d", rank => 2) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "d", rank => 0) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "a", rank => -1) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "c", rank => -1)) | |
WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was: | |
Decrement out of range | |
in method left at test.raku line 7 | |
in block at test.raku line 35 | |
in code at test.raku line 33 | |
in block <unit> at test.raku line 46 | |
(Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "c", rank => 3) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "a", rank => 3) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "d", rank => 2) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "d", rank => 0) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "a", rank => -1) Chess::Square.new(file => "b", rank => 1) => Chess::Square.new(file => "c", rank => -1)) | |
WARNING: unhandled Failure detected in DESTROY. If you meant to ignore it, you can mark it as handled by calling .Bool, .so, .not, or .defined methods. The Failure was: | |
Decrement out of range | |
in method left at test.raku line 7 | |
in block at test.raku line 35 | |
in code at test.raku line 33 | |
in block <unit> at test.raku line 46 | |
}}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment