魔方算法源代码_第1页
魔方算法源代码_第2页
魔方算法源代码_第3页
魔方算法源代码_第4页
魔方算法源代码_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.#include graphics.h#include stdio.hint color69=4,4,4,4,4,4,4,4,4, 2,2,2,2,2,2,2,2,2, 14,14,14,14,14,14,14,14,14, 15,15,15,15,15,15,15,15,15, 7,7,7,7,7,7,7,7,7, 9,9,9,9,9,9,9,9,9;int column69=195,255,315,345,375,315,255,225,285, 180,180,180,240,300,300,300,240,240, 345,345,345,375,405,405,405,375,37

2、5, 470,470,470,530,590,590,590,530,530, 55,55,55,85,115,115,115,85,85, 195,255,315,345,375,315,255,225,285;int row69=135,135,135,105,75,75,75,105,105, 180,240,300,300,300,240,180,180,240, 165,225,285,255,225,165,105,135,185, 90,150,210,210,210,150,90,90,150, 165,225,285,255,225,165,105,135,185, 425,

3、425,425,395,365,365,365,395,395;void boxinit() setcolor(CYAN); moveto(150,150); lineto(330,150); line(150,210,330,210); line(150,270,330,270); line(150,330,330,330); line(180,120,360,120); line(210,90,390,90); line(240,60,420,60); line(360,120,360,300); line(390,90,390,270); line(420,60,420,240); li

4、ne(330,210,420,120); line(330,270,420,180); line(330,330,420,240); line(330,150,420,60); line(330,150,330,330); line(270,150,270,330); line(210,150,210,330); line(150,150,150,330); line(150,150,240,60); line(210,150,300,60); line(270,150,360,60); moveto(40,150); lineto(130,60); lineto(130,240); line

5、to(40,330); lineto(40,150); line(70,120,70,300); line(100,90,100,270); line(40,210,130,120); line(40,270,130,180); moveto(440,60); lineto(620,60); lineto(620,240); lineto(440,240); lineto(440,60); line(440,120,620,120); line(440,180,620,180); line(500,60,500,240); line(560,60,560,240); moveto(150,44

6、0); lineto(330,440); lineto(420,350); lineto(240,350); lineto(150,440); line(210,440,300,350); line(270,440,360,350); line(180,410,360,410); line(210,380,390,380);void temp() delay(1);void upcolor()int i,j; for(i=0;i6;i+) for(j=0;j9;j+) setfillstyle(1,colorij); floodfill(columnij,rowij,CYAN); temp()

7、;/该函数实现边面转90度的功能/bt为要转的边面void borderturn(int bt)int x1,x2; x1=colorbt0; x2=colorbt1; colorbt0=colorbt2; colorbt1=colorbt3; colorbt2=colorbt4; colorbt3=colorbt5; colorbt4=colorbt6; colorbt5=colorbt7; colorbt6=x1; colorbt7=x2;/该函数实现中间面转90度的功能/x1,x2,x3,x4为旋转涉及到的面参数,x5-x16为正方形参数说明是哪个正方形参与了旋转/其中x5,x6,x7为

8、x1面的/x8,x9,x10为x2面的/x11,x12,x13为x3面的/x14,x15,x16为x4面的/中间面旋转涉及到四个面的变化void medturn(int x1,int x2,int x3,int x4,int x5,int x6,int x7,int x8, int x9,int x10,int x11,int x12,int x13,int x14,int x15,int x16)int y1,y2,y3; y1=colorx1x5; y2=colorx1x6; y3=colorx1x7; colorx1x5=colorx2x8; colorx1x6=colorx2x9; c

9、olorx1x7=colorx2x10; colorx2x8=colorx3x11; colorx2x9=colorx3x12; colorx2x10=colorx3x13; colorx3x11=colorx4x14; colorx3x12=colorx4x15; colorx3x13=colorx4x16; colorx4x14=y1; colorx4x15=y2; colorx4x16=y3;/函数实现UP面顺时针转90*i度的功能void turn1(int i)int k; for(k=0;ki;k+) borderturn(0); medturn(1,2,3,4,0,7,6,0,7

10、,6,6,7,0,6,7,0); /函数实现UP面和DOWN面中间层顺时针转90*i度的功能void turn2(int i)int k; for(k=0;ki;k+) medturn(1,2,3,4,1,8,5,1,8,5,5,8,1,5,8,1); /函数实现DOWN面顺时针转90*i度的功能void turn3(int i)int k; for(k=0;ki;k+) borderturn(5); medturn(1,2,3,4,2,3,4,2,3,4,4,3,2,4,3,2); /函数实现FRONT面顺时针转90*i度的功能void turn4(int i)int k; for(k=0;

11、ki;k+) borderturn(1); medturn(4,5,2,0,0,1,2,0,1,2,2,1,0,2,1,0); /函数实现FRONT面和BACK面的中间层顺时针转90*i度的功能void turn5(int i)int k; for(k=0;ki;k+) medturn(4,5,2,0,7,8,3,7,8,3,3,8,7,3,8,7); /函数实现BACK面顺时针转90*i度的功能void turn6(int i)int k; for(k=0;ki;k+) borderturn(3); medturn(4,5,2,0,6,5,4,6,5,4,4,5,6,4,5,6); /函数实

