https://github.com/osoco/exercise-8-queens-victoriadiro
exercise-8-queens-VictoriaDiro created by GitHub Classroom
https://github.com/osoco/exercise-8-queens-victoriadiro
Last synced: 8 months ago
JSON representation
exercise-8-queens-VictoriaDiro created by GitHub Classroom
- Host: GitHub
- URL: https://github.com/osoco/exercise-8-queens-victoriadiro
- Owner: osoco
- License: gpl-3.0
- Created: 2019-07-25T08:53:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-28T11:43:44.000Z (almost 7 years ago)
- Last Synced: 2025-03-05T17:36:22.712Z (over 1 year ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exercise: 8 queens
Let's try to find a solution to this problem on paper, in an OOP style.
# Context
We want to place the maximum number of queens in a chess board, so they don't threat each other.
The provided API is as follows:
## Board
Represents a chess board with pieces in it. In our context, it will only contain Queens.
```
withQueen(Queen): Board
```
You can place a new Queen, and you'll get a new board.
```
threats(): boolean
```
You can use this method to check if the Board contains any threat.
```
empty(Position): boolean
```
This method can be used to check whether you can place a new Queen in given position.
## Queen
In our model, a Queen represents the piece in a certain position.
```
position(): Position
```
You can ask the Queen her position, if you need to.
```
board(): Board
```
You can get the information about the Board.
## Position
Represents a position in the chess board.
```
row(): Number
```
A number ranging from 1 to 8.
```
column(): Number
```
A number ranging from 1 to 8. We won't use standard chess notation.
```
threats(Position): boolean
```
You can use this method to check whether this position threats another position, according to Queen rules.
# Assignment 1
## QueenSolver
Write an "algorithm" (think of it as a sequence of actions or recipe) resembling the following API:
```
solve(): void
result(): Solution
```
## Solution
Solution, on the other hand, can be inspected to find the solution.
```
success(): boolean
```
It returns whether it could find a solution.
```
solutions(): List
```
It returns a list or an array of Queen instances. If its size is not 8, it's considered not successful.
# Assignment 2
Try to generalize the previous solution to allow an arbitrary board size, not only 8.