Skip to content

Commit

Permalink
Added q to quit
Browse files Browse the repository at this point in the history
  • Loading branch information
gsobell committed Jun 23, 2023
1 parent 4920e6b commit 2af4609
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If you encounter any bugs, open a issue on GitHub.
### Gameplay

Use the arrow or vim keys to navigate the board. Enter or space places a stone.
Use `u` to undo, `p` to pass.
Use `u` to undo, `p` to pass, `q` to quit.
Also supports mouse input; click to move, double click to place stone.

<!-- Two consecutive passes end the game. -->
Expand Down
15 changes: 11 additions & 4 deletions dango.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def is_ko(self, y, x, color, captures) -> bool:
return True
return False


def capture_check(self, y, x, color):
"""Checks if playing color at (y, x) captures neighbor
(any neighbor has one remaining liberty)"""
Expand Down Expand Up @@ -337,7 +336,6 @@ def clear_message(stdscr):
stdscr.refresh()



def play(stdscr):
curses_setup(stdscr)
moves = [] # moves (y,x), for undo. None if pass
Expand All @@ -348,17 +346,18 @@ def play(stdscr):
draw_A1(stdscr)
draw_board(stdscr)
stdscr.getch()
update_to_play = True
y, x = 3, SIZE*2 - 3 # top right corner
while "game loop":
while "input loop":
old_cursor = y, x
c = stdscr.getch()
clear_message(stdscr) # after getch(), so can be read
if c == 10 or c == ord(" "):
if stones.legal_placement(y, x, color, captures):
place_piece(y, x, color, stones, moves, captures, stdscr)
moves.append((y, x))
color *= -1
update_to_play = True
else:
error_out(stdscr, "Not a valid move")
break
Expand All @@ -377,6 +376,7 @@ def play(stdscr):
moves, captures, stdscr)
moves.append((y, x))
color *= -1
update_to_play = True
else:
error_out(stdscr, "Not a valid move")
break
Expand Down Expand Up @@ -448,14 +448,21 @@ def play(stdscr):
else:
standard_out(stdscr, "Undo pass.")
color *= -1
elif c == ord("q"):
standard_out(
stdscr, "Would you like to exit? (Press 'q' again)")
if stdscr.getch() == ord("q"):
exit()
else:
y, x = get_move(c, y, x, stdscr)
draw_cursor((y, x), old_cursor, stones, stdscr)
# A1 = yx_to_a1(y, x)
# standard_out(stdscr, f"cords are: {A1}")
# standard_out(stdscr, f"click is: {click}")
# standard_out(stdscr, f"(y,x) is: {y, x}")
standard_out(stdscr,f"{'White' if color == 1 else 'Black'} to play.")
standard_out(
stdscr, f"{'White' if color == 1 else 'Black'} to play." +
((curses.COLS - 15) * ' ')) # clears old message
stdscr.refresh()


Expand Down

0 comments on commit 2af4609

Please sign in to comment.