level 5
132泡沫
楼主
/*黑白棋_v2.1*/
/*修复 同一地方能下不同棋子的重大bug*/
/*修复 时不时报错不能下子且又改变棋子颜色的重大bug*/
/*优化 棋盘界面*/
/*由 132泡沫 创作,转载请注明出处*/
#include <stdio.h>
#include<conio.h>
#define BOARDSIZE 8
int OthelloBoard[BOARDSIZE + 1][BOARDSIZE + 1];
int black = 1;
int white = 2;
int Null = 0;
int inx;
int iny;
int B=0;//设置全局标记
void newBoard();
void importwight();
void importblack();
void Boardnumber();
void showBoard();
int opposite(int BorW){//取反
if (BorW==black)
return white;
if (BorW==white)
return black;
}
/* 棋盘初始化 */
void newBoard() {
int x, y;
for (x = 1; x <=BOARDSIZE; x++)
for (y = 1; y <= BOARDSIZE; y++)
OthelloBoard[x][y] = Null;
OthelloBoard[4][4] = 1;
OthelloBoard[4][5] = 2;
OthelloBoard[5][5] = 1;
OthelloBoard[5][4] = 2;
}
/* 黑棋坐标输入 */
void importblack() {
loop:
printf("black move\n");
printf("this is x path:");
scanf("%d", &inx);
printf("this is y path:");
scanf("%d", &iny);
if ((OthelloBoard[inx][iny] == black)||( OthelloBoard[inx][iny] == white)){
printf("输入有误,请重新输入\n");
goto loop;
}
OthelloBoard[inx][iny] = black;
}
/* 白棋坐标输入 */
void importwhite() {
loop:
printf("white move\n");
printf("this is x path:");
scanf("%d", &inx);
printf("this is y path:");
scanf("%d", &iny);
if ((OthelloBoard[inx][iny] == black)||( OthelloBoard[inx][iny] == white)){
printf("输入有误,请重新输入\n");
goto loop;
}
OthelloBoard[inx][iny] = white;
}
/*****************同化 扫描****************/
/*左边同化*/
void change_left(int BorW){
int i,x;
if (OthelloBoard[inx-1][iny]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx;x>0;x--,i++){//确保可被同化
if (OthelloBoard[x][iny]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny]!=0;i--){
OthelloBoard[inx-i][iny]=BorW;//同化
}
}
}
}else
B++;
}
/*右边同化*/
void change_right(int BorW){
int i,x;
if (OthelloBoard[inx+1][iny]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx;x<=BOARDSIZE+1;x++,i++){//确保可被同化
if (OthelloBoard[x][iny]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny]!=0;i--){
OthelloBoard[inx+i][iny]=BorW;//同化
}
}
}
}else
B++;
}
/*上面同化*/
void change_up(int BorW){
int i,y;
if (OthelloBoard[inx][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,y=iny;y>0;y--,i++){//确保可被同化
if (OthelloBoard[inx][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx][iny-i]!=0;i--){
OthelloBoard[inx][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*下面同化*/
void change_down(int BorW){
int i,y;
if (OthelloBoard[inx][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,y=iny;y<=BOARDSIZE+1;y++,i++){//确保可被同化
if (OthelloBoard[inx][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx][iny+i]!=0;i--){
OthelloBoard[inx][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*左上同化*/
void change_left_up(int BorW){
int i,x,y;
if (OthelloBoard[inx-1][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x>0)&&(y>0);x--,y--,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny-i]!=0;i--){
OthelloBoard[inx-i][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*右上同化*/
void change_right_up(int BorW){
int i,x,y;
if (OthelloBoard[inx+1][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x<=BOARDSIZE+1)&&(y>0);x++,y--,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny-i]!=0;i--){
OthelloBoard[inx+i][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*左下同化*/
void change_left_down(int BorW){
int i,x,y;
if (OthelloBoard[inx-1][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x>0)&&(y<=BOARDSIZE+1);x--,y++,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny+i]!=0;i--){
OthelloBoard[inx-i][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*右下同化*/
void change_right_down(int BorW){
int i,x,y;
if (OthelloBoard[inx+1][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x<=BOARDSIZE+1)&&(y<=BOARDSIZE+1);x++,y++,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny+i]!=0;i--){
OthelloBoard[inx+i][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*同化 扫描*/
void change(BorW){
change_left(BorW);
change_right(BorW);
change_up(BorW);
change_down(BorW);
change_left_up(BorW);
change_right_up(BorW);
change_left_down(BorW);
change_right_down(BorW);
}
/******************************************/
2015年11月06日 08点11分
1
/*修复 同一地方能下不同棋子的重大bug*/
/*修复 时不时报错不能下子且又改变棋子颜色的重大bug*/
/*优化 棋盘界面*/
/*由 132泡沫 创作,转载请注明出处*/
#include <stdio.h>
#include<conio.h>
#define BOARDSIZE 8
int OthelloBoard[BOARDSIZE + 1][BOARDSIZE + 1];
int black = 1;
int white = 2;
int Null = 0;
int inx;
int iny;
int B=0;//设置全局标记
void newBoard();
void importwight();
void importblack();
void Boardnumber();
void showBoard();
int opposite(int BorW){//取反
if (BorW==black)
return white;
if (BorW==white)
return black;
}
/* 棋盘初始化 */
void newBoard() {
int x, y;
for (x = 1; x <=BOARDSIZE; x++)
for (y = 1; y <= BOARDSIZE; y++)
OthelloBoard[x][y] = Null;
OthelloBoard[4][4] = 1;
OthelloBoard[4][5] = 2;
OthelloBoard[5][5] = 1;
OthelloBoard[5][4] = 2;
}
/* 黑棋坐标输入 */
void importblack() {
loop:
printf("black move\n");
printf("this is x path:");
scanf("%d", &inx);
printf("this is y path:");
scanf("%d", &iny);
if ((OthelloBoard[inx][iny] == black)||( OthelloBoard[inx][iny] == white)){
printf("输入有误,请重新输入\n");
goto loop;
}
OthelloBoard[inx][iny] = black;
}
/* 白棋坐标输入 */
void importwhite() {
loop:
printf("white move\n");
printf("this is x path:");
scanf("%d", &inx);
printf("this is y path:");
scanf("%d", &iny);
if ((OthelloBoard[inx][iny] == black)||( OthelloBoard[inx][iny] == white)){
printf("输入有误,请重新输入\n");
goto loop;
}
OthelloBoard[inx][iny] = white;
}
/*****************同化 扫描****************/
/*左边同化*/
void change_left(int BorW){
int i,x;
if (OthelloBoard[inx-1][iny]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx;x>0;x--,i++){//确保可被同化
if (OthelloBoard[x][iny]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny]!=0;i--){
OthelloBoard[inx-i][iny]=BorW;//同化
}
}
}
}else
B++;
}
/*右边同化*/
void change_right(int BorW){
int i,x;
if (OthelloBoard[inx+1][iny]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx;x<=BOARDSIZE+1;x++,i++){//确保可被同化
if (OthelloBoard[x][iny]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny]!=0;i--){
OthelloBoard[inx+i][iny]=BorW;//同化
}
}
}
}else
B++;
}
/*上面同化*/
void change_up(int BorW){
int i,y;
if (OthelloBoard[inx][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,y=iny;y>0;y--,i++){//确保可被同化
if (OthelloBoard[inx][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx][iny-i]!=0;i--){
OthelloBoard[inx][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*下面同化*/
void change_down(int BorW){
int i,y;
if (OthelloBoard[inx][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,y=iny;y<=BOARDSIZE+1;y++,i++){//确保可被同化
if (OthelloBoard[inx][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx][iny+i]!=0;i--){
OthelloBoard[inx][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*左上同化*/
void change_left_up(int BorW){
int i,x,y;
if (OthelloBoard[inx-1][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x>0)&&(y>0);x--,y--,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny-i]!=0;i--){
OthelloBoard[inx-i][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*右上同化*/
void change_right_up(int BorW){
int i,x,y;
if (OthelloBoard[inx+1][iny-1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x<=BOARDSIZE+1)&&(y>0);x++,y--,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny-i]!=0;i--){
OthelloBoard[inx+i][iny-i]=BorW;//同化
}
}
}
}else
B++;
}
/*左下同化*/
void change_left_down(int BorW){
int i,x,y;
if (OthelloBoard[inx-1][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x>0)&&(y<=BOARDSIZE+1);x--,y++,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx-i][iny+i]!=0;i--){
OthelloBoard[inx-i][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*右下同化*/
void change_right_down(int BorW){
int i,x,y;
if (OthelloBoard[inx+1][iny+1]==opposite(BorW)){//判断周围是否有相反的棋子
for (i=0,x=inx,y=iny;(x<=BOARDSIZE+1)&&(y<=BOARDSIZE+1);x++,y++,i++){//确保可被同化
if (OthelloBoard[x][y]==BorW&&i>1){//确定被同化的子
for (i;i>0&&OthelloBoard[inx+i][iny+i]!=0;i--){
OthelloBoard[inx+i][iny+i]=BorW;//同化
}
}
}
}else
B++;
}
/*同化 扫描*/
void change(BorW){
change_left(BorW);
change_right(BorW);
change_up(BorW);
change_down(BorW);
change_left_up(BorW);
change_right_up(BorW);
change_left_down(BorW);
change_right_down(BorW);
}
/******************************************/
