Skip to content
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

Issues/268 initial map csv #296

Merged
merged 8 commits into from
Nov 6, 2024
Merged

Issues/268 initial map csv #296

merged 8 commits into from
Nov 6, 2024

Conversation

jessesnyder
Copy link
Contributor

Adds parsing of CSV files as a way of specifying an initial grid state.
See #268

@jessesnyder jessesnyder merged commit 283d0d3 into main Nov 6, 2024
2 checks passed
@jessesnyder jessesnyder deleted the issues/268-initial-map-csv branch November 6, 2024 20:52
Copy link
Collaborator

@stugots stugots left a comment

Choose a reason for hiding this comment

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

great! this has already been merged, but here are some suggestions anyway :)

if matrix:
result["columns"] = len(matrix[0])
else:
result["columns"] = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

result["columns"] = len(matrix[0]) if matrix else 0

cell = cell.strip()
player_match = player_regex.match(cell)
if not cell:
# emtpy
Copy link
Collaborator

Choose a reason for hiding this comment

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

empty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the suggestion is here?

item_data["remaining_uses"] = int(id_and_maybe_uses[1])
result["items"].append(item_data)

return dict(result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmmm.... result is already a defaultdict. Can it be returned without converting it to dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do think a dict is a clearer and simpler interface (since this is the key return value) than a defaultdict, so I probably would have made this choice anyway. To me, returning a defaultdict suggests I will be modifying the result.


reader = csv.reader(csv_file)
grid_state = matrix2gridworld(list(reader))
return grid_state
Copy link
Collaborator

Choose a reason for hiding this comment

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

return matrix2gridworld(list(reader))

@jessesnyder
Copy link
Contributor Author

great! this has already been merged, but here are some suggestions anyway :)

I'm all for post-merge reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants