我们玩过的连连看游戏,通过选定两个图形相同的元素,判定其是否可在三次转弯内连接起来,若能,则消去,若不能,则不可消去,
直至最后全部消除。
本算法中不包括关于死锁状态判定。
// 连连看.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <vector>
#include <queue>
using namespace std;
struct Point
{
int x;
int y;
};
int pushonelinespot(Point a,Point b,int c[6][6], queue<Point> &g) //将a点可直线到达的点压入队列g中
{
int i;
Point temp;
for(i=1;;i++) //向下检测
{ if((a.x+i)<=5&&c[a.x+i][a.y]==0)
{
temp.x=a.x+i;temp.y=a.y;
g.push(temp);}
else if(c[a.x+i][a.y]!=0&&(a.x+i)<=5)
{if((a.x+i)==b.x&&a.y==b.y) return 1;
else break;}
else break;
}
for(i=-1;;i--) //向上检测
{ if(c[a.x+i][a.y]==0&&(a.x+i)>=0)
{ temp.x=a.x+i;temp.y=a.y;
g.push(tem