12、现RIGHT面顺时针转90*i度的功能void turn7(int i)int k; for(k=0;ki;k+) borderturn(2); medturn(1,5,3,0,6,5,4,2,3,4,4,5,6,4,3,2); /函数实现LEFT面和RIGHT面的中间层顺时针转90*i度的功能void turn8(int i)int k; for(k=0;ki;k+) medturn(1,5,3,0,7,8,3,1,8,5,3,8,7,5,8,1); /函数实现LEFT面顺时针转90*i度的功能void turn9(int i)int k; for(k=0;ki;k+) borderturn

13、(4); medturn(1,5,3,0,0,1,2,0,7,6,2,1,0,6,7,0); /实现i次L-E-L-U-L-E-L-U功能void turna(int i)int k; for(k=0;ki;k+) turn9(1);/L turn2(3);/E turn9(3);/L turn1(1);/U turn9(1);/L turn2(1);/E turn9(3);/L turn1(3);/U /实现i次R-E-R-U-R-E-U功能void turnb(int i)int k; for(k=0;ki;k+) turn7(1);/R turn2(1);/E turn7(3);/R t

14、urn1(3);/U turn7(1);/R turn2(3);/E turn7(3);/R turn1(1);/U void turnc(int i)int k; for(k=0;ki;k+) turn7(1); turn9(1); turn1(3); turn9(3); turn1(1); turn7(3); turn1(3); turn9(1); turn1(1); turn9(3); void turnd(int i)int k; for(k=0;ki;k+) turn9(1); turn7(1); turn1(1); turn7(3); turn1(3); turn9(3); tur

15、n1(1); turn7(1); turn1(3); turn7(3); void turne(int i)int k; for(k=0;ki;k+) turn7(3); turn3(1); turn7(1); turn3(3); turn4(1); turn3(3); turn4(3); void turnf(int i)int k; for(k=0;ki;k+) turn4(1); turn2(1); turn9(1); turn2(3); turn4(1); void turnc1(int i)int k; for(k=0;ki;k+) turn4(3); turn2(3); turn7

16、(1); turn2(1); turn4(3); void turnd1(int i)int k; for(k=0;ki;k+) turn8(1); turn9(1); turnd(1); turn8(3); turn9(3); void turnb1(int i)int k; for(k=0;ki;k+) turn7(1); turnd(1); turn7(3); void turnlast()int k,total,k1,total1,i,j,c0,c1,c2,c3,c4,c5; c0=color08; c5=color58; /*对好第一层的十字架 */ total=0; while(t

17、otal4) break; i+; if(i=5) i=0; while(color51!=c5) turn1(1); if(i7) break; i+; if(i=8) i=0; while(color51!=c5) turn2(1); if(i7) break; i+; if(i=8) else total+;turn1(1);turn2(1);turn3(1); else total+;turn1(1);turn2(1);turn3(1); else total+;turn1(1);turn2(1);turn3(1); c0=color08; c1=color18; c2=color28

