Пример #1
0
void WriteLevel(EDGELIST *tree, int currentLevel) {
	FILE *fp;
	POSITION currentEdge;
	char filename[80];
	EDGE theEdge;

	sprintf(filename, "visualization/m%s/m%s_%d_level_%d_vis.dot", kDBName, kDBName, getOption(), currentLevel);
	fp = fopen(filename, "w+");

	fprintf(fp, "/* Visualization of game tree of %s, variant %d*/\n", kGameName, getOption());
	fprintf(fp, "digraph g {\n");
	fprintf(fp, "\tlabel = \"%s, variant %d\"\n", kGameName, getOption());
	fprintf(fp, "\tlabelloc = \"top\"\n");
	fprintf(fp, "\tranksep = 1\n");
	fprintf(fp, "\tnode [fixedsize = \"true\", width = .75, height = .75]\n");
	//fprintf(fp, "\tmode = \"hier\"\n");
	//fprintf(fp, "\tmodel = \"circuit\"\n");

	/* Turn off edge drawing if gDrawEdges is FALSE */
	if(!gDrawEdges) {
		fprintf(fp, "\tsplines = \"\"\n");
	}

	fprintf(fp, "\tsubgraph cluster_%d {\n", currentLevel);
	fprintf(fp, "\t\tlabel = \"Level %d\"\n", currentLevel);
	fprintf(fp, "\t\tcolor = \"blue\"\n\n");

	/* Draw legend */
	fprintf(fp, "\t\tsubgraph cluster_toc {\n");
	fprintf(fp, "\t\t\trank = \"max\"\n");
	fprintf(fp, "\t\t\tlabel = \"Legend\"\n");
	fprintf(fp, "\t\t\tcolor = \"blue\"\n");

	/* Legend: Meaning of shapes */
	fprintf(fp, "\t\t\tsubgraph cluster_shape {\n");
	fprintf(fp, "\t\t\t\trank = \"same\"\n");
	fprintf(fp, "\t\t\t\tlabel = \"Position Shapes\"\n");
	fprintf(fp, "\t\t\t\tdefault [shape = \"%s\", label = \"Non-draw\"]\n", DEFAULT_SHAPE);
	fprintf(fp, "\t\t\t\tdraw [shape = \"%s\", label = \"Draw\"]\n", DRAW_SHAPE);
	fprintf(fp, "\t\t\t\tfringe [shape = \"%s\", label = \"Fringe\"]\n", FRINGE_SHAPE);
	fprintf(fp, "\t\t\t}\n");

	/* Legend: Meaning of colors */
	fprintf(fp, "\t\t\tsubgraph cluster_color {\n");
	fprintf(fp, "\t\t\t\trank = \"same\"\n");
	fprintf(fp, "\t\t\t\tlabel = \"Position Colors\"\n");
	fprintf(fp, "\t\t\t\twin [label = \"Win\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, WIN_COLOR);
	fprintf(fp, "\t\t\t\ttie [label = \"Tie\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, TIE_COLOR);
	fprintf(fp, "\t\t\t\tlose [label = \"Lose\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, LOSE_COLOR);
	fprintf(fp, "\t\t\t\tdraw2 [label = \"Draw\", shape = \"%s\", style = \"filled\", color = \"%s\"]\n", DEFAULT_SHAPE, DRAW_COLOR);
	fprintf(fp, "\t\t\t}\n");
	fprintf(fp, "\t\t}\n");

	for(currentEdge = 0; currentEdge < (tree->nextEdgeInLevel)[currentLevel]; currentEdge++) {
		theEdge = (tree->edges)[currentLevel][currentEdge];
		WriteNode(fp, theEdge.Parent, currentLevel, tree);
		WriteNode(fp, theEdge.Child, currentLevel, tree);

		fprintf(fp, "\t\t%llu -> %llu [color = \"%s\"]\n", theEdge.Parent, theEdge.Child, MoveColor(theEdge));
	}

	if(gRemotenessOrder) {
		WriteRanks(fp, tree);
		PrepareRankList(tree);
	}

	fprintf(fp, "\t}\n");
	fprintf(fp, "}\n");
	fclose(fp);
	UnMarkAllAsVisited();
}
Пример #2
0
void playtoplay()/*人人对战*/
{
int x,y,t=1,i,j,cc=0;
while(1)/*换棋手走棋*/
{
x=120,y=80;/*每次棋子一开始出来的坐标,x为行坐标,y为列坐标*/
while(1) /*具体一个棋手走棋的过程*/
{
PrintScore(1);/*输出棋手1的成绩*/
PrintScore(2);/*输出棋手2的成绩*/
SetPlayColor(t);/*t变量是用来判断棋手所执棋子的颜色*/
fillellipse(x,y,15,15);
key=bioskey(0);/*接收按键*/
if(key==ESC)/*跳出游戏*/
break;
else
if(key==ENTER)/*如果按键确定就可以跳出循环*/
{
if(y!=80&&a[(x-120)/40][(y-120)/40]!=1
&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置没有棋子*/
{
if(t%2==1)/*如果是棋手1移动*/
a[(x-120)/40][(y-120)/40]=1;
else/*否则棋手2移动*/
a[(x-120)/40][(y-120)/40]=2;
if(!QpChange(x,y,t))/*落子后判断棋盘的变化*/
{
a[(x-120)/40][(y-120)/40]=0;/*恢复空格状态*/
cc++;/*开始统计尝试次数*/
if(cc>=64-score1-score2) /*如果尝试超过空格数则停步*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
break;
}
else
continue;/*如果按键无效*/
}
DoScore();/*分数的改变*/
break;/*棋盘变化了,则轮对方走棋*/
}
else/*已经有棋子就继续按键*/
continue;
}
else /*四个方向按键的判断*/
if(key==LEFT&&x>120)/*左方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x-=40;
fillellipse(x,y,15,15);
}
else
if(key==RIGHT&&x<400&&y>80)/*右方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x+=40;
fillellipse(x,y,15,15);
}
else
if(key==UP&&y>120)/*上方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y-=40;
fillellipse(x,y,15,15);
}
else
if(key==DOWN&&y<400)/*下方向键*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y+=40;
fillellipse(x,y,15,15);
}
}
if(key==ESC)/*结束游戏*/
break;
if((score1+score2)==64||score1==0||score2==0)/*格子已经占满或一方棋子为0判断胜负*/
{
playWin();/*输出最后结果*/
break;
}
t=t%2+1; /*一方走后,改变棋子颜色即轮对方走*/
cc=0; /*计数值恢复为0*/
} /*endwhile*/
}