Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cu268hafe
lsgm
Commits
7088eea5
Commit
7088eea5
authored
Oct 08, 2021
by
christof
Browse files
minichess
parent
26b65913
Changes
1
Hide whitespace changes
Inline
Side-by-side
minichess.raku
0 → 100644
View file @
7088eea5
## https://www.ostwaldgymnasium.de/index.php/aktuell/wettbewerbe/2078-denken-lohnt-sich-10-21
## Die Bedrohungen der einzelnen Figuren, ausgehend von ihrer aktuellen Position
## (nur valide für minichess)
my %threats = (king => [[-1,-1],[-1,1],[1,1],[1,-1], [0,1], [0,-1], [1,0], [-1,0]],
queen => [[-1,-1],[-1,1],[1,1],[1,-1], [0,1], [0,-1], [1,0], [-1,0]],
rook => [[0,1], [0,-1], [1,0], [2,0],[-1,0], [-2,0]],
bishop => [[1,1], [-1,1],[1,-1],[-1,-1]],
knight => [[2,1], [-2,-1], [-2,1], [2,-1]],
pawn => [[1,1], [-1,1]]);
## Anzahl der Bedrohungen auf den Feldern ("11" -> Feld x=1, y=1)
## my %target-threats = ("11" => 1, "21" => 1, "31" => 2, "12" => 2, "22" => 1);
my %target-threats = ("11" => 2, "21" => 2, "31" => 2, "12" => 2, "22" => 2, "32" => 2);
for ([1,2,3] X [1,2]).combinations(3) -> @positions {
## für alle 3er Kombinationen von Positionen
for ("king", "queen", "rook" xx 2, "bishop" xx 2, "knight" xx 2, "pawn" xx 3)
.flat.combinations(3).unique(:with(&[eqv])) -> @pieces {
## für alle 3er Kombinationen von Figuren (gleiche rausfiltern)
my %sum-threats = ();
for @positions Z @pieces -> [@pos, $piece] {
## die bedrohungen auf die aktuelle Position addieren, und Positionen außerhalb des Spielfeldes herausfiltern
for %threats{$piece}.map({ $_ «+» @pos }).grep({ (0 < .[0] < 4) && (0 < .[1] < 3) }) -> @tpos {
## Die Bedrohung zu dem bedrohten Feld addieren
%sum-threats{ @tpos.join }++;
}
}
if (%target-threats eqv %sum-threats) {
## Falls alle Bedrohungen übereinstimmen, Belegung ausgeben
say @positions Z @pieces;
}
}
}
## Ausgabe: (((1 1) rook) ((2 1) rook) ((3 1) knight))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment