mirror of
https://gitlab.com/oloturia/damastodon.git
synced 2025-01-07 22:17:15 +01:00
merging created a mess
This commit is contained in:
commit
e08a9a5799
2 changed files with 59 additions and 13 deletions
|
@ -15,6 +15,9 @@ save_position = "/tmp/"
|
||||||
CLEANR = re.compile('<.*?>')
|
CLEANR = re.compile('<.*?>')
|
||||||
botname = "@damastodon "
|
botname = "@damastodon "
|
||||||
|
|
||||||
|
firow = "🔠1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣\n"
|
||||||
|
colsx = "🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 "
|
||||||
|
|
||||||
def cleanHTML(raw):
|
def cleanHTML(raw):
|
||||||
cleanText = re.sub(CLEANR, '',raw)
|
cleanText = re.sub(CLEANR, '',raw)
|
||||||
return cleanText
|
return cleanText
|
||||||
|
@ -62,7 +65,11 @@ def check_message(notification):
|
||||||
pickle.dump("@"+challenger,f)
|
pickle.dump("@"+challenger,f)
|
||||||
pickle.dump(False,f)
|
pickle.dump(False,f)
|
||||||
pickle.dump(board,f)
|
pickle.dump(board,f)
|
||||||
|
<<<<<<< HEAD
|
||||||
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")
|
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")
|
||||||
|
=======
|
||||||
|
mastodon.status_post("◾: @"+account+" ◽: @"+challenger+" turn ◽\n"+dama.draw_checkerboard(board,space="🟥 ",white_norm="◽ ",white_knight="⚪ ",black_norm="◾ ",black_knight="⚫ ",empty="🟦 ",frstrow=firow, column=colsx),visibility="direct")
|
||||||
|
>>>>>>> reversecheckboard
|
||||||
return
|
return
|
||||||
elif content.split(" ")[1].lower() == "no":
|
elif content.split(" ")[1].lower() == "no":
|
||||||
os.remove(save_position+content.split(" ")[0][1:])
|
os.remove(save_position+content.split(" ")[0][1:])
|
||||||
|
@ -83,7 +90,7 @@ def check_message(notification):
|
||||||
mastodon.status_post(black+" "+white+" the match was cancelled.")
|
mastodon.status_post(black+" "+white+" the match was cancelled.")
|
||||||
return
|
return
|
||||||
if (black == "@"+account and turn == 1) or (white == "@"+account and turn == 0):
|
if (black == "@"+account and turn == 1) or (white == "@"+account and turn == 0):
|
||||||
board = dama.valid_move(content.lower(),turn,board)
|
board = dama.valid_move(content.lower(),turn,board,inversion=True)
|
||||||
if board == -1:
|
if board == -1:
|
||||||
mastodon.status_post("@"+account+" \nInvalid move.",visibility="direct")
|
mastodon.status_post("@"+account+" \nInvalid move.",visibility="direct")
|
||||||
return
|
return
|
||||||
|
@ -100,7 +107,11 @@ def check_message(notification):
|
||||||
colour = "◾"
|
colour = "◾"
|
||||||
winner = dama.checkWin(board)
|
winner = dama.checkWin(board)
|
||||||
if winner == (False,False):
|
if winner == (False,False):
|
||||||
|
<<<<<<< HEAD
|
||||||
mastodon.status_post("◾: "+black+" ◽: "+white+" turn "+colour+"\n"+dama.draw_checkerboard(board,space="🟥",white_norm="◽",white_knight="⚪",black_norm="◾",black_knight="⚫",empty="🟦",frstrow="0🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 \n"),visibility="direct")
|
mastodon.status_post("◾: "+black+" ◽: "+white+" turn "+colour+"\n"+dama.draw_checkerboard(board,space="🟥",white_norm="◽",white_knight="⚪",black_norm="◾",black_knight="⚫",empty="🟦",frstrow="0🇦 🇧 🇨 🇩 🇪 🇫 🇬 🇭 \n"),visibility="direct")
|
||||||
|
=======
|
||||||
|
mastodon.status_post("◾: "+black+" ◽: "+white+" turn "+colour+"\n"+dama.draw_checkerboard(board,space="🟥 ",white_norm="◽ ",white_knight="⚪ ",black_norm="◾ ",black_knight="⚫ ",empty="🟦 ",frstrow=firow, column=colsx),visibility="direct")
|
||||||
|
>>>>>>> reversecheckboard
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if winner == (True,False):
|
if winner == (True,False):
|
||||||
|
|
|
@ -2,7 +2,14 @@
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def draw_checkerboard(status,space="▒",white_norm="h",white_knight="H",black_norm="b",black_knight="B",empty=" ",frstrow=" abcdefgh\n",column="12345678"):
|
def draw_checkerboard(status,space="▒",white_norm="h",white_knight="H",black_norm="b",black_knight="B",empty=" ",frstrow=" abcdefgh\n",column="12345678"):
|
||||||
|
=======
|
||||||
|
def draw_checkerboard(status,space="▒",white_norm="h",white_knight="H",black_norm="b",black_knight="B",empty=" ",column="12345678",frstrow=" abcdefgh\n"):
|
||||||
|
""" Draw a checkerboard, status is the virtual representation of the board, as a bi-dimensional array, white/black norm/knight are the representation of the pieces
|
||||||
|
space is a non-walkable cell, empty is a walkable cell, column contains labels for the left column, frstrow the labels for the first row.
|
||||||
|
"""
|
||||||
|
>>>>>>> reversecheckboard
|
||||||
bstr = ""
|
bstr = ""
|
||||||
bstr += frstrow
|
bstr += frstrow
|
||||||
for row in range(0,len(status)):
|
for row in range(0,len(status)):
|
||||||
|
@ -22,13 +29,14 @@ def draw_checkerboard(status,space="▒",white_norm="h",white_knight="H",black_n
|
||||||
bstr += empty
|
bstr += empty
|
||||||
if (cell < 3):
|
if (cell < 3):
|
||||||
bstr += space
|
bstr += space
|
||||||
if row % 2 !=0:
|
if row % 2 !=0: #odd lines ends with space and a line feed, even ones just with the line feed
|
||||||
bstr += space+"\n"
|
bstr += space+"\n"
|
||||||
else:
|
else:
|
||||||
bstr += "\n"
|
bstr += "\n"
|
||||||
return bstr
|
return bstr
|
||||||
|
|
||||||
def position_resolver(pos,board):
|
def position_resolver(pos,board):
|
||||||
|
"""Checks if the position is valid and wether it contains a piece or not"""
|
||||||
row,col = row_column_translation(pos[1],pos[0])
|
row,col = row_column_translation(pos[1],pos[0])
|
||||||
if (col == -1):
|
if (col == -1):
|
||||||
return -1
|
return -1
|
||||||
|
@ -36,6 +44,8 @@ def position_resolver(pos,board):
|
||||||
return board[row][col]
|
return board[row][col]
|
||||||
|
|
||||||
def row_column_translation(row,col):
|
def row_column_translation(row,col):
|
||||||
|
"""Converts a coordinate made by a letter/number couple in the index usable with the array that represents the board"""
|
||||||
|
|
||||||
row = int(row) - 1
|
row = int(row) - 1
|
||||||
if row % 2 != 0:
|
if row % 2 != 0:
|
||||||
cols = range(ord("a"),ord("a")+7,2)
|
cols = range(ord("a"),ord("a")+7,2)
|
||||||
|
@ -46,13 +56,27 @@ def row_column_translation(row,col):
|
||||||
else:
|
else:
|
||||||
return row,cols.index(ord(col))
|
return row,cols.index(ord(col))
|
||||||
|
|
||||||
def valid_move(pos_toParse,turn,board):
|
def traslate_coord(pos):
|
||||||
|
for en,p in enumerate(pos):
|
||||||
|
temp_col = chr( (int(pos[en][1])-1)+ord("a") )
|
||||||
|
temp_row = ord(pos[en][0])-ord("a")
|
||||||
|
pos[en] = temp_col
|
||||||
|
pos[en] += str(temp_row +1)
|
||||||
|
return pos
|
||||||
|
|
||||||
|
def valid_move(pos_toParse,turn,board,inversion=False):
|
||||||
|
"""Checks if the move is valid, execute it and returns the updated 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)
|
#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)
|
pos = re.findall("\\b[abcdefgh][12345678]\\b",pos_toParse) #both row-col and col-row are accepted
|
||||||
#for rowcol in pos:
|
if len(pos) == 0:
|
||||||
# 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
|
pos = re.findall("\\b[12345678][abcdefgh]\\b",pos_toParse)
|
||||||
# return -1
|
for en,x in enumerate(pos):
|
||||||
if len(pos) < 2:
|
pos[en] = x[1]+x[0]
|
||||||
|
|
||||||
|
if inversion:
|
||||||
|
pos = traslate_coord(pos)
|
||||||
|
|
||||||
|
if len(pos) < 2: #less than 2 coords were given, movement is invalid
|
||||||
return -1
|
return -1
|
||||||
row_start,col_start = row_column_translation(pos[0][1],pos[0][0])
|
row_start,col_start = row_column_translation(pos[0][1],pos[0][0])
|
||||||
if(row_start == -1):
|
if(row_start == -1):
|
||||||
|
@ -78,7 +102,7 @@ def valid_move(pos_toParse,turn,board):
|
||||||
start_cell = 3
|
start_cell = 3
|
||||||
board[row][col] = start_cell
|
board[row][col] = start_cell
|
||||||
return board
|
return board
|
||||||
else:
|
else: #destination cell is not empty
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
for x in range(0,len(pos) -1):
|
for x in range(0,len(pos) -1):
|
||||||
|
@ -105,9 +129,9 @@ def valid_move(pos_toParse,turn,board):
|
||||||
if ((row == 7) and start_cell == 1):
|
if ((row == 7) and start_cell == 1):
|
||||||
start_cell = 3
|
start_cell = 3
|
||||||
pos.pop(0) #if there are other moves this check loops
|
pos.pop(0) #if there are other moves this check loops
|
||||||
else:
|
else: #one of the pieces moves are invalid
|
||||||
return -1
|
return -1
|
||||||
else:
|
else: #destination not empty
|
||||||
return -1
|
return -1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
@ -135,18 +159,29 @@ def checkWin(board):
|
||||||
return (white_won,black_won)
|
return (white_won,black_won)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
import sys
|
||||||
|
column_i = "12345678"
|
||||||
|
frstrow_i = " abcdefgh\n"
|
||||||
|
inverted = False
|
||||||
|
try:
|
||||||
|
if sys.argv[1] == "i":
|
||||||
|
column_i = "abcdefgh"
|
||||||
|
frstrow_i = " 12345678\n"
|
||||||
|
inverted = True
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
main_board = init_board()
|
main_board = init_board()
|
||||||
s = ""
|
s = ""
|
||||||
turn = False
|
turn = False
|
||||||
while (s !="q"):
|
while (s !="q"):
|
||||||
vis_board = draw_checkerboard(main_board)
|
vis_board = draw_checkerboard(main_board,column=column_i,frstrow=frstrow_i)
|
||||||
print(vis_board)
|
print(vis_board)
|
||||||
if turn:
|
if turn:
|
||||||
s = input("Black move:")
|
s = input("Black move:")
|
||||||
else:
|
else:
|
||||||
s = input("White move:")
|
s = input("White move:")
|
||||||
if (s !="q"):
|
if (s !="q"):
|
||||||
result = valid_move(s,turn,main_board)
|
result = valid_move(s,turn,main_board,inversion=inverted)
|
||||||
if result != -1:
|
if result != -1:
|
||||||
main_board = result
|
main_board = result
|
||||||
winner = checkWin(main_board)
|
winner = checkWin(main_board)
|
||||||
|
|
Loading…
Reference in a new issue