Added a command for notification of new turns

This commit is contained in:
sloumdrone 2018-12-29 18:53:54 -08:00
parent 9d3069f358
commit cab40feb98
1 changed files with 19 additions and 3 deletions

22
oberon
View File

@ -7,7 +7,7 @@ import subprocess
import json
version = '0.3.2'
version = '0.4.1'
home_folder = os.path.expanduser('~')
username = os.path.split(home_folder)[-1]
database = '/var/lib/oberon/oberon.sqlite'
@ -49,6 +49,16 @@ def validate_input(r,c, board):
return True
def available_moves():
q = "SELECT p1, p2, turn FROM games WHERE winner is null and (p1 = ? or p2 = ?)"
v = (username, username)
res = db_do(q, v)
p1 = len([x for x in res if x[0] == username and x[2] % 2 != 0])
p2 = len([x for x in res if x[1] == username and x[2] % 2 == 0])
if p1 + p2 > 0:
print('\nIt is your turn in oberon!\n')
def check_win_state(point, piece, board):
ends = [
walk_to_ends(point, 0, piece, board),
@ -124,8 +134,11 @@ def play_game(gid):
while True:
verify = input('Are you sure (y/n)? ')
if verify in ['y', 'yes']:
# Change game to over
# make opponent the winner
winner = res[0][1] if res[0][4] % 2 == 0 else res[0][2]
if not set_winner(gid, winner):
print('Error updating database')
return False
print('Game forfeited. {} wins.'.format(winner))
return True
elif verify in ['n', 'no']:
continue
@ -240,6 +253,9 @@ def parse_args():
elif args[1] == 'history':
show_game_record()
sys.exit(0)
elif args[1] == 'available':
available_moves()
sys.exit(0)
elif args[1] == 'create':
print('Must include an opponent name.\nFind one in chat or cspc!')
sys.exit(1)