📄 wuzi.cpp
字号:
/*------------------------------ Wuziai52.cpp -------------------------------------------------
Programmer : FeiJia(TIIM)
Zhejiang University Computer Science 2000
Version: 0.2 Builder 2001.05.01
Evaluate version: 4.30.01
Ai version: 5.09.01
Board Area :15*15
Total line number:1555
Use Turbo C++3.0
Try to use digui:
-----------------------------------------------------------------------*/
#include"math.h"
#include"conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "graphics.h"
#include "dos.h"
#include"ourmouse.h"
#include"wuzi.h"
#include"bmp16.h"
#define LEFT 1
#define TRUE 1
#define FALSE 0
#define RADIUS 7
#define MAXDEPTH 190
#define OUTSTEP 1
#define QIPANWIDTH 280
#define QIPANHEIGHT 280
#define QIPANX 180
#define QIPANY 100
#define QIPANAREA 15
#define VERSION 0.2
int man=1;
int Manandcom=1; /*manandcom==1 means manand computer,else manandcom==-1,manandman*/
long FIVE=1000000,LIVEFOUR=10000;
long CRACKFOUR=2500,LIVETHREE=2500;
long CRACKTHREE=500,LIVETWO=100,CRACKTWO=10, ONE=10,CRACKONE=10;
static int stepnum=1;
int flag;
int whofirst=-1;
int matrix[19][19]={0};
int oldmatrix1[19][19]={0};
int oldmatrix2[19][19]={0};
int paintnow=FALSE;
/* typedef struct MARK
{
int five,livefour,crackfour,hopfour,hopthree,livethree;
int crackthree,livetwo,cracktwo,one;
long mark;
int i,j;
} MARK; */
MARK initialmark(MARK x)
{
x.five=0;
x.livefour=0;
x.crackfour=0;
x.hopfour=0;
x.hopthree=0;
x.livethree=0;
x.crackthree=0;
x.livetwo=0;
x.cracktwo=0;
x.one=0;
x.mark=0;
x.i=1;
x.j=1;
return (x);
}
/*----------------A struct for Buttons----------*/
BUTTON StartBtn={150,430,60,25,""},
ChangeBtn={250,430,65,25,""},
RegretBtn={340,430,65,25,""},
ManandcomBtn={430,430,75,25,""},
ExitBtn={550,430,65,25,""};
/*---------function declaration--------------------------*/
/*int initmouse();
void showmouse();
void hidemouse();
void readmouse(int *f,int *x,int *y);
void paint_qipan();
int iffive(int i,int j, int who);
int paint_qizi(int x,int y,int who);
void paint_button(BUTTON Button);
void setup_screen();
void ButtonDown(BUTTON button);
MARK evaluate(int i,int j,int who);
int ai(int depth,int who);
void StartBtn_clicked();
void RegretBtn_clicked(void);
void anytoprocess(int x,int y,int f); */
/* ---------------------------- paint the qipan------------------*/
void paint_qipan()
{int i=QIPANX,j=QIPANY,width=QIPANWIDTH,height=QIPANHEIGHT;
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
setfillstyle(1,15);
bar(0,0,320,479);
setfillstyle(1,0);
bar(320,0,639,479);
setfillstyle(1,6);
bar(i-25,j-25,i+width+25,j+height+25);
rectangle(i,j,i+width,j+height);
setcolor(WHITE);
line(i-10,j-10,i+width+10,j-10);
line(i-10,j-10,i-10,j+height+10);
setcolor(BLACK);
line(i-10,j+height+10,i+width+10,j+height+10);
line(i-10,j+height+11,i+width+10,j+height+11);
line(i+width+10,j-10,i+width+10,j+height+10);
line(i+width+11,j-10,i+width+11,j+height+10);
moveto(i,j);
for(i=QIPANX;i<=QIPANX+QIPANWIDTH;i+=20)
line(i,QIPANY,i,QIPANY+QIPANHEIGHT);
for(j=QIPANY;j<=QIPANY+QIPANHEIGHT;j+=20)
line(QIPANX,j,QIPANX+QIPANWIDTH,j);
for(i=1;i<=15;i++)
{ char *s;
sprintf(s,"%d",i);
if(i<=9)
outtextxy(QIPANX+i*20-23,QIPANY-20,s);
else
outtextxy(QIPANX+i*20-25,QIPANY-20,s); }
for(j=1;j<=15;j++)
{ char *s;
sprintf(s,"%d",j);
if(j<=9)
outtextxy(QIPANX-20,QIPANY+j*20-23,s);
else
outtextxy(QIPANX-30,QIPANY+j*20-23,s); }
setfillstyle(1,0);
/*---------Paint five points-----------------*/
// circle(320,240,2);
circle(QIPANX+QIPANWIDTH/2,QIPANY+QIPANHEIGHT/2,2);
floodfill(QIPANX+QIPANWIDTH/2+1,QIPANY+QIPANHEIGHT/2+1,0);
floodfill(QIPANX+QIPANWIDTH/2-1,QIPANY+QIPANHEIGHT/2-1,0);
floodfill(QIPANX+QIPANWIDTH/2+1,QIPANY+QIPANHEIGHT/2-1,0);
floodfill(QIPANX+QIPANWIDTH/2-1,QIPANY+QIPANHEIGHT/2+1,0);
circle(240,160,2);
floodfill(241,159,0);
floodfill(241,161,0);
floodfill(239,161,0);
floodfill(239,159,0);
circle(400,160,2);
floodfill(401,161,0);
floodfill(401,159,0);
floodfill(399,159,0);
floodfill(399,161,0);
circle(240,320,2);
floodfill(241,321,0);
floodfill(241,319,0);
floodfill(239,319,0);
floodfill(239,321,0);
circle(400,320,2);
floodfill(401,321,0);
floodfill(401,319,0);
floodfill(399,321,0);
floodfill(399,319,0);
char *version;
char *author;
char *name;
name="WUZIQI";
version="Ver 0.2;\nBuild 5.01.01";
author="Programmer :FeiJia(tiim)";
outtextxy(10,10,name);
outtextxy(10,30,author);
outtextxy(10,40,version);
}
/* //////////////////
//A function which know whether the black or white has won the game:
///////////////////
//////// */
int iffive(int i,int j, int who)
{
int count1,count2,count,lthorf=0,ci,cj,mark,tmd;
int countline,countcolum;
char *str;
str=(who==1)?"BLACK WIN!":"WHITE WIN!";
tmd=0;
/* 1.line */
count1=0;
count2=0;
ci=i;
cj=j;
while(matrix[i][cj+1]==who)
{
count1++;
cj++;
if(cj>15)
break;
}
cj=j;
while(matrix[i][cj-1]==who)
{
count2++;
cj--;
if(cj<1)
break;
}
countline=count1+count2+1;
if(countline==5)
tmd=1;
/*2colum*/
count1=0;
count2=0;
ci=i;
cj=j;
while(matrix[ci+1][j]==who)
{
count1++;
ci++;
if(cj>15)
break;
}
ci=i;
while(matrix[ci-1][j]==who)
{
count2++;
ci--;
if(cj<1)
break;
}
countcolum=count1+count2+1;
if(countcolum==5)
{
tmd=1;
}
/*left lean*/
count1=0;
count2=0;
ci=i;
cj=j;
while(matrix[ci+1][cj+1]==who)
{
count1++;
cj++;
ci++;
if((cj>15)||(ci>15))
break;
}
cj=j;
ci=i;
while(matrix[ci-1][cj-1]==who)
{
count2++;
cj--;
ci--;
if((cj<1)||(ci<1))
break;
}
count=count1+count2+1;
if(count==5)
tmd=1;
/*right lean*/
count1=0;
count2=0;
ci=i;
cj=j;
while(matrix[ci-1][cj+1]==who)
{
count1++;
cj++;
ci--;
if((cj>15)||(ci<1))
break;
}
cj=j;
ci=i;
while(matrix[ci+1][cj-1]==who)
{
count2++;
ci++;
cj--;
if((cj<1)||(ci>15))
break;
}
count=count1+count2+1;
if(count==5)
tmd=1;
if(tmd==1)
{ int color;
color=getcolor();
setcolor(0);
textsettingstype textinfo;
gettextsettings(&textinfo);
settextstyle(DEFAULT_FONT,HORIZ_DIR,3);
outtextxy(200,230,str);
settextstyle(textinfo.font,textinfo.direction,textinfo.charsize);
setcolor(color);
paintnow=FALSE;
return(tmd);
}
else if(tmd==0)
{return(tmd);
}
}
int paint_qizi(int x,int y,int who)
{
int color;
color=(who==1)?BLACK:WHITE;
int xx,yy,tx,ty;
xx=(int)(((float)x/20)+0.5)*20;
yy=(int)(((float)y/20)+0.5)*20;
tx=(xx+20-QIPANX)/20;
ty=(yy+20-QIPANY)/20;
hidemouse();
setcolor(color);
circle(xx,yy,RADIUS);
setfillstyle(1,color);
floodfill(xx-3,yy-3,color);
floodfill(xx+3,yy+3,color);
floodfill(xx-3,yy+3,color);
floodfill(xx+3,yy-3,color);
showmouse();
matrix[tx][ty]=who;
if(iffive(tx,ty,who))
return (0);
else
return (1);
}
void paint_button(BUTTON Button)
{
setfillstyle(1,LIGHTGRAY);
bar(Button.x,Button.y,Button.x+Button.width,Button.y+Button.height);
moveto(Button.x,Button.y);
setcolor(WHITE);
linerel(0,Button.height);
moveto(Button.x,Button.y);
linerel(Button.width,0);
setcolor(BLACK);
linerel(0,Button.height);
linerel(-Button.width,0);
setcolor(DARKGRAY);
outtextxy(Button.x+10,Button.y+10,Button.name);
}
void setup_screen()
{
paint_qipan();
paint_button(StartBtn);
paint_button(ChangeBtn);
paint_button(ExitBtn);
paint_button(RegretBtn);
paint_button(ManandcomBtn);
ShowBmp16("wuzibtn.bmp",100,300);
ShowBmp16("wuzistar.bmp",450,0);
//putimage(400,0,buf_wavestar,COPY_PUT);
}
void ButtonDown(BUTTON button)
{ setcolor(BLUE);
moveto(button.x+button.width,button.y);
hidemouse();
linerel(-button.width,0);
linerel(0,button.height);
setcolor(WHITE);
linerel(button.width,0);
linerel(0,-button.height);
showmouse();
delay(200);
hidemouse();
moveto(button.x+button.width,button.y);
linerel(-button.width,0);
linerel(0,button.height);
setcolor(BLACK);
linerel(button.width,0);
linerel(0,-button.height);
showmouse();
}
/* //////////////////////////
//The most important part of this game ,this function can give every
//step a mark. evaluate ver5.14.
/////////////////
////////// */
MARK evaluate(int i,int j,int who)
{
int count1,count2,count,lthorf=0,ci,cj;
MARK mark;
int countline,countcolum;
mark=initialmark(mark);
if(stepnum<=3)
LIVETWO=LIVETHREE;
else
LIVETWO=100;
/* you must know there are some effects caused by the borderling */
/* column*/
count1=0;
count2=0;
ci=i;
cj=j;
while(matrix[i][cj+1]==who)
{
count1++;
cj++;
if(cj>15)
break;
}
cj=j;
while(matrix[i][cj-1]==who)
{
count2++;
cj--;
if(cj<1)
break;
}
countline=count1+count2+1;
switch (countline)
{ case 5:
mark.five++;
break;
case 4:
// if(j+count1+1<=15&&j-count2-1>=0)
if(matrix[i][j+count1+1]==0&&matrix[i][j-count2-1]==0)
{
mark.livefour++;
break;
}
else if(matrix[i][j+count1+1]==0||matrix[i][j-count2-1]==0)
{
mark.crackfour++;
lthorf+=1;
break;
}
else
break;
case 3:
if((matrix[i][j+count1+1]==0&&matrix[i][j+count1+2]==who)
||(matrix[i][j-count2-1]==0&&matrix[i][j-count2-2]==who))
{
mark.crackfour++;
// mark.livethree--;
lthorf++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -