Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
岳巧源
/
my-awesome-project
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cff1df63
authored
Jul 12, 2024
by
岳巧源
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add new line
parent
28bbbcc0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
0 deletions
test.py
test.py
View file @
cff1df63
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment