Skip to content

go-counting: Add single-territory function to README; Add canonical data #1195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 200 additions & 0 deletions exercises/go-counting/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"exercise": "go-counting",
"version": "1.0.0",
"comments": [
"Territory consists of [x, y] coordinate pairs."
],
"cases": [
{
"description": "Black corner territory on 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 0,
"y": 1
},
"expected": {
"owner": "BLACK",
"territory": [[0, 0], [0, 1], [1, 0]]
}
},
{
"description": "White center territory on 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 2,
"y": 3
},
"expected": {
"owner": "WHITE",
"territory": [[2, 3]]
}
},
{
"description": "Open corner territory on 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 1,
"y": 4
},
"expected": {
"owner": "NONE",
"territory": [[0, 3], [0, 4], [1, 4]]
}
},
{
"description": "A stone and not a territory on 5x5 board",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jssander @petertseng I know this PR has already been merged, but should this be "A stone is not a territory..."?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want. I admit I don't see a reason to prefer one or the other, but that could just be because of English not being my first language. I'm happy to defer to others on this matter.

"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 1,
"y": 1
},
"expected": {
"owner": "NONE",
"territory": []
}
},
{
"description": "Invalid because X is too low for 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": -1,
"y": 1
},
"expected": {
"error": "Invalid coordinate"
}
},
{
"description": "Invalid because X is too high for 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 5,
"y": 1
},
"expected": {
"error": "Invalid coordinate"
}
},
{
"description": "Invalid because Y is too low for 5x5 board",
"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 1,
"y": -1
},
"expected": {
"error": "Invalid coordinate"
}
},
{
"description": "Invalid because Y is too high for 5x5 board",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thanks for making this change.

"property": "territory",
"input": {
"board": [
" B ",
" B B ",
"B W B",
" W W ",
" W "
],
"x": 1,
"y": 5
},
"expected": {
"error": "Invalid coordinate"
}
},
{
"description": "One territory is the whole board",
"property": "territories",
"input": {
"board": [
" "
]
},
"expected": {
"territoryBlack": [],
"territoryWhite": [],
"territoryNone": [[0, 0]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this says territory, singular. What if a board has more than one black territory? How should that be handled?

Same, but for no owner

}
},
{
"description": "Two territory rectangular board",
"property": "territories",
"input": {
"board": [
" BW ",
" BW "
]
},
"expected": {
"territoryBlack": [[0, 0], [0, 1]],
"territoryWhite": [[3, 0], [3, 1]],
"territoryNone": []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice this says territory, singular. What if a board has more than one black territory? How should that be handled?

Same, but for no owner

}
},
{
"description": "Two region rectangular board",
"property": "territories",
"input": {
"board": [
" B "
]
},
"expected": {
"territoryBlack": [[0, 0], [2, 0]],
"territoryWhite": [],
"territoryNone": []
}
}
]
}
2 changes: 2 additions & 0 deletions exercises/go-counting/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Write a function that determines the territory of each player. You may
assume that any stones that have been stranded in enemy territory have
already been taken off the board.

Write a function that determines the territory which includes a specified coordinate.

Multiple empty intersections may be encircled at once and for encircling
only horizontal and vertical neighbours count. In the following diagram
the stones which matter are marked "O" and the stones that don't are
Expand Down