Skip to content

Adding a smarter gatherer - #105

Draft
Debilski wants to merge 1 commit into
mainfrom
smart-gatherer
Draft

Debilski wants to merge 1 commit into
mainfrom
smart-gatherer

Conversation

@Debilski

@Debilski Debilski commented Sep 9, 2026

Copy link
Copy Markdown
Member

Adapted basic gatherer: Will not go to a field when there is an enemy on a neighbouring field. Not sure if I if pos in list(bot.graph[bot.enemy[0].position]) is actually the nicest way of doing this, though.

@Debilski

Debilski commented Sep 9, 2026

Copy link
Copy Markdown
Member Author

The smart gatherer has been added to CI so that we can see if it out performs the original one. :)

@otizonaizit

Copy link
Copy Markdown
Member

Adapted basic gatherer: Will not go to a field when there is an enemy on a neighbouring field.

This is to make the gatherer a bit better in the hope that when they run background games between hunter and gatherer they get more balanced statistics and do not assume that hunting is the "best" strategy, right? Just writing this down explicitly because we will forget what is the point of changing the demos.

Not sure if I if pos in list(bot.graph[bot.enemy[0].position]) is actually the nicest way of doing this, though.

It was extremely surprising to me to discover that addressing the graph with a position returns a list of neighbors. That would freak out the students, I am very sure.

If we keep this, we should use or re-use the danger_zone function from demo09_paint_background.py. It is more verbose, but it doesn't use any magic and it's pretty straightforward to understand, albeit less efficient than the trick used here ;)

@Debilski

Copy link
Copy Markdown
Member Author

It was extremely surprising to me to discover that addressing the graph with a position returns a list of neighbors. That would freak out the students, I am very sure.

I was checking https://networkx.org/documentation/stable/reference/classes/generated/networkx.Graph.neighbors.html and of course I went for the alternative suggestion. :)

@Debilski

Copy link
Copy Markdown
Member Author

I do agree that it makes sense to re-use the danger zone implementation. OTOH, why do we support networkx if we don’t make use of it. (I could live with a comment to the function suggesting that it might make sense to rewrite it using nx.)

@otizonaizit

Copy link
Copy Markdown
Member

I was checking https://networkx.org/documentation/stable/reference/classes/generated/networkx.Graph.neighbors.html and of course I went for the alternative suggestion. :)

of course ;)

I agree, writing:

if pos in bot.graph.neighbors(bot.enemy[0].position):

instead of:

if pos in list(bot.graph[bot.enemy[0].position]):
    continue

would make the code 4 characters longer and it would be definitely too readable and too easy to understand intuitively. Let them do some thinking and put some prints here and there to understand what is going on :)

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.

2 participants