18、; c3=color38; c4=color48; c5=color58; while(color33!=c3) turn3(1); upcolor(); if(color43=c1) turnf(1); else if(color23=c1) turnc1(1); if(color43!=c4) turn5(2); turn1(2); turn5(2); upcolor(); /*对好第一层的十字架end*/ /*对好第一层*/ total=0; k=0; while(total4) break; i+; while(color12!=c1 | color42!=c4 | color50!=

19、c5) i=0; while(color12!=c1 | color42!=c4 | color50!=c5) turn9(2); turnc(1); turn9(2); turn1(1); if(i3) break; i+; if(i100) break; k+; upcolor(); /*对好第一层end*/ c0=color08; c1=color18; c2=color28; c3=color38; c4=color48; total=0; /*开始对第二层 */ while(color25!=c2 | color35!=c3 | color31!=c3 | color45!=c4 |

20、 color41!=c4 | color11!=c1 | color15!=c1 | color21!=c2) /*当看到顶层有第二层的东西就将其放下去*/ for(k=0;k4) break; i+; if(i4) break; i+; if(i4) break; i+; k=0; if(color25!=c2 | color35!=c3) turna(2); turn2(1); turn3(1); k=1; c1=color18; c2=color28; c3=color38; c4=color48; i=0; while(color01!=c2 | color17!=c3) turn2(

21、1); k+; c1=color18; c2=color28; c3=color38; c4=color48; if(i3) break; i+; if(color01=c2 & color17=c3) turna(1); if(k10) break; total+; i=0; while(color13!=color18) turn2(1); if(i4) break; i+; upcolor(); /*对好第二层end*/ /* 对好第三层的四个角*/ c0=color08; c1=color18; c2=color28; c3=color38; c4=color48; j=0; whil

22、e(color00!=c0 | color10!=c1 | color40!=c4) | (color06!=c0 | color30!=c3 | color46!=c4) | (color02!=c0 | color20!=c2 | color16!=c1) /*将近角对好*/ k=0; while(color02!=c0 | color20!=c2 | color16!=c1) i=0; while(color02!=c0 | color20!=c2 | color16!=c1) turn1(1); if(i4) break; i+; if(i4) turnc(1); if(k16) br

23、eak; k+; upcolor(); k1=0; while(color00!=c0 | color10!=c1 | color40!=c4 | color06!=c0 | color30!=c3 | color46!=c4) /*将左角对好*/ k=0; while(color00!=c0 | color10!=c1 | color40!=c4) turnd(1); i=0; while(i15) break; k+; upcolor(); /*还是没有对好*/ if(k15)&(color00!=c0 | color10!=c1 | color40!=c4) turn1(1); turn

24、c(1); turn1(3); turnd(1); else /*将远角对好*/ i=0; while(i4) break; k1+; /*还是没有对好*/ if(k14)&(color06!=c0 | color30!=c3 | color46!=c4 | color00!=c0 | color10!=c1 | color40!=c4) turn1(1); turn2(1); turn3(1); c1=color18; c2=color28; c3=color38; c4=color48; if(j16) break; j+; upcolor(); /* 对好第三层的四个角end*/ /*对

25、好第三层的十字*/ k1=0; while(color01!=c0 | color17!=c1 | color03!=c0 | color37!=c3 | color05!=c0 | color27!=c2 | color07!=c0 | color47!=c4) /*找一个已经对好的边*/ k1=0; while(k14)&(color37!=c3 | color05!=c0) k=0; while(k4)&(color37!=c3 | color05!=c0) i=0; while(i4)&(color37!=c3 | color05!=c0) turn1(1); turn2(1); tu

26、rn3(1); c1=color18; c2=color28; c3=color38; c4=color48; i+; /*没有找到,变换一下角度*/ if(i=4)&(color37!=c3 | color05!=c0) turna(1); turn1(3); turna(1); turn1(1); k+; /*还是没有找到,翻转一下*/ if(k=4)&(color37!=c3 | color05!=c0) turna(1); turn2(3); turnb(1); turn2(1); turna(2); k1+; turn1(1); turn2(1); turn3(1); c1=colo

27、r18; c2=color28; c3=color38; c4=color48; upcolor(); /*对另外三边*/ k=0; while(k16)&(color01!=c0 | color17!=c1 | color03!=c0 | color27!=c2 | color07!=c0 | color47!=c4) i=0; while(i16) break; k1+; /*将底对齐*/ i=0; while(color13!=c1) turn3(1); if(i4) break; i+; upcolor();main() int driver,mode; int bkcolor69;

28、int i,j,b; char a; FILE *fp; driver=DETECT; mode=0; initgraph(&driver,&mode,bgi); setbkcolor(1); for(i=0;i6;i+) for(j=0;j9;j+) bkcolorij=colorij; gotoxy(10,15); printf(Are you continue last game?ntpress n another); if(a=getch()!=n) fp=fopen(box.txt,r); b=getc(fp); for(i=0;i6;i+) for(j=0;j9;j+) colorij=b; b=getc(fp); fclose(fp); cleardevice(); boxinit(); upcolor(); while(a=getch()!=q) switch (a

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论