Skip to content

Commit

Permalink
Merge pull request #817 from Debilski/feature/suicide-arrow
Browse files Browse the repository at this point in the history
UI: Better visualisation of debug arrows for bot suicide
  • Loading branch information
Debilski authored Aug 8, 2024
2 parents 5845d10 + f228ae5 commit 056d52b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
32 changes: 26 additions & 6 deletions pelita/ui/tk_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,12 +1006,32 @@ def draw_moves(self, game_state):
req_pos = tuple(game_state['requested_moves'][bot]['requested_position'])
except TypeError:
req_pos = None
arrow_item = Arrow(self.mesh_graph,
position=old_pos,
req_pos=game_state['bots'][bot],
success=game_state['requested_moves'][bot]['success'])
arrow_item.draw(self.ui.game_canvas)
self.arrow_items.append(arrow_item)

if game_state['requested_moves'][bot]['success'] and tuple(game_state['bots'][bot]) != tuple(game_state['requested_moves'][bot]['requested_position']):
# Bot has committed suicide. Show two arrows.
arrow_item1 = Arrow(self.mesh_graph,
position=old_pos,
req_pos=game_state['requested_moves'][bot]['requested_position'],
success=True,
head=False)
arrow_item1.draw(self.ui.game_canvas)

arrow_item2 = Arrow(self.mesh_graph,
position=game_state['requested_moves'][bot]['requested_position'],
req_pos=game_state['bots'][bot],
success=True)
arrow_item2.draw(self.ui.game_canvas)

self.arrow_items.append(arrow_item1)
self.arrow_items.append(arrow_item2)
else:
arrow_item = Arrow(self.mesh_graph,
position=old_pos,
req_pos=game_state['bots'][bot],
success=game_state['requested_moves'][bot]['success'])
arrow_item.draw(self.ui.game_canvas)
self.arrow_items.append(arrow_item)


def draw_bots(self, game_state):
if game_state:
Expand Down
8 changes: 5 additions & 3 deletions pelita/ui/tk_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ def draw(self, canvas, game_state=None, show_lifetime=False):
canvas.create_text(*center, text=food_age, font=(None, 10), fill=text_col, tag=tag)

class Arrow(TkSprite):
def __init__(self, mesh, req_pos, success, **kwargs):
def __init__(self, mesh, req_pos, success, head=True, **kwargs):
self.req_pos = req_pos
self.success = success
self.head = head

super(Arrow, self).__init__(mesh, **kwargs)

Expand Down Expand Up @@ -400,6 +401,7 @@ def draw(self, canvas, game_state=None):
self.screen((head.real, head.imag)),
self.screen((head_right.real, head_right.imag))
]
canvas.create_line(points,
fill=BROWN, width=scale, tag=(self.tag, "arrow"), capstyle="round")
if self.head:
canvas.create_line(points,
fill=BROWN, width=scale, tag=(self.tag, "arrow"), capstyle="round")

0 comments on commit 056d52b

Please sign in to comment.