INDAPlus21 / INDAPlus21/eliasfl-task-10
Pass
- Dominant language
- Prolog
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**Very well done Elias!**
You code is really good!
Readability formatting is all personal preference. I find yours to be a little confusing. In the future, your code will depend on whatever your team or company deems worthy. Until then, find a formatting that your are confortable with others reading; something that makes you look good.
_Your code_:
```prolog
check_alive(Row, Column, Board, Stone, Visited) :-
% ...
(Stone_ = e;
Stone = Stone_,
Down is Row + 1,
Up is Row - 1,
Right is Column + 1,
Left is Column - 1,
(check_alive(Down, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Up, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Left, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Right, Board, Stone, [(Row, Column)|Visited]))).
```
_Airy formatting_:
```prolog
check_alive(Row, Column, Board, Stone, Visited) :-
% ...
(
Stone_ = e;
Stone = Stone_,
Down is Row + 1,
Up is Row - 1,
Right is Column + 1,
Left is Column - 1,
(
check_alive(Down, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Up, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Left, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Right, Board, Stone, [(Row, Column)|Visited])
)
).
```
I find it curious that you exit the predicate without backtracking.
_Your code_:
```prolog
alive(Row, Column, BoardFileName) :-
% ...
check_alive(Row, Column, Board, Stone, []), !.
```
You don't have to do this by adding one single pair of parathesis in `check_alive`. This way the predicate returns at `Stone_ = e` without testing other boolean combinations.
_Fixed (with airy formatting)_:
```prolog
check_alive(Row, Column, Board, Stone, Visited) :-
% ...
(
Stone_ = e;
(
Stone = Stone_,
Down is Row + 1,
Up is Row - 1,
Right is Column + 1,
Left is Column - 1,
(
check_alive(Down, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Up, Column, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Left, Board, Stone, [(Row, Column)|Visited]);
check_alive(Row, Right, Board, Stone, [(Row, Column)|Visited])
)
)
).
```
Thanks for your hard work!
Educational read: https://www.metalevel.at/prolog/fun
Contributor guide
No contributing guide indexed for this repository
Research direction
The feedback discusses the check_alive/5 and alive/3 predicates, including formatting and backtracking behavior. Start by locating those predicates in the repository and compare their current behavior with the examples in this issue; done would require resolving the suggested code-quality and control-flow concerns.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100