Commit cff1df63 by 岳巧源

add new line

parent 28bbbcc0
Showing with 110 additions and 0 deletions
import pymysql
# if __name__ == '__main__':
# conf = {
# 'host': "10.8.0.6",
# 'port': 3306,
# 'user': "larosa",
# 'password': "er2403Kn06#",
# 'db': "mydb",
# 'charset': 'utf8'
# }
# # sql = "select id, name from student where id = 16"
# sql_insert = "insert into student (id, name) values (%s, %s)"
# db = pymysql.connect(**conf)
# cursor = db.cursor()
# id = 22
# name = "dsd\'dsds\"ds \"d"
# arr = [str(id), str(name)]
# tuple_arr = (str(id), str(name))
# print(sql_insert % tuple_arr)
# cursor.execute(sql_insert, arr)
# db.commit()
class ChessBoard:
def __init__(self):
self.black_count = 0
self.white_count = 0
self.board = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
def get_board(self):
return self.board, self.black_count, self.white_count
def set_board(self, row: int, col: int, black: bool) -> bool:
if 0 <= row <= 14 and 0 <= col <= 14:
if self.board[row][col] == 0:
if black:
self.board[row][col] = 1
self.black_count += 1
else:
self.board[row][col] = -1
self.white_count += 1
return True
else:
return False
else:
return False
def judge_horizontal(self, row: int, col: int) -> bool:
left = 0
right = 0
for step in range(1, 5):
if row - step >= 0 and self.board[row - step][col] == 1:
left += 1
else:
break
for step in range(1, 5):
if row + step <= 14 and self.board[row + step][col] == 1:
right += 1
else:
break
return left + right + 1 >= 5
def judge_vertical(self, row: int, col: int) -> bool:
return False
def judge_left_slope(self, row: int, col: int) -> bool:
return False
def judge_right_slope(self, row: int, col: int) -> bool:
return False
def win(self, row: int, col: int, black: bool) -> bool:
if black:
if self.black_count >= 5:
return self.judge_horizontal(row, col) or \
self.judge_vertical(row, col) or \
self.judge_left_slope(row, col) or \
self.judge_right_slope(row, col)
else:
return False
else:
if self.white_count >= 5:
return self.judge_horizontal(row, col) or \
self.judge_vertical(row, col) or \
self.judge_left_slope(row, col) or \
self.judge_right_slope(row, col)
else:
return False
if __name__ == '__main__':
pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment