有没有java五子棋源代码代码啊 亲

基于C语言实现五子棋游戏完整实例代码
转载 & & 投稿:shichen2014
这篇文章主要介绍了基于C语言实现五子棋游戏完整实例代码,相信对于学习游戏开发的朋友会有一定的帮助与借鉴价值,需要的朋友可以参考下
本文实例讲述了基于C语言实现五子棋游戏的方法,代码备有比较完整的注释,可以帮助读者更好的加以理解。
五子棋游戏代码如下:
* 使用键盘的上下左右键移动棋盘,空格键表示下棋,ESC键退出程序
#include &stdio.h&
#include &stdlib.h&
#include &bios.h&
#include &graphics.h&
#include&malloc.h&
* 对应键盘键的十六进制数字
#define ESC 0x11b
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define BLANK 0x3920
#define PLAYER1 1
#define PLAYER2 2
#define COMPUTER 2
#define LENGTH 15
#define SEARCH_DEEP 2
* 用来在函数can_expand()查找可以扩展的节点步长
#define STEP 1
/************全局变量定义***************/
oldx = 240,
oldy = 240;
step_sum = 0;
chessman[LENGTH][LENGTH];
depth = 2; /* 搜索的深度 */
win_flag = 0;
typedef struct five_chess *
struct five_chess {
chess[LENGTH][LENGTH];
record[LENGTH][LENGTH];
stack_deep0 = 0;
stack_c[10];
close[600];
push(point s0)
if (stack_deep0 & 10)
stack_c[stack_deep0++] = s0;
if (stack_deep0 & 0)
return stack_c[stack_deep0 - 1];
/*else return 一个什么样的东西?*/
if (stack_deep0 & 0)
stack_deep0--;
is_empty()
if (stack_deep0 != 0)
/************函数的声明**************/
win_or_not(int x0, int y0, int who,
int chessman[LENGTH][LENGTH], int a);
set_chessman();
print_result();
/************评价函数部分************/
score_row(int i, int j, int chessman[LENGTH][LENGTH]);
score_col(int i, int j, int chessman[LENGTH][LENGTH]);
score_diag_45(int i, int j, int chessman[LENGTH][LENGTH]);
score_diag_135(int i, int j, int chessman[LENGTH][LENGTH]);
total_score(int who_running, int chessman[LENGTH][LENGTH]);
score(int chessman[LENGTH][LENGTH]);
rowdt(int i, int j, int chessman[LENGTH][LENGTH]);
coldt(int i, int j, int chessman[LENGTH][LENGTH]);
diadt(int i, int j, int chessman[LENGTH][LENGTH]);
vdiadt(int i, int j, int chessman[LENGTH][LENGTH]);
can_expand(int i, int j, int chessman[LENGTH][LENGTH]);
copy(point s1, point s0);
POW(int s, int t)
if (t &= 0)
for (i = 0; i & i++)
* 定义computer先手
expand(point s0)
new_chess = (point) malloc(sizeof(struct five_chess));
/*************************这里出错***********************************/
for (i = 0; i & LENGTH; i++)
for (j = 0; j & LENGTH; j++)
new_chess-&chess[i][j] = s0-&chess[i][j];
for (i = 0; i & LENGTH; i++)
for (j = 0; j & LENGTH; j++)
new_chess-&record[i][j] = s0-&chess[i][j];
/*************************这里出错***********************************/
if (s0-&layer % 2 == 0)
flag = COMPUTER;
flag = PLAYER1;
for (i = 0; i & LENGTH; i++)
for (j = 0; j & LENGTH; j++) {
if (s0-&record[i][j])
/*如果有棋子*/
if (can_expand(i, j, s0-&chess) == 0)
/*如果有棋子,而且沿水平,树直,左上—右下,右上—左下,四个方向可以扩展*/
s0-&record[i][j] =
new_chess-&chess[i][j] =
new_chess-&layer = s0-&layer + 1;
new_chess-&x =
new_chess-&y =
new_chess-&record[i][j] =
return new_
* for(i=5;i&10;i++) for(j=5;j&10;j++){ if(s0-&record[i][j])
* if(can_expand(i,j,s0-&chess)==0) s0-&record[i][j]=
* new_chess-&x=i; new_chess-&y=j; new_chess-&record[i][j]=
* new_chess-&layer=s0-&layer+1; new_chess-&chess[i][j]= return
* new_ } for(i=2;i&12;i++) for(j=2;j&12;j++){
* if(i&4&&i&10&&j&4&&j&10) if(s0-&record[i][j])
* if(can_expand(i,j,s0-&chess)==0) s0-&record[i][j]=
* new_chess-&x=i; new_chess-&y=j; new_chess-&record[i][j]=
* new_chess-&layer=s0-&layer+1; new_chess-&chess[i][j]= return
* } for(i=0;i&LENGTH;i++) for(j=0;j&LENGTH;j++){
* if(i&1&&i&12&&j&1&&j&12) if(s0-&record[i][j])
* if(can_expand(i,j,s0-&chess)==0) s0-&record[i][j]=
* new_chess-&chess[i][j]= new_chess-&layer=s0-&layer+1;
* new_chess-&x=i; new_chess-&y=j; new_chess-&record[i][j]= return
new_chess-&layer = -1;
return new_
computer()
break_now = 0;
break_then = 0;
go_on = 0;
s0 = NULL,
s1 = NULL,
s2 = NULL,
max_chess = NULL;
temps = NULL,
* 堆栈的初始化
stack_deep0 = 0;
s0 = malloc(sizeof(struct five_chess));
for (i = 0; i & 600; i++)
/*为什么是600*/
close[i] = NULL;
/*close是一个point 数组*/
close[num++] = s0;
for (i = 0; i & LENGTH; i++)
for (j = 0; j & LENGTH; j++) {
s0-&chess[i][j] = chessman[i][j];
s0-&record[i][j] = chessman[i][j];
s0-&layer = 0;
s0-&value = -3000000;
s0-&score = -3000000;
while (is_empty() != 0) {
/*看是栈否为空*/
s01 = top();
/*如果不是空*/
s1 = expand(s01);
/*从栈顶开始展开*/
close[num++] = s1;
if (s1-&layer == -1) {
win_or_not((s1-&x + 1) * 30, (s1-&y + 1) * 30, 2, s1-&chess,
if (go_on == 2) {
a = (s1-&x + 1) * 30;
b = (s1-&y + 1) * 30;
break_then = 1;
win_or_not((s1-&x + 1) * 30, (s1-&y + 1) * 30, 1, s1-&chess,
if (go_on == 1) {
a = (s1-&x + 1) * 30;
b = (s1-&y + 1) * 30;
break_then = 1;
s1-&value = 30000;
while (1) {
s1 = top();
s2 = expand(s1);
if (s2-&layer == -1) {
if (s1-&value & top()-&value) {
top()-&value = s1-&
max_chess = s1;
}/*end of if*/
s2-&score = score(s2-&chess);
temps = top();
if (s2-&score & temps-&value)
temps-&value = s2-&
}/*end of whiile(1) */
if (break_then == 0) {
for (i = 0; i & LENGTH; i++) {
for (j = 0; j & LENGTH; j++)
if (max_chess-&chess[i][j] != chessman[i][j]) {
a = i * 30 + 30;
b = j * 30 + 30;
break_now = 1;
if (break_now == 1)
for (i = 0; i & 600; i++) {
if (close[i] == NULL)
free(close[i]);
/**********************************************************/
play_with_who = 1;
printf("1.Play with human\n2.Play with computer\nPlease choice: ");
scanf("%d", &play_with_who);
/*显示棋盘*/
if (play_with_who == 1) {
/*人与人玩*/
while (1) {
/*设置人与人玩的界面*/
settextstyle(0, 0, 2);
if ((step_sum + 1) % 2) {
setcolor(1);
outtextxy(500, 180, "Player2");
setcolor(4);
outtextxy(500, 180, "Player1");
setcolor(1);
outtextxy(500, 180, "Player1");
setcolor(10);
outtextxy(500, 180, "Player2");
if (bioskey(1))
* 按了一次键盘那么就true,执行下面代码,这是bios。h
key = bioskey(0);
* 返回一个键盘值,如没有按键,则一直等待
switch (key) {
case LEFT:
if (x1 & 30) {
/*显示方框*/
if (y1 & 30) {
case RIGHT:
if (x1 & 450) {
case DOWN:
if (y1 & 450) {
case BLANK:
/*按下空格键后放置棋子*/
if (chessman[x1 / 30][y1 / 30])
/*如果当前位置有棋子,不能放置,退出*/
step_sum++;
/*如果没有棋子,下一步谁走加1*/
* P1 设置棋子
if (step_sum % 2) {
setcolor(15);
/*画棋子*/
setfillstyle(SOLID_FILL, 15); /* 封闭图形,进行实体填充*/
circle(x1, y1, 10);
floodfill(x1, y1, 15);
/*填充圆*/
chessman[x1 / 30][y1 / 30] = PLAYER1;
/*设置棋盘状态*/
win_flag = win_or_not(x1, y1, 1, chessman, 0);
/*分析游戏是否结束,谁胜谁败*/
if (win_flag == 1)
outtextxy(480, 240, "P1 Win");
else if (win_flag == 3)
outtextxy(480, 240, "DOGFALL");
if (win_flag != 0) {
/*如果没人胜,游戏继续*/
while (bioskey(1) == 0);
closegraph();
/*what this mean?*/
} else { /* P2 设置棋子 */
setcolor(12);
setfillstyle(SOLID_FILL, 12);
circle(x1, y1, 10);
floodfill(x1, y1, 12);
chessman[x1 / 30][y1 / 30] = PLAYER2;
win_flag = win_or_not(x1, y1, 2, chessman, 0);
if (win_flag == 2)
outtextxy(480, 240, "P2 Win");
else if (win_flag == 3)
outtextxy(480, 240, "DOGFALL");
if (win_flag != 0) {
while (bioskey(1) == 0);
closegraph();
chessman[7][7] = COMPUTER;
/*人和电脑玩,电脑先走一步*/
setcolor(12);
setfillstyle(SOLID_FILL, 12);
circle(240, 240, 10);
floodfill(240, 240, 12);
flag_run = 0;
/*有什么用?*/
step_sum++;
/*下一步谁走?*/
while (1) {
while (1) {
if (flag_run == 1)
if (bioskey(1)) {
key = bioskey(0);
* 返回一个键盘值,如没有按键,则一直等待
switch (key) {
case LEFT:
if (x1 & 30) {
if (y1 & 30) {
case RIGHT:
if (x1 & 450) {
case DOWN:
if (y1 & 450) {
case BLANK:
if (chessman[x1 / 30 - 1][y1 / 30 - 1])
/*有棋子了不走*/
setcolor(15);
setfillstyle(SOLID_FILL, 15); /* 封闭图形,进行实体填充
circle(x1, y1, 10);
floodfill(x1, y1, 15);
/*画棋子*/
chessman[x1 / 30 - 1][y1 / 30 - 1] = PLAYER1;
flag_run = 1;
/*有什么用?*/
step_sum++;
/*下一步谁走*/
win_flag = win_or_not(x1, y1, 1, chessman, 0);
/*谁胜谁负*/
if (win_flag == 1)
outtextxy(480, 240, "P1 Win");
else if (win_flag == 3)
outtextxy(480, 240, "DOGFALL");
if (win_flag != 0) {
while (bioskey(1) == 0);
/*没有人胜则继续等待下棋*/
closegraph();
} /* switch */
computer();
/*调用智能体*/
* a,b存放的是现在电脑准备下的位置
* 返回一个a,b的结构体不是更好,用全局变量不爽啊
* struct {
setcolor(12);
setfillstyle(SOLID_FILL, 12);
circle(a, b, 10);
floodfill(a, b, 12);
chessman[a / 30 - 1][b / 30 - 1] = COMPUTER;
flag_run = 0;
step_sum++;
win_flag = win_or_not(a, b, 2, chessman, 0);
if (win_flag == 2)
outtextxy(480, 240, "ComputerWin");
else if (win_flag == 3)
outtextxy(480, 240, "DOGFALL");
if (win_flag != 0) {
while (bioskey(1) == 0);
closegraph();
* 画棋盘的过程
gdriver = DETECT,
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver, &gmode, " ");
* 对显示适配器进行配置
setbkcolor(1);
for (i = 0; i & 30; i++) {
setcolor((i &= 2) ? 9 : i);
rectangle(i, i, 479 - i, 479 - i); /* 画矩形边框 */
for (i = 1; i & 14; i++)
for (j = 1; j & 14; j++) {
setcolor(14);
line(30 + 30 * i, 30, 30 + 30 * i, 449);
line(30, 30 + 30 * i, 449, 30 + 30 * i);
* 画整个图的边框
for (i = 0; i & 15; i++) {
setcolor(i);
rectangle(i, i, 640 - i, 480 - i);
line(480 - i, 15, 480 - i, 465);
* 输出屏幕右侧的信息
setcolor(4);
settextstyle(0, 0, 2);
outtextxy(500, 45, "GOBANG");
setcolor(10);
settextstyle(0, 0, 1);
outtextxy(500, 90, "Designed By");
outtextxy(514, 118, "Ye Binbin");
outtextxy(480, 140, "from class A of CS");
* 移动光标
setcolor(1);
if (oldx & 450) {
if (oldy & 30)
line(oldx + 7, oldy - 15, oldx + 15, oldy - 15);
if (oldy & 30)
line(oldx + 15, oldy - 15, oldx + 15, oldy - 7);
if (oldy & 450)
line(oldx + 15, oldy + 7, oldx + 15, oldy + 15);
if (oldy & 450)
line(oldx + 15, oldy + 15, oldx + 7, oldy + 15);
if (oldx & 30) {
if (oldy & 450)
line(oldx - 7, oldy + 15, oldx - 15, oldy + 15);
if (oldy & 450)
line(oldx - 15, oldy + 15, oldx - 15, oldy + 7);
if (oldy & 30)
line(oldx - 15, oldy - 7, oldx - 15, oldy - 15);
if (oldy & 30)
line(oldx - 15, oldy - 15, oldx - 7, oldy - 15);
setcolor(12);
if (x1 & 450) {
if (y1 & 30)
line(x1 + 7, y1 - 15, x1 + 15, y1 - 15);
if (y1 & 30)
line(x1 + 15, y1 - 15, x1 + 15, y1 - 7);
if (y1 & 450)
line(x1 + 15, y1 + 7, x1 + 15, y1 + 15);
if (y1 & 450)
line(x1 + 15, y1 + 15, x1 + 7, y1 + 15);
if (x1 & 30) {
if (y1 & 450)
line(x1 - 7, y1 + 15, x1 - 15, y1 + 15);
if (y1 & 450)
line(x1 - 15, y1 + 15, x1 - 15, y1 + 7);
if (y1 & 30)
line(x1 - 15, y1 - 7, x1 - 15, y1 - 15);
if (y1 & 30)
line(x1 - 15, y1 - 15, x1 - 7, y1 - 15);
oldx = x1;
oldy = y1;
set_chessman()
* 棋子有三种状态,0是未初始状态,1是控制方棋子,2是对方棋子
for (i = 0; i & 15; i++)
for (j = 0; j & 15; j++)
chessman[i][j] = 0;
* 0表示没有赢,1表示p1胜利,2表示p2胜利,3表示平局
win_or_not(int x0, int y0, int who, int chessman[LENGTH][LENGTH], int a)
i = x0 / 30 - 1,
j = y0 / 30 - 1;
line_sum = -1;
tmp_i = i,
if (a == 1) {
* 测试第一层扩展是否满足赢的条件
c = chessman[i][j];
chessman[i][j] = who_
while (1) {
/* 查找共行的棋子是否连接了五个 */
while (tmp_i &= 0 && line_sum != 4) {
if (chessman[tmp_i--][j] == who_run)
line_sum++;
if (line_sum == 4)
line_sum++;
while (tmp_i &= 15 && line_sum != 5) {
if (chessman[tmp_i++][j] == who_run)
line_sum++;
if (line_sum == 5) {
if (a == 1)
chessman[i][j] =
return who_
line_sum = -1;
while (1) {
/* 查找共列的棋子是否连接了五个 */
while (tmp_j &= 0 && line_sum != 4) {
if (chessman[i][tmp_j--] == who_run)
line_sum++;
if (line_sum == 4)
line_sum++;
while (tmp_j &= 15 && line_sum != 5) {
if (chessman[i][tmp_j++] == who_run)
line_sum++;
if (line_sum == 5) {
if (a == 1)
chessman[i][j] =
return who_
line_sum = -1;
while (1) {
/* 查找上对角线上是否连接了五个 */
while (line_sum != 4 && tmp_i &= 15 && tmp_j &= 0) {
if (chessman[tmp_i++][tmp_j--] == who_run)
line_sum++;
if (line_sum == 4)
line_sum++;
while (line_sum != 5 && tmp_i &= 0 && tmp_j &= 15) {
if (chessman[tmp_i--][tmp_j++] == who_run)
line_sum++;
if (line_sum == 5) {
if (a == 1)
chessman[i][j] =
return who_
line_sum = -1;
while (1) {
/* 查找下对角线上是否连接了五个 */
while (line_sum != 4 && tmp_i &= 0 && tmp_j &= 0) {
if (chessman[tmp_i--][tmp_j--] == who_run)
line_sum++;
if (line_sum == 4)
line_sum++;
while (line_sum != 5 && tmp_i &= 15 && tmp_j &= 15) {
if (chessman[tmp_i++][tmp_j++] == who_run)
line_sum++;
if (line_sum == 5) {
if (a == 1)
chessman[i][j] =
return who_
if (step_sum == 225) {
if (a == 1)
chessman[i][j] =
if (a == 1)
chessman[i][j] =
score_row(int i, int j, int chessman[LENGTH][LENGTH])
sum_chessmen = 0;
score = 0;
who_running = chessman[i][j];
if (j == LENGTH) {
while (chessman[i][j] == who_running) {
sum_chessmen++;
if (sum_chessmen &= 5)
score = 200000;
if (chessman[i][j] == 0) /* 没有下子,活的情况 */
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0; /* 死的情况 */
while (chessman[i][j] == who_running && j != LENGTH) {
sum_chessmen++;
j = j - sum_chessmen - 1;
while (chessman[i][j] == who_running && j != -1) {
sum_chessmen++;
if (j &= 0 && mid_j & LENGTH) {
if (chessman[i][j] == 0 && chessman[i][mid_j] == 0)
score = 18000 / POW(50, 4 - sum_chessmen);
else if ((chessman[i][j] != 0 && chessman[i][mid_j] == 0)
|| (chessman[i][j] == 0 && chessman[i][mid_j] != 0))
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (j & 0 && mid_j & LENGTH) {
if (chessman[i][mid_j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (j &= 0 && mid_j &= LENGTH) {
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (j & 0 && mid_j &= LENGTH)
score = 0;
score_col(int i, int j, int chessman[LENGTH][LENGTH])
sum_chessmen = 0,
score = 0;
who_running = chessman[i][j];
if (i == LENGTH) {
while (chessman[i][j] == who_running) {
sum_chessmen++;
if (sum_chessmen &= 5)
score = 200000;
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
while (chessman[i][j] == who_running) {
sum_chessmen++;
if (i == LENGTH || chessman[i][j] != who_running) {
i = i - sum_
while (chessman[i - 1][j] == who_running) {
sum_chessmen++;
if (i &= 0) {
if (chessman[i][j] == 0 && chessman[mid_i][j] == 0)
score = 18000 / POW(50, 4 - sum_chessmen);
else if ((chessman[i][j] != 0 && chessman[mid_i][j]) == 0
|| (chessman[i][j] == 0
&& chessman[mid_i][j] != 0))
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (i & 0 && mid_i & LENGTH) {
if (chessman[mid_i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (i & 0 && mid_i & LENGTH) {
if (chessman[mid_i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (i &= 0 && mid_i &= LENGTH) {
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
score_diag_45(int i, int j, int chessman[LENGTH][LENGTH])
sum_chessmen = 0;
score = 0;
who_running = chessman[i][j];
if (i == LENGTH || j == LENGTH) {
while (chessman[i][j] == who_running && i & 1 && j & 1) {
sum_chessmen++;
if (sum_chessmen &= 5)
score = 200000;
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
while (chessman[i][j] == who_running && i &= LENGTH && j &= LENGTH) {
sum_chessmen++;
i = i - sum_
j = j - sum_
while (chessman[i - 1][j - 1] == who_running) {
sum_chessmen++;
if (sum_chessmen &= 5)
score = 200000;
if (i &= 0 && j &= 0 && mid_i & LENGTH && mid_j & LENGTH) {
if (chessman[mid_i][mid_j] == 0 && chessman[i][j] == 0)
score = 18000 / POW(50, 4 - sum_chessmen);
else if ((chessman[mid_i][mid_j] == 0 && chessman[i][j] != 0)
|| (chessman[mid_i][mid_j] != 0
&& chessman[i][j] == 0))
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (i &= 0 && j &= 0) {
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
} else if (mid_i & LENGTH && mid_j & LENGTH) {
if (chessman[mid_i][mid_j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
score = 0;
score_diag_135(int i, int j, int chessman[LENGTH][LENGTH])
sum_chessmen = 0;
score = 0;
who_running = chessman[i][j];
while (chessman[i][j] == who_running && j != -1 && i & LENGTH) {
sum_chessmen++;
while (chessman[i][j] == who_running && j != LENGTH) {
sum_chessmen++;
if (sum_chessmen &= 5)
score = 200000;
if (i &= 0 && j & LENGTH && mid_j &= 0 && mid_i & LENGTH) {
if (chessman[i][j] == 0 && chessman[mid_i][mid_j] == 0)
score = 18000 / POW(50, 4 - sum_chessmen);
if ((chessman[i][j] == 0 && chessman[mid_i][mid_j] != 0)
|| (chessman[i][j] != 0
&& chessman[mid_i][mid_j] == 0))
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (i &= 0 && j & LENGTH) {
if (chessman[i][j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
if (mid_j &= 0 && mid_i & LENGTH) {
if (chessman[mid_i][mid_j] == 0)
score = 2000 / POW(10, 4 - sum_chessmen);
score = 0;
total_score(int who_running, int chessman[LENGTH][LENGTH])
* 统计出在该点上的得分,who_running=1表示人的棋子,2为电脑的棋子
score = 0;
for (i = 0; i & LENGTH; i++)
for (j = 0; j & LENGTH; j++) {
if (chessman[i][j] == who_running) {
score += score_row(i, j, chessman);
score += score_col(i, j, chessman);
score += score_diag_45(i, j, chessman);
score += score_diag_135(i, j, chessman);
score(int chessman[LENGTH][LENGTH])
* 计算最终的得分数,分别考虑了在这个位置放对方棋子跟自己棋子的综合
sum1 = total_score(COMPUTER, chessman);
sum2 = total_score(PLAYER1, chessman);
return sum1 - sum2;
* 扩展-----剪枝过程
rowdt(int i, int j, int chessman[LENGTH][LENGTH])
/*在树直方向*/
midjl = j - STEP,
/*当前棋子的上方*/
midjr = j + STEP + 1;
/*当前棋子的下方棋子的下方??????*/
if (midjl & 0)
midjl = 0;
if (midjr & LENGTH)
midjr = LENGTH;
for (k = k & k++)
if (chessman[i][k] != 0)
/*如果有棋子*/
coldt(int i, int j, int chessman[LENGTH][LENGTH])
/*水平方向*/
midil = i + STEP + 1,
/*当前的右边棋子的右一个*/
midiu = i - STEP;
/*当前棋子的左一个*/
if (midiu & 0)
midiu = 0;
if (midil & LENGTH)
midil = LENGTH;
for (k = k & k++)
if (chessman[k][j] != 0)
diadt(int i, int j, int chessman[LENGTH][LENGTH])
/*右上到左下方向*/
for (k = 0; k & STEP; k++) {
if (midj & 0 || midi &= LENGTH)
if (chessman[midi][midj] != 0)
for (k = 0; k & STEP; k++) {
if (i & 0 || j &= LENGTH)
if (chessman[i][j] != 0)
vdiadt(int i, int j, int chessman[LENGTH][LENGTH])
/*左上到右下方向*/
for (k = 0; k & STEP; k++) {
if (midi & 0 || midj & 0)
if (chessman[midi][midj] != 0)
for (k = 0; k & STEP; k++) {
if (j &= LENGTH || i &= LENGTH)
if (chessman[i][j] != 0)
can_expand(int i, int j, int chessman[LENGTH][LENGTH])
if (rowdt(i, j, chessman))
if (coldt(i, j, chessman))
if (diadt(i, j, chessman))
if (vdiadt(i, j, chessman))
* 如果不能扩展,返回0
/************************************************************/
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具>> js五子棋
所属分类:
下载地址:
js五子棋.rar文件大小:3.80 kB
分享有礼! 》
请点击右侧的分享按钮,把本代码分享到各社交媒体。
通过您的分享链接访问Codeforge,每来2个新的IP,您将获得0.1 积分的奖励。
通过您的分享链接,每成功注册一个用户,该用户在Codeforge上所获得的每1个积分,您都将获得0.2 积分的分成奖励。
纯js代码实现五子棋,但是算法存在一些缺陷,实现了判定输赢的算法和判定黑白棋下棋顺序的算法,在实现人机对下的算法有比较大的缺陷
Sponsored links
源码文件列表
温馨提示: 点击源码文件名可预览文件内容哦 ^_^
b.png1.15 kB27-11-12 00:00
3.79 kB05-11-13 09:55
w.png1.24 kB27-11-12 00:00
(提交有效评论获得积分)
评论内容不能少于15个字,不要超出160个字。
评价成功,多谢!
下载js五子棋.rar
CodeForge积分(原CF币)全新升级,功能更强大,使用更便捷,不仅可以用来下载海量源代码马上还可兑换精美小礼品了
您的积分不足,优惠套餐快速获取 30 积分
10积分 / ¥100
30积分 / ¥200原价 ¥300 元
100积分 / ¥500原价 ¥1000 元
订单支付完成后,积分将自动加入到您的账号。以下是优惠期的人民币价格,优惠期过后将恢复美元价格。
支付宝支付宝付款
微信钱包微信付款
更多付款方式:、
您本次下载所消耗的积分将转交上传作者。
同一源码,30天内重复下载,只扣除一次积分。
鲁ICP备号-3 runtime:Elapsed:269.021ms - init:0.1;find:0.6;t:0.5;tags:0.4;related:36.0;comment:0.2; 27.69
登录 CodeForge
还没有CodeForge账号?
Switch to the English version?
^_^"呃 ...
Sorry!这位大神很神秘,未开通博客呢,请浏览一下其他的吧五子棋源码
查看次数:5651
下载次数:2339
上传时间:
大小:19 KB
五子棋源码
测试环境:Xcode 6,iOS 8.0
您还没有登录!请或
下载过该代码的还下载了
本周热门下载
&2018 Chukong Technologies,Inc.
京公网安备89有哪些开源的计算机五子棋程序的源代码值得初学者阅读? - 知乎46被浏览<strong class="NumberBoard-itemValue" title="分享邀请回答262 条评论分享收藏感谢收起写回答1 个回答被折叠()}

我要回帖

更多关于 java五子棋源代码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信