CResource::~CResource(){ InitGraph(); }
int main(int argc,char *argv[]) { int *g; int *new_g; int *new_edges; int seed = 1; int gsize; int count; int i; int j; int k; int best_count; int best_i; int best_j; void *taboo_list; /* * start with graph of size 15 */ gsize = 15; g = (int *)malloc(gsize*gsize*sizeof(int)); if(g == NULL) { exit(1); } /* * make a fifo to use as the taboo list */ taboo_list = FIFOInitEdge(TABOOSIZE); if(taboo_list == NULL) { exit(1); } /* * start out with half 1 and half 0. */ InitGraph(g, gsize, seed); /* * while we do not have a publishable result */ while(gsize < 102) { /* * find out how we are doing */ count = CliqueCount(g,gsize); /* * if we have a counter example */ if(count == 0) { printf("Eureka! Counter-example found!\n"); PrintGraph(g,gsize); OutputGraph(g,gsize, seed); /* * make a new graph one size bigger */ new_g = (int *)malloc((gsize+1)*(gsize+1)*sizeof(int)); if(new_g == NULL) exit(1); /* * copy the old graph into the new graph leaving the * last row and last column alone */ CopyGraph(g,gsize,new_g,gsize+1); /* * half-half the last column and zero out the last row */ new_edges = (int *)malloc(gsize*sizeof(int)); InitEdges(new_edges, gsize, seed); k = 0; for(i=0; i < gsize; i++) { new_g[i*(gsize+1) + gsize] = new_edges[k]; // last column new_g[gsize*(gsize+1) + i] = 0; // last row k ++; } new_g[(gsize+1)*(gsize+1)] = 0; free(new_edges); /* * throw away the old graph and make new one the * graph */ free(g); g = new_g; gsize = gsize+1; /* * reset the taboo list for the new graph */ taboo_list = FIFOResetEdge(taboo_list); /* * keep going */ continue; } /* * otherwise, we need to consider flipping an edge * * let's speculative flip each edge, record the new count, * and unflip the edge. We'll then remember the best flip and * keep it next time around * * only need to work with upper triangle of matrix => * notice the indices */ best_count = BIGCOUNT; for(i=0; i < gsize; i++) { for(j=i+1; j < gsize; j++) { /* * flip it */ g[i*gsize+j] = 1 - g[i*gsize+j]; //printf("The best count is %d, and the count is %d.", best_count, count); count = CliqueCount_EA(g,gsize,best_count); //count = CliqueCount(g, gsize); /* * is it better and the i,j,count not taboo? */ if((count < best_count) && // !FIFOFindEdge(taboo_list,i,j)) !FIFOFindEdgeCount(taboo_list,i,j,count)) { best_count = count; best_i = i; best_j = j; } /* * flip it back */ g[i*gsize+j] = 1 - g[i*gsize+j]; } } if(best_count == BIGCOUNT) { printf("no best edge found, terminating\n"); exit(1); } /* * keep the best flip we saw */ g[best_i*gsize+best_j] = 1 - g[best_i*gsize+best_j]; /* * taboo this graph configuration so that we don't visit * it again */ count = CliqueCount(g,gsize); // FIFOInsertEdge(taboo_list,best_i,best_j); FIFOInsertEdgeCount(taboo_list,best_i,best_j,count); printf("ce size: %d, best_count: %d, best edge: (%d,%d), new color: %d\n", gsize, best_count, best_i, best_j, g[best_i*gsize+best_j]); /* * rinse and repeat */ } FIFODeleteGraph(taboo_list); return(0); }
/************************************************************************* * This function prunes all the vertices in a graph with degree greater * than factor*average **************************************************************************/ void PruneGraph(CtrlType *ctrl, GraphType *graph, int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *iperm, float factor) { int i, j, k, l, nlarge, pnvtxs, pnedges; idxtype *pxadj, *padjncy; idxtype *perm; perm = idxmalloc(nvtxs, "PruneGraph: perm"); factor = factor*xadj[nvtxs]/nvtxs; pnvtxs = pnedges = nlarge = 0; for (i=0; i<nvtxs; i++) { if (xadj[i+1]-xadj[i] < factor) { perm[i] = pnvtxs; iperm[pnvtxs++] = i; pnedges += xadj[i+1]-xadj[i]; } else { perm[i] = nvtxs - ++nlarge; iperm[nvtxs-nlarge] = i; } } /* printf("Pruned %d vertices\n", nlarge); */ InitGraph(graph); if (nlarge == 0) { /* No prunning */ graph->nvtxs = nvtxs; graph->nedges = xadj[nvtxs]; graph->ncon = 1; graph->xadj = xadj; graph->adjncy = adjncy; graph->gdata = idxmalloc(3*nvtxs+graph->nedges, "CompressGraph: gdata"); graph->vwgt = graph->gdata; graph->adjwgtsum = graph->gdata+nvtxs; graph->cmap = graph->gdata+2*nvtxs; graph->adjwgt = graph->gdata+3*nvtxs; idxset(nvtxs, 1, graph->vwgt); idxset(graph->nedges, 1, graph->adjwgt); for (i=0; i<nvtxs; i++) graph->adjwgtsum[i] = xadj[i+1]-xadj[i]; graph->label = idxmalloc(nvtxs, "CompressGraph: label"); for (i=0; i<nvtxs; i++) graph->label[i] = i; } else { /* Prune the graph */ /* Allocate memory for the compressed graph*/ graph->gdata = idxmalloc(4*pnvtxs+1 + 2*pnedges, "PruneGraph: gdata"); pxadj = graph->xadj = graph->gdata; graph->vwgt = graph->gdata + pnvtxs+1; graph->adjwgtsum = graph->gdata + 2*pnvtxs+1; graph->cmap = graph->gdata + 3*pnvtxs+1; padjncy = graph->adjncy = graph->gdata + 4*pnvtxs+1; graph->adjwgt = graph->gdata + 4*pnvtxs+1 + pnedges; pxadj[0] = pnedges = l = 0; for (i=0; i<nvtxs; i++) { if (xadj[i+1]-xadj[i] < factor) { for (j=xadj[i]; j<xadj[i+1]; j++) { k = perm[adjncy[j]]; if (k < pnvtxs) padjncy[pnedges++] = k; } pxadj[++l] = pnedges; } } graph->nvtxs = pnvtxs; graph->nedges = pnedges; graph->ncon = 1; idxset(pnvtxs, 1, graph->vwgt); idxset(pnedges, 1, graph->adjwgt); for (i=0; i<pnvtxs; i++) graph->adjwgtsum[i] = pxadj[i+1]-pxadj[i]; graph->label = idxmalloc(pnvtxs, "CompressGraph: label"); for (i=0; i<pnvtxs; i++) graph->label[i] = i; } free(perm); }
/************************************************************************* * This function compresses a graph by merging identical vertices * The compression should lead to at least 10% reduction. **************************************************************************/ void CompressGraph(CtrlType *ctrl, GraphType *graph, int nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *cptr, idxtype *cind) { int i, ii, iii, j, jj, k, l, cnvtxs, cnedges; idxtype *cxadj, *cadjncy, *cvwgt, *mark, *map; KeyValueType *keys; mark = idxsmalloc(nvtxs, -1, "CompressGraph: mark"); map = idxsmalloc(nvtxs, -1, "CompressGraph: map"); keys = (KeyValueType *)GKmalloc(nvtxs*sizeof(KeyValueType), "CompressGraph: keys"); /* Compute a key for each adjacency list */ for (i=0; i<nvtxs; i++) { k = 0; for (j=xadj[i]; j<xadj[i+1]; j++) k += adjncy[j]; keys[i].key = k+i; /* Add the diagonal entry as well */ keys[i].val = i; } ikeysort(nvtxs, keys); l = cptr[0] = 0; for (cnvtxs=i=0; i<nvtxs; i++) { ii = keys[i].val; if (map[ii] == -1) { mark[ii] = i; /* Add the diagonal entry */ for (j=xadj[ii]; j<xadj[ii+1]; j++) mark[adjncy[j]] = i; cind[l++] = ii; map[ii] = cnvtxs; for (j=i+1; j<nvtxs; j++) { iii = keys[j].val; if (keys[i].key != keys[j].key || xadj[ii+1]-xadj[ii] != xadj[iii+1]-xadj[iii]) break; /* Break if keys or degrees are different */ if (map[iii] == -1) { /* Do a comparison if iii has not been mapped */ for (jj=xadj[iii]; jj<xadj[iii+1]; jj++) { if (mark[adjncy[jj]] != i) break; } if (jj == xadj[iii+1]) { /* Identical adjacency structure */ map[iii] = cnvtxs; cind[l++] = iii; } } } cptr[++cnvtxs] = l; } } /* printf("Original: %6d, Compressed: %6d\n", nvtxs, cnvtxs); */ InitGraph(graph); if (cnvtxs >= COMPRESSION_FRACTION*nvtxs) { graph->nvtxs = nvtxs; graph->nedges = xadj[nvtxs]; graph->ncon = 1; graph->xadj = xadj; graph->adjncy = adjncy; graph->gdata = idxmalloc(3*nvtxs+graph->nedges, "CompressGraph: gdata"); graph->vwgt = graph->gdata; graph->adjwgtsum = graph->gdata+nvtxs; graph->cmap = graph->gdata+2*nvtxs; graph->adjwgt = graph->gdata+3*nvtxs; idxset(nvtxs, 1, graph->vwgt); idxset(graph->nedges, 1, graph->adjwgt); for (i=0; i<nvtxs; i++) graph->adjwgtsum[i] = xadj[i+1]-xadj[i]; graph->label = idxmalloc(nvtxs, "CompressGraph: label"); for (i=0; i<nvtxs; i++) graph->label[i] = i; } else { /* Ok, form the compressed graph */ cnedges = 0; for (i=0; i<cnvtxs; i++) { ii = cind[cptr[i]]; cnedges += xadj[ii+1]-xadj[ii]; } /* Allocate memory for the compressed graph*/ graph->gdata = idxmalloc(4*cnvtxs+1 + 2*cnedges, "CompressGraph: gdata"); cxadj = graph->xadj = graph->gdata; cvwgt = graph->vwgt = graph->gdata + cnvtxs+1; graph->adjwgtsum = graph->gdata + 2*cnvtxs+1; graph->cmap = graph->gdata + 3*cnvtxs+1; cadjncy = graph->adjncy = graph->gdata + 4*cnvtxs+1; graph->adjwgt = graph->gdata + 4*cnvtxs+1 + cnedges; /* Now go and compress the graph */ idxset(nvtxs, -1, mark); l = cxadj[0] = 0; for (i=0; i<cnvtxs; i++) { cvwgt[i] = cptr[i+1]-cptr[i]; mark[i] = i; /* Remove any dioganal entries in the compressed graph */ for (j=cptr[i]; j<cptr[i+1]; j++) { ii = cind[j]; for (jj=xadj[ii]; jj<xadj[ii+1]; jj++) { k = map[adjncy[jj]]; if (mark[k] != i) cadjncy[l++] = k; mark[k] = i; } } cxadj[i+1] = l; } graph->nvtxs = cnvtxs; graph->nedges = l; graph->ncon = 1; idxset(graph->nedges, 1, graph->adjwgt); for (i=0; i<cnvtxs; i++) graph->adjwgtsum[i] = cxadj[i+1]-cxadj[i]; graph->label = idxmalloc(cnvtxs, "CompressGraph: label"); for (i=0; i<cnvtxs; i++) graph->label[i] = i; } GKfree(&keys, &map, &mark, LTERM); }
/************************************************************************* * This function sets up the graph from the user input **************************************************************************/ void SetUpGraph(GraphType *graph, int OpType, int nvtxs, int ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *adjwgt, int wgtflag) { int i, j, k, sum, gsize; float *nvwgt; idxtype tvwgt[MAXNCON]; if (OpType == OP_KMETIS && ncon == 1 && (wgtflag&2) == 0 && (wgtflag&1) == 0) { SetUpGraphKway(graph, nvtxs, xadj, adjncy); return; } InitGraph(graph); graph->nvtxs = nvtxs; graph->nedges = xadj[nvtxs]; graph->ncon = ncon; graph->xadj = xadj; graph->adjncy = adjncy; if (ncon == 1) { /* We are in the non mC mode */ gsize = 0; if ((wgtflag&2) == 0) gsize += nvtxs; if ((wgtflag&1) == 0) gsize += graph->nedges; gsize += 2*nvtxs; graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); /* Create the vertex/edge weight vectors if they are not supplied */ gsize = 0; if ((wgtflag&2) == 0) { vwgt = graph->vwgt = idxset(nvtxs, 1, graph->gdata); gsize += nvtxs; } else graph->vwgt = vwgt; if ((wgtflag&1) == 0) { adjwgt = graph->adjwgt = idxset(graph->nedges, 1, graph->gdata+gsize); gsize += graph->nedges; } else graph->adjwgt = adjwgt; /* Compute the initial values of the adjwgtsum */ graph->adjwgtsum = graph->gdata + gsize; gsize += nvtxs; for (i=0; i<nvtxs; i++) { sum = 0; for (j=xadj[i]; j<xadj[i+1]; j++) sum += adjwgt[j]; graph->adjwgtsum[i] = sum; } graph->cmap = graph->gdata + gsize; gsize += nvtxs; } else { /* Set up the graph in MOC mode */ gsize = 0; if ((wgtflag&1) == 0) gsize += graph->nedges; gsize += 2*nvtxs; graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); gsize = 0; for (i=0; i<ncon; i++) tvwgt[i] = idxsum_strd(nvtxs, vwgt+i, ncon); nvwgt = graph->nvwgt = fmalloc(ncon*nvtxs, "SetUpGraph: nvwgt"); for (i=0; i<nvtxs; i++) { for (j=0; j<ncon; j++) nvwgt[i*ncon+j] = (1.0*vwgt[i*ncon+j])/(1.0*tvwgt[j]); } /* Create the edge weight vectors if they are not supplied */ if ((wgtflag&1) == 0) { adjwgt = graph->adjwgt = idxset(graph->nedges, 1, graph->gdata+gsize); gsize += graph->nedges; } else graph->adjwgt = adjwgt; /* Compute the initial values of the adjwgtsum */ graph->adjwgtsum = graph->gdata + gsize; gsize += nvtxs; for (i=0; i<nvtxs; i++) { sum = 0; for (j=xadj[i]; j<xadj[i+1]; j++) sum += adjwgt[j]; graph->adjwgtsum[i] = sum; } graph->cmap = graph->gdata + gsize; gsize += nvtxs; } if (OpType != OP_KMETIS && OpType != OP_KVMETIS) { graph->label = idxmalloc(nvtxs, "SetUpGraph: label"); for (i=0; i<nvtxs; i++) graph->label[i] = i; } }
/************************************************************************* * This function sets up the graph from the user input **************************************************************************/ void VolSetUpGraph(GraphType *graph, int OpType, int nvtxs, int ncon, idxtype *xadj, idxtype *adjncy, idxtype *vwgt, idxtype *vsize, int wgtflag) { int i, j, k, sum, gsize; idxtype *adjwgt; float *nvwgt; idxtype tvwgt[MAXNCON]; InitGraph(graph); graph->nvtxs = nvtxs; graph->nedges = xadj[nvtxs]; graph->ncon = ncon; graph->xadj = xadj; graph->adjncy = adjncy; if (ncon == 1) { /* We are in the non mC mode */ gsize = graph->nedges; /* This is for the edge weights */ if ((wgtflag&2) == 0) gsize += nvtxs; /* vwgts */ if ((wgtflag&1) == 0) gsize += nvtxs; /* vsize */ gsize += 2*nvtxs; graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); /* Create the vertex/edge weight vectors if they are not supplied */ gsize = 0; if ((wgtflag&2) == 0) { vwgt = graph->vwgt = idxset(nvtxs, 1, graph->gdata); gsize += nvtxs; } else graph->vwgt = vwgt; if ((wgtflag&1) == 0) { vsize = graph->vsize = idxset(nvtxs, 1, graph->gdata); gsize += nvtxs; } else graph->vsize = vsize; /* Allocate memory for edge weights and initialize them to the sum of the vsize */ adjwgt = graph->adjwgt = graph->gdata+gsize; gsize += graph->nedges; for (i=0; i<nvtxs; i++) { for (j=xadj[i]; j<xadj[i+1]; j++) adjwgt[j] = 1+vsize[i]+vsize[adjncy[j]]; } /* Compute the initial values of the adjwgtsum */ graph->adjwgtsum = graph->gdata + gsize; gsize += nvtxs; for (i=0; i<nvtxs; i++) { sum = 0; for (j=xadj[i]; j<xadj[i+1]; j++) sum += adjwgt[j]; graph->adjwgtsum[i] = sum; } graph->cmap = graph->gdata + gsize; gsize += nvtxs; } else { /* Set up the graph in MOC mode */ gsize = graph->nedges; if ((wgtflag&1) == 0) gsize += nvtxs; gsize += 2*nvtxs; graph->gdata = idxmalloc(gsize, "SetUpGraph: gdata"); gsize = 0; /* Create the normalized vertex weights along each constrain */ if ((wgtflag&2) == 0) vwgt = idxsmalloc(nvtxs, 1, "SetUpGraph: vwgt"); for (i=0; i<ncon; i++) tvwgt[i] = idxsum_strd(nvtxs, vwgt+i, ncon); nvwgt = graph->nvwgt = fmalloc(ncon*nvtxs, "SetUpGraph: nvwgt"); for (i=0; i<nvtxs; i++) { for (j=0; j<ncon; j++) nvwgt[i*ncon+j] = (1.0*vwgt[i*ncon+j])/(1.0*tvwgt[j]); } if ((wgtflag&2) == 0) free(vwgt); /* Create the vsize vector if it is not supplied */ if ((wgtflag&1) == 0) { vsize = graph->vsize = idxset(nvtxs, 1, graph->gdata); gsize += nvtxs; } else graph->vsize = vsize; /* Allocate memory for edge weights and initialize them to the sum of the vsize */ adjwgt = graph->adjwgt = graph->gdata+gsize; gsize += graph->nedges; for (i=0; i<nvtxs; i++) { for (j=xadj[i]; j<xadj[i+1]; j++) adjwgt[j] = 1+vsize[i]+vsize[adjncy[j]]; } /* Compute the initial values of the adjwgtsum */ graph->adjwgtsum = graph->gdata + gsize; gsize += nvtxs; for (i=0; i<nvtxs; i++) { sum = 0; for (j=xadj[i]; j<xadj[i+1]; j++) sum += adjwgt[j]; graph->adjwgtsum[i] = sum; } graph->cmap = graph->gdata + gsize; gsize += nvtxs; } if (OpType != OP_KVMETIS) { graph->label = idxmalloc(nvtxs, "SetUpGraph: label"); for (i=0; i<nvtxs; i++) graph->label[i] = i; } }
/************************************************************************* * This function reads the spd matrix **************************************************************************/ void ReadGraph(GraphType *graph, char *filename, int *wgtflag) { int i, j, k, l, fmt, readew, readvw, ncon, edge, ewgt; idxtype *xadj, *adjncy, *vwgt, *adjwgt; char *line, *oldstr, *newstr; FILE *fpin; InitGraph(graph); line = (char *)malloc(sizeof(char)*(MAXLINE+1)); if ((fpin = fopen(filename, "r")) == NULL) { printf("Failed to open file %s\n", filename); exit(0); } while (fgets(line, MAXLINE, fpin) && line[0] == '%'); if (feof(fpin)) { graph->nvtxs = 0; free(line); return; } fmt = ncon = 0; sscanf(line, "%d %d %d %d", &(graph->nvtxs), &(graph->nedges), &fmt, &ncon); readew = (fmt%10 > 0); readvw = ((fmt/10)%10 > 0); if (fmt >= 100) { printf("Cannot read this type of file format!"); exit(0); } *wgtflag = 0; if (readew) *wgtflag += 1; if (readvw) *wgtflag += 2; if (ncon > 0 && !readvw) { printf("------------------------------------------------------------------------------\n"); printf("*** I detected an error in your input file ***\n\n"); printf("You specified ncon=%d, but the fmt parameter does not specify vertex weights\n", ncon); printf("Make sure that the fmt parameter is set to either 10 or 11.\n"); printf("------------------------------------------------------------------------------\n"); exit(0); } graph->nedges *=2; ncon = graph->ncon = (ncon == 0 ? 1 : ncon); /*printf("%d %d %d %d %d [%d %d]\n", fmt, fmt%10, (fmt/10)%10, ncon, graph->ncon, readew, readvw);*/ if (graph->nvtxs > MAXIDX) errexit("\nThe matrix is too big: %d [%d %d]\n", graph->nvtxs, MAXIDX, sizeof(idxtype)); xadj = graph->xadj = idxsmalloc(graph->nvtxs+1, 0, "ReadGraph: xadj"); adjncy = graph->adjncy = idxmalloc(graph->nedges, "ReadGraph: adjncy"); vwgt = graph->vwgt = (readvw ? idxmalloc(ncon*graph->nvtxs, "ReadGraph: vwgt") : NULL); adjwgt = graph->adjwgt = (readew ? idxmalloc(graph->nedges, "ReadGraph: adjwgt") : NULL); /* Start reading the graph file */ for (xadj[0]=0, k=0, i=0; i<graph->nvtxs; i++) { while ((oldstr = fgets(line, MAXLINE, fpin)) && line[0] == '%'); /* skip lines with '#' */ if (oldstr == NULL && feof(fpin)) { printf("------------------------------------------------------------------------------\n"); printf("Premature end of input file when reading the adjacency list for vertex %d\n", i+1); printf("------------------------------------------------------------------------------\n"); exit(0); } oldstr = line; newstr = NULL; if (strlen(line) == MAXLINE) errexit("\nBuffer for fgets not big enough!\n"); if (readvw) { for (l=0; l<ncon; l++) { vwgt[i*ncon+l] = (int)strtol(oldstr, &newstr, 10); oldstr = newstr; } } for (;;) { edge = (int)strtol(oldstr, &newstr, 10) -1; oldstr = newstr; if (readew) { ewgt = (int)strtol(oldstr, &newstr, 10); oldstr = newstr; } if (edge < 0) break; adjncy[k] = edge; if (readew) adjwgt[k] = ewgt; k++; } xadj[i+1] = k; } fclose(fpin); if (k != graph->nedges) { printf("------------------------------------------------------------------------------\n"); printf("*** I detected an error in your input file ***\n\n"); printf("In the first line of the file, you specified that the graph contained\n%d edges. However, I only found %d edges in the file.\n", graph->nedges/2, k/2); if (2*k == graph->nedges) { printf("\n *> I detected that you specified twice the number of edges that you have in\n"); printf(" the file. Remember that the number of edges specified in the first line\n"); printf(" counts each edge between vertices v and u only once.\n\n"); } printf("Please specify the correct number of edges in the first line of the file.\n"); printf("------------------------------------------------------------------------------\n"); exit(0); } free(line); }
void beforegame() /******游戏主界面*******/ { int i,j; fire(); ShowBmp256(70,65,".\\source\\login.bmp",1,0); InitGraph(); star=malloc(sizeof(struct STAR)*STARNUM); initstar(star); InitMouse(0,0,maxx,maxy); getdat(); handler=getvect(0x1c); mousex=getmaxx()/2; mousey=getmaxy()/2; logo=bmp_to_dat(".\\source\\snooker.bmp"); vs1=bmp_to_dat(".\\source\\head0.bmp"); vs2=bmp_to_dat(".\\source\\head1.bmp"); play(1); for (i=0;i<3;i++) { putimage(0,0,logo,NOT_PUT); for (j=20;j<=1000;j+=10) { delay(1000); } delay(3000); putimage(0,0,logo,COPY_PUT); for (j=1000;j>=20;j-=10) { delay(2000); } delay(3000); } putimage(0,0,logo,COPY_PUT); for (i=0;i<STARNUM;i++) drawstar(star); outchinese(400,80,s_cn,EOF,4,2); putimage(300,280,vs1,COPY_PUT); putimage(520,280,vs2,COPY_PUT); settextstyle(1,0,12); setcolor(GREEN); outtextxy(380,260,"Vs"); drawmouse(mousex,mousey); play(2); drawmenu(mm); while(1) { while(bioskey(1)!=0) getch(); position(1); mm=fill(); drawmouse(mousex,mousey); if (button==1) { switch (mm) { case 0: { free(logo); free(star); cleardevice(); return; } case 1: { practice(); restore(); break; } case 2: { noplay(); option(); break; } case 3: { noplay(); toprank(); restore(); break; } case 4: { if (Music_on==1) play(0); showhelp(); break; } case 5: { position(0); End(1); drawmouse(mousex,mousey); break; } } } button=0; } }
void standard() { int i,j,k=0; int a=150,b=105; unsigned long gsize; /*计算器按钮标签文本字符 */ char str[][5]={"1","2","3","-","/","4","5","6","*","Sqrt","7","8","9","1/x","C"}; char temp[6]=""; InitGraph(); cleardevice(); setbkcolor(BLACK); setfillstyle(SOLID_FILL,LIGHTGRAY); bar3d(130,45,500,280,10,1); /* 计算器外框 */ setcolor(DARKGRAY); line(150,60,150,90); line(150,90,480,90); setcolor(WHITE); line(150,60,480,60); line(480,60,480,90); setfillstyle(SOLID_FILL,YELLOW); bar(150,60,480,90); /* 绘制信息显示框 */ setfillstyle(SOLID_FILL,LIGHTGRAY); for(i=0;i<5;i++) /* 绘制计算器按钮框 */ for(j=0;j<4;j++) { bar(a+i*70,b+j*45,a+50+i*70,b+30+j*45); bottonup(a+i*70,a+i*70+50,b+j*45,b+j*45+30); } setcolor(YELLOW); settextstyle(1,0,1); bar(120,315,550,345); bottonup(120,550,315,345); bar(120,350,550,380); bottonup(120,550,350,380); bar(120,385,550,415); bottonup(120,550,385,415); bar(120,420,550,470); bottonup(120,550,420,470); setcolor(YELLOW); settextstyle(1,0,1); outtextxy(30,290,"control with left-click or keyboard,right-click or Esc to exit."); outtextxy(130,321,"Switch to scientific mode."); outtextxy(130,356,"Switch to statistics mode."); outtextxy(130,391,"switch to high-precision calculation mode."); settextstyle(1,0,3); setcolor(RED); outtextxy(283,433,"HELP"); settextstyle(1,0,3); setcolor(YELLOW); outtextxy(260,10,"standard mode"); settextstyle(1,0,2); setcolor(GREEN); for(j=0;j<3;j++) for(i=0;i<5;i++) /* 显示计算器前三排按钮标签 */ { strcpy(temp,str[k++]); if (temp[0]=='S') {outtextxy(a+6+70*i,200-j*45,temp);continue;} if (temp[0]=='1') {outtextxy(a+10+70*i,200-j*45,temp);continue;} outtextxy(a+17+70*i,200-j*45,temp); } outtextxy(167,245,"0"); /* 显示计算器最后一排按钮标签 */ outtextxy(377,245,"+"); outtextxy(447,245,"="); settextstyle(1,0,3); outtextxy(310,235,"."); settextstyle(1,0,2); outtextxy(228,243,"+"); outtextxy(237,246,"/"); outtextxy(246,250,"-"); setcolor(BLACK); }
Palette256(char *p) { InitGraph(); LoadPalette(p); SetHardPalette(); };
Palette256(){InitGraph();};