Skip to content

Commit a210f23

Browse files
Sync queen-attack (#553)
* Sync queen-attack * format
1 parent 39ed3e1 commit a210f23

File tree

3 files changed

+42
-29
lines changed

3 files changed

+42
-29
lines changed

exercises/practice/queen-attack/.docs/instructions.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ A chessboard can be represented by an 8 by 8 array.
88

99
So if you are told the white queen is at `c5` (zero-indexed at column 2, row 3) and the black queen at `f2` (zero-indexed at column 5, row 6), then you know that the set-up is like so:
1010

11-
```text
12-
a b c d e f g h
13-
8 _ _ _ _ _ _ _ _ 8
14-
7 _ _ _ _ _ _ _ _ 7
15-
6 _ _ _ _ _ _ _ _ 6
16-
5 _ _ W _ _ _ _ _ 5
17-
4 _ _ _ _ _ _ _ _ 4
18-
3 _ _ _ _ _ _ _ _ 3
19-
2 _ _ _ _ _ B _ _ 2
20-
1 _ _ _ _ _ _ _ _ 1
21-
a b c d e f g h
22-
```
11+
![A chess board with two queens. Arrows emanating from the queen at c5 indicate possible directions of capture along file, rank and diagonal.](https://assets.exercism.org/images/exercises/queen-attack/queen-capture.svg)
2312

2413
You are also able to answer whether the queens can attack each other.
2514
In this case, that answer would be yes, they can, because both pieces share a diagonal.
15+
16+
## Credit
17+
18+
The chessboard image was made by [habere-et-dispertire][habere-et-dispertire] using LaTeX and the [chessboard package][chessboard-package] by Ulrike Fischer.
19+
20+
[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire
21+
[chessboard-package]: https://github.com/u-fischer/chessboard
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[3ac4f735-d36c-44c4-a3e2-316f79704203]
6-
description = "queen with a valid position"
13+
description = "Test creation of Queens with valid and invalid positions -> queen with a valid position"
714

815
[4e812d5d-b974-4e38-9a6b-8e0492bfa7be]
9-
description = "queen must have positive row"
16+
description = "Test creation of Queens with valid and invalid positions -> queen must have positive row"
1017

1118
[f07b7536-b66b-4f08-beb9-4d70d891d5c8]
12-
description = "queen must have row on board"
19+
description = "Test creation of Queens with valid and invalid positions -> queen must have row on board"
1320

1421
[15a10794-36d9-4907-ae6b-e5a0d4c54ebe]
15-
description = "queen must have positive column"
22+
description = "Test creation of Queens with valid and invalid positions -> queen must have positive column"
1623

1724
[6907762d-0e8a-4c38-87fb-12f2f65f0ce4]
18-
description = "queen must have column on board"
25+
description = "Test creation of Queens with valid and invalid positions -> queen must have column on board"
1926

2027
[33ae4113-d237-42ee-bac1-e1e699c0c007]
21-
description = "can not attack"
28+
description = "Test the ability of one queen to attack another -> cannot attack"
2229

2330
[eaa65540-ea7c-4152-8c21-003c7a68c914]
24-
description = "can attack on same row"
31+
description = "Test the ability of one queen to attack another -> can attack on same row"
2532

2633
[bae6f609-2c0e-4154-af71-af82b7c31cea]
27-
description = "can attack on same column"
34+
description = "Test the ability of one queen to attack another -> can attack on same column"
2835

2936
[0e1b4139-b90d-4562-bd58-dfa04f1746c7]
30-
description = "can attack on first diagonal"
37+
description = "Test the ability of one queen to attack another -> can attack on first diagonal"
3138

3239
[ff9b7ed4-e4b6-401b-8d16-bc894d6d3dcd]
33-
description = "can attack on second diagonal"
40+
description = "Test the ability of one queen to attack another -> can attack on second diagonal"
3441

3542
[0a71e605-6e28-4cc2-aa47-d20a2e71037a]
36-
description = "can attack on third diagonal"
43+
description = "Test the ability of one queen to attack another -> can attack on third diagonal"
3744

3845
[0790b588-ae73-4f1f-a968-dd0b34f45f86]
39-
description = "can attack on fourth diagonal"
46+
description = "Test the ability of one queen to attack another -> can attack on fourth diagonal"
47+
48+
[543f8fd4-2597-4aad-8d77-cbdab63619f8]
49+
description = "Test the ability of one queen to attack another -> cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal"

exercises/practice/queen-attack/queen-attack_spec.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,15 @@ describe('queen-attack', function()
6868
end)
6969

7070
it('can attack on fourth diagonal', function()
71-
local q1 = Queen({ row = 2, column = 2 })
72-
local q2 = Queen({ row = 5, column = 5 })
71+
local q1 = Queen({ row = 1, column = 7 })
72+
local q2 = Queen({ row = 0, column = 6 })
7373
assert.is_true(q1.can_attack(q2))
7474
end)
75+
76+
it('cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal',
77+
function()
78+
local q1 = Queen({ row = 4, column = 1 })
79+
local q2 = Queen({ row = 2, column = 5 })
80+
assert.is_false(q1.can_attack(q2))
81+
end)
7582
end)

0 commit comments

Comments
 (0)