From 9a2f896d9559451d5af2a610f3d7fe38b69b827e Mon Sep 17 00:00:00 2001 From: oloturia <5429234+oloturia@users.noreply.github.com> Date: Fri, 29 Oct 2021 15:17:58 +0200 Subject: [PATCH 1/4] more typos --- damastodon.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/damastodon.py b/damastodon.py index 08c000d..3350bcb 100755 --- a/damastodon.py +++ b/damastodon.py @@ -28,21 +28,21 @@ def check_message(notification): content = content[len(botname):] saves = os.listdir(save_position) if content.lower() == "help": - mastodon.status_post("Hello @"+account+",\nchallenge an user by writing to me\nCHALL \nEx. \"CHALL @someone@mastdn.inst.wxyz\"\nThe challenger takes WHITE and begins the match.\nFor movements and jumps, write the coords separated by spaces.\nEx. \"A4 B5\" (normal movement) or \"A4 C6 D8\" (double jump)\nQUIT ends the match.\nCommands are NOT case sensitive..",visibility="direct") + mastodon.status_post("Hello @"+account+" \nchallenge an user by writing to me\nCHALL \nEx. \"CHALL @someone@mastdn.inst.wxyz\"\nThe challenger takes WHITE and begins the match.\nFor movements and jumps, write the coords separated by spaces.\nEx. \"A4 B5\" (normal movement) or \"A4 C6 D8\" (double jump)\nQUIT ends the match.\nCommands are NOT case sensitive..",visibility="direct") return if not os.path.exists(save_position+account): if content[:5].lower() == "sfida": file_save_white = [sv for sv in saves if account in sv] file_save_black = [sv for sv in saves if content[:6] in sv] if len(file_save_white) > 0: - mastodon.status_post("Hello @"+account+",\n you're already playing a match") + mastodon.status_post("Hello @"+account+" \n you're already playing a match") return elif len(file_save_black): - mastodon.status_post("Hello @"+content[7:]+",\n is already playing a match") + mastodon.status_post("Hello @"+content[7:]+" \n is already playing a match") return else: open(save_position+account,"w").close() - ident = mastodon.status_post("Hello @"+content[7:]+",\n@"+account+" challenged you to a match of draughts! Anzwer \n@"+account+" OK\n to accept the chellenge or \n@"+account+" NO\n to cancel.",visibility="direct") + ident = mastodon.status_post("Hello @"+content[7:]+" \n@"+account+" challenged you to a match of draughts! Answer \n@"+account+" OK\n to accept the chellenge or \n@"+account+" NO\n to cancel.",visibility="direct") return elif content.split(" ")[1].lower() == "ok": os.symlink(content.split(" ")[0][1:],save_position+account) @@ -59,7 +59,7 @@ def check_message(notification): mastodon.status_post(account+" you cancelled the challenge from "+content.split(" ")[0],visibility="direct") return else: - mastodon.status_post("Hello @"+account+" I can't understand your commend or you're not in a match.\nWrite HELP to see the list of available commands.",visibility="direct") + mastodon.status_post("Hello @"+account+" \nI can't understand your commend or you're not in a match.\nWrite HELP to see the list of available commands.",visibility="direct") return else: with open(save_position+account,"rb") as f: @@ -75,7 +75,7 @@ def check_message(notification): if (black == "@"+account and turn == 1) or (white == "@"+account and turn == 0): board = dama.valid_move(content.lower(),turn,board) if board == -1: - mastodon.status_post("@"+account+"\nInvalid move.",visibility="direct") + mastodon.status_post("@"+account+" \nInvalid move.",visibility="direct") return else: with open(save_position+account,"wb") as f: @@ -102,7 +102,7 @@ def check_message(notification): mastodon.status_post("◾: "+black+" ◽: "+white+"\n"+winner_t+" WINS!\n"+dama.draw_checkerboard(board,space="🟥 ",white_norm="◽ ",white_knight="⚪ ",black_norm="◾ ",black_knight="⚫ ",empty="🟦 ",frstrow="0🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 \n"),visibility="direct") return else: - mastodon.status_post("@"+account+"\nIt's not your turn.",visibility="direct") + mastodon.status_post("@"+account+" \nIt's not your turn.",visibility="direct") return if __name__ == "__main__": From 5c7fc6f96166c313bb93e80c1ecc011051d2da60 Mon Sep 17 00:00:00 2001 From: oloturia <5429234+oloturia@users.noreply.github.com> Date: Fri, 29 Oct 2021 15:22:30 +0200 Subject: [PATCH 2/4] trying to fix a bug --- damastodon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/damastodon.py b/damastodon.py index 3350bcb..3d5728c 100755 --- a/damastodon.py +++ b/damastodon.py @@ -31,7 +31,7 @@ def check_message(notification): mastodon.status_post("Hello @"+account+" \nchallenge an user by writing to me\nCHALL \nEx. \"CHALL @someone@mastdn.inst.wxyz\"\nThe challenger takes WHITE and begins the match.\nFor movements and jumps, write the coords separated by spaces.\nEx. \"A4 B5\" (normal movement) or \"A4 C6 D8\" (double jump)\nQUIT ends the match.\nCommands are NOT case sensitive..",visibility="direct") return if not os.path.exists(save_position+account): - if content[:5].lower() == "sfida": + if content[:5].lower() == "chall": file_save_white = [sv for sv in saves if account in sv] file_save_black = [sv for sv in saves if content[:6] in sv] if len(file_save_white) > 0: From 0420b93a0fb2e9c84904016a82d5583d8e3ba7b7 Mon Sep 17 00:00:00 2001 From: oloturia <5429234+oloturia@users.noreply.github.com> Date: Fri, 29 Oct 2021 16:31:33 +0200 Subject: [PATCH 3/4] Debugged version --- damastodon.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/damastodon.py b/damastodon.py index 3d5728c..919b531 100755 --- a/damastodon.py +++ b/damastodon.py @@ -31,35 +31,45 @@ def check_message(notification): mastodon.status_post("Hello @"+account+" \nchallenge an user by writing to me\nCHALL \nEx. \"CHALL @someone@mastdn.inst.wxyz\"\nThe challenger takes WHITE and begins the match.\nFor movements and jumps, write the coords separated by spaces.\nEx. \"A4 B5\" (normal movement) or \"A4 C6 D8\" (double jump)\nQUIT ends the match.\nCommands are NOT case sensitive..",visibility="direct") return if not os.path.exists(save_position+account): + try: + challenged = notification["status"]["mentions"][1]["acct"] + except: + mastodon.status_post("Hello @"+account+" \n your request is not valid") + return if content[:5].lower() == "chall": file_save_white = [sv for sv in saves if account in sv] - file_save_black = [sv for sv in saves if content[:6] in sv] + file_save_black = [sv for sv in saves if challenged in sv] if len(file_save_white) > 0: mastodon.status_post("Hello @"+account+" \n you're already playing a match") return elif len(file_save_black): - mastodon.status_post("Hello @"+content[7:]+" \n is already playing a match") + mastodon.status_post("Hello @"+account+" \n the user you challenged is already playing a match") return else: open(save_position+account,"w").close() - ident = mastodon.status_post("Hello @"+content[7:]+" \n@"+account+" challenged you to a match of draughts! Answer \n@"+account+" OK\n to accept the chellenge or \n@"+account+" NO\n to cancel.",visibility="direct") + ident = mastodon.status_post("Hello @"+challenged+" \n@"+account+" challenged you to a match of draughts! Answer \n@"+account+" OK\n to accept the chellenge or \n@"+account+" NO\n to cancel.",visibility="direct") return elif content.split(" ")[1].lower() == "ok": - os.symlink(content.split(" ")[0][1:],save_position+account) + try: + challenger = notification["status"]["mentions"][1]["acct"] + except: + mastodon.status_post("Hello @"+account+" \n your request is not valid") + return + os.symlink(save_position+challenger,save_position+account) board = dama.init_board() - with open(account,"wb") as f: + with open(save_position+account,"wb") as f: pickle.dump("@"+account,f) - pickle.dump(content.split(" ")[0],f) + pickle.dump("@"+challenger,f) pickle.dump(False,f) pickle.dump(board,f) - mastodon.status_post("◾: @"+account+" ◽: "+content.split(" ")[0]+" turn ◽\n"+dama.draw_checkerboard(board,space="🟥 ",white_norm="◽ ",white_knight="⚪ ",black_norm="◾ ",black_knight="⚫ ",empty="🟦 ",frstrow="0🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 \n"),visibility="direct") + mastodon.status_post("◾: @"+account+" ◽: @"+challenger+" turn ◽\n"+dama.draw_checkerboard(board,space="🟥 ",white_norm="◽ ",white_knight="⚪ ",black_norm="◾ ",black_knight="⚫ ",empty="🟦 ",frstrow="0🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 \n"),visibility="direct") return elif content.split(" ")[1].lower() == "no": os.remove(save_position+content.split(" ")[0][1:]) mastodon.status_post(account+" you cancelled the challenge from "+content.split(" ")[0],visibility="direct") return else: - mastodon.status_post("Hello @"+account+" \nI can't understand your commend or you're not in a match.\nWrite HELP to see the list of available commands.",visibility="direct") + mastodon.status_post("Hello @"+account+" \nI can't understand your command or you're not in a match.\nWrite HELP to see the list of available commands.",visibility="direct") return else: with open(save_position+account,"rb") as f: From 14eb5e9d196237a1b1abada6501d6dc340fc13c3 Mon Sep 17 00:00:00 2001 From: oloturia <5429234+oloturia@users.noreply.github.com> Date: Fri, 29 Oct 2021 16:59:22 +0200 Subject: [PATCH 4/4] Movement is controlled by regex --- draughts_engine.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/draughts_engine.py b/draughts_engine.py index 37a8006..fcc4212 100755 --- a/draughts_engine.py +++ b/draughts_engine.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +import re + def draw_checkerboard(status,space="▒",white_norm="h",white_knight="H",black_norm="b",black_knight="B",empty=" ",frstrow=" abcdefgh\n"): bstr = "" bstr += frstrow @@ -46,10 +48,13 @@ def row_column_translation(row,col): return row,cols.index(ord(col)) def valid_move(pos_toParse,turn,board): - pos = pos_toParse.split(" ") #tricky part, pos[0] is the starting cell, pos[1] to pos[n] the destination point(s), for every coord, [x][0] is the column (the letter) and [x][1] the row (the number) - for rowcol in pos: - if (rowcol[0] not in ("a","b","c","d","e","f","g","h")) or (rowcol[1] not in ("1","2","3","4","5","6","7","8")): #check if the positions are valid - return -1 + #pos = pos_toParse.split(" ") #tricky part, pos[0] is the starting cell, pos[1] to pos[n] the destination point(s), for every coord, [x][0] is the column (the letter) and [x][1] the row (the number) + pos = re.findall("\\b[abcdefgh][12345678]\\b",pos_toParse) + #for rowcol in pos: + # if (rowcol[0] not in ("a","b","c","d","e","f","g","h")) or (rowcol[1] not in ("1","2","3","4","5","6","7","8")): #check if the positions are valid + # return -1 + if len(pos) < 2: + return -1 row_start,col_start = row_column_translation(pos[0][1],pos[0][0]) if(row_start == -1): return -1