{
if( Opreat[0]!= -32 ) continue; Opreat[1]= getch( ); }
if( Opreat[0]== -32&& Opreat[1]== 72|| Opreat[0]== 'w'|| Opreat[0]== 'W' )
{
if( Currect( Move_X- 1, Move_Y ) ) {
Move_X-= 1; } }
else if( Opreat[0]== -32&& Opreat[1]== 80|| Opreat[0]== 's'|| Opreat[0]== 'S' ) {
if( Currect( Move_X+ 1, Move_Y ) ) {
Move_X+= 1; } }
else if( Opreat[0]== -32&& Opreat[1]== 75|| Opreat[0]== 'a'|| Opreat[0]== 'A' ) {
if( Currect( Move_X, Move_Y- 1 ) )
{
Move_Y-= 1; } }
else if( Opreat[0]== -32&& Opreat[1]== 77|| Opreat[0]== 'd'|| Opreat[0]== 'D' ) {
if( Currect( Move_X, Move_Y+ 1 ) ) {
Move_Y+= 1; } }
ChangeCoordinates( Move_X, Move_Y, &Temp_X, &Temp_Y ); Gotoxy( Temp_X, Temp_Y ); } } }
bool Win( int Ply, int X, int Y ) {
先找上下的是否存在一条直线连成ChessBoard.MINBOX个 int Count= 1, Flag= 0;
for( int i= X- 1, k= X+ 1; Legal( i )|| Legal( k ); i--, k++ ) {
int LastCount= Count;
if( Legal( i )&& ChessBoard.Status[i][Y]== Ply )
{
Count++; }
if( Legal( k )&& ChessBoard.Status[k][Y]== Ply ) {
Count++; }
if( LastCount== Count ) break;
if( Count== ChessBoard.MINBOX ) {
Flag= 1; return true; } }
左右查找是否满足条件 if( !Flag ) {
Count= 1;
for( int i= Y- 1, k= Y+ 1; Legal( i )|| Legal( k ); i--, k++ {
int LastCount= Count;
if( Legal( i )&& ChessBoard.Status[X][i]== Ply ) {
Count++;
)
}
if( Legal( k )&& ChessBoard.Status[X][k]== Ply ) {
Count++; }
if( LastCount== Count ) break;
if( Count== ChessBoard.MINBOX ) {
Flag= 1; return true; } } }
搜索45度角是否为满足ChessBoard.MINBOX 以X正轴为参考轴 if( !Flag ) {
Count= 1;
for( int i1= X- 1, j1= Y+ 1, i2= X+ 1, j2= Y- 1 ; Legal( i1 )&& Legal( j1 )|| Legal( i2 )&& Legal( j2 ) ; i1--, j1++, i2++, j2-- ) {
int LastCount= Count;
if( Legal( i1 )&& Legal( j1 )&& ChessBoard.Status[i1][j1]== Ply ) {
Count++;
相关推荐: