Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
aa152147
五子棋
提交
a6a839ea
五
五子棋
项目概览
aa152147
/
五子棋
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
43
Fork
23
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
五
五子棋
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a6a839ea
编写于
6月 19, 2023
作者:
6
63db3122f0950a2aef64df95
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto Commit
上级
3349811a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
208 addition
and
14 deletion
+208
-14
src/App.vue
src/App.vue
+133
-13
src/assets/main.css
src/assets/main.css
+75
-1
未找到文件。
src/App.vue
浏览文件 @
a6a839ea
<
script
setup
>
import
{
reactive
,
ref
,
watch
}
from
"
vue
"
import
{
onMounted
,
reactive
,
ref
}
from
"
vue
"
// 配置
const
con
=
reactive
({
width
:
1
0
,
height
:
1
0
width
:
2
0
,
height
:
2
0
})
const
lattices
=
ref
([])
watch
(()
=>
con
,
()
=>
{
let
nextPlay
=
'
isBlack
'
// isWhite
// 5 连珠的下标
let
isWin
=
[]
onMounted
(
confirm
)
function
confirm
()
{
const
{
width
,
height
}
=
con
nextPlay
=
'
isBlack
'
isWin
=
[]
lattices
.
value
=
Array
(
height
).
fill
([]).
map
(
item
=>
Array
(
width
).
fill
(
null
))
}
function
playChess
(
item
,
r_i
,
c_i
)
{
if
(
isWin
.
length
||
item
)
return
lattices
.
value
[
r_i
][
c_i
]
=
nextPlay
const
test
=
checkWin
(
lattices
.
value
,
nextPlay
)
if
(
test
)
{
console
.
log
(
test
)
isWin
=
test
return
}
nextPlay
=
nextPlay
===
'
isBlack
'
?
'
isWhite
'
:
'
isBlack
'
}
// AI 生成代码
function
checkWin
(
board
)
{
const
rows
=
board
.
length
;
const
cols
=
board
[
0
].
length
;
// 检查行
for
(
let
row
=
0
;
row
<
rows
;
row
++
)
{
for
(
let
col
=
0
;
col
<
cols
-
4
;
col
++
)
{
if
(
board
[
row
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
][
col
+
1
]
&&
board
[
row
][
col
]
===
board
[
row
][
col
+
2
]
&&
board
[
row
][
col
]
===
board
[
row
][
col
+
3
]
&&
board
[
row
][
col
]
===
board
[
row
][
col
+
4
]
)
{
const
positions
=
[];
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
positions
.
push
([
row
,
col
+
i
]);
}
return
positions
;
}
}
}
// 检查列
for
(
let
col
=
0
;
col
<
cols
;
col
++
)
{
for
(
let
row
=
0
;
row
<
rows
-
4
;
row
++
)
{
if
(
board
[
row
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
1
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
2
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
3
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
4
][
col
]
)
{
const
positions
=
[];
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
positions
.
push
([
row
+
i
,
col
]);
}
return
positions
;
}
}
}
},
{
deep
:
true
})
// 检查对角线(左上到右下)
for
(
let
row
=
0
;
row
<
rows
-
4
;
row
++
)
{
for
(
let
col
=
0
;
col
<
cols
-
4
;
col
++
)
{
if
(
board
[
row
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
1
][
col
+
1
]
&&
board
[
row
][
col
]
===
board
[
row
+
2
][
col
+
2
]
&&
board
[
row
][
col
]
===
board
[
row
+
3
][
col
+
3
]
&&
board
[
row
][
col
]
===
board
[
row
+
4
][
col
+
4
]
)
{
const
positions
=
[];
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
positions
.
push
([
row
+
i
,
col
+
i
]);
}
return
positions
;
}
}
}
// 检查对角线(右上到左下)
for
(
let
row
=
0
;
row
<
rows
-
4
;
row
++
)
{
for
(
let
col
=
cols
-
1
;
col
>=
4
;
col
--
)
{
if
(
board
[
row
][
col
]
&&
board
[
row
][
col
]
===
board
[
row
+
1
][
col
-
1
]
&&
board
[
row
][
col
]
===
board
[
row
+
2
][
col
-
2
]
&&
board
[
row
][
col
]
===
board
[
row
+
3
][
col
-
3
]
&&
board
[
row
][
col
]
===
board
[
row
+
4
][
col
-
4
]
)
{
const
positions
=
[];
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
positions
.
push
([
row
+
i
,
col
-
i
]);
}
return
positions
;
}
}
}
// 如果没有连续五个棋子,则返回 null
return
null
;
}
function
getStyle
(
item
,
r_i
,
c_i
)
{
if
(
isWin
.
length
)
{
return
isWin
.
map
(([
r
,
c
])
=>
`
${
r
}
_
${
c
}
`
).
includes
(
`
${
r_i
}
_
${
c_i
}
`
)
?
'
isWin
'
:
item
}
return
item
}
</
script
>
<
template
>
<div>
<p>
<div
class=
"content flex-between"
>
<p
class=
"flex-between"
>
<label>
高:
</label>
<input
type=
"number"
>
<input
v-model=
"con.height"
type=
"number"
>
</p>
<p
class=
"flex-between"
>
<label>
宽:
</label>
<input
v-model=
"con.width"
type=
"number"
>
</p>
<button
@
click=
"confirm"
>
重新开始
</button>
</div>
<div
class=
"content border-top content-lattice"
>
<p
class=
"row"
v-for=
"(lattice, r_i) in lattices"
:key=
"r_i"
>
<p
class=
"col"
:class=
"getStyle(item, r_i, c_i)"
v-for=
"(item, c_i) in lattice"
:key=
"`$
{r_i}-${c_i}`"
@click="playChess(item, r_i, c_i)">
</p>
<p>
<label>
框:
</label>
<input
type=
"number"
>
</p>
</div>
<div></div>
</
template
>
src/assets/main.css
浏览文件 @
a6a839ea
@import
"./base.css"
;
*
{
*
{
margin
:
0
;
padding
:
0
;
}
...
...
@@ -9,5 +9,79 @@
margin
:
0
auto
;
font-weight
:
normal
;
cursor
:
pointer
;
}
.content
{
padding
:
6px
;
box-sizing
:
border-box
;
}
.flex-between
{
display
:
flex
;
justify-content
:
space-between
;
align-items
:
center
;
}
input
{
width
:
60px
;
}
.border-top
{
border-top
:
1px
solid
#ccc
;
}
.content-lattice
{
display
:
flex
;
justify-content
:
center
;
}
.row
{
display
:
flex
;
flex-direction
:
column
;
}
.col
{
width
:
20px
;
height
:
20px
;
text-align
:
center
;
line-height
:
20px
;
position
:
relative
;
}
.col
::after
{
content
:
''
;
line-height
:
0px
;
text-align
:
center
;
height
:
1px
;
width
:
100%
;
background
:
#999
;
position
:
absolute
;
top
:
calc
(
50%
-
1px
);
left
:
0
;
}
.col
::before
{
content
:
''
;
width
:
1px
;
height
:
100%
;
background
:
#999
;
position
:
absolute
;
left
:
calc
(
50%
-
1px
);
top
:
0
;
}
.isWhite
::after
{
content
:
'O'
;
color
:
brown
;
}
.isBlack
::after
{
content
:
'O'
;
color
:
black
;
}
.isWin
::after
{
content
:
'O'
;
color
:
red
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录