📄 product.cpp
字号:
// Product.cpp: implementation of the CProduct class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "chess.h"
#include "Product.h"
#include "chessdlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
int i=0,j,k;
CString ss[50];
CChessDlg* www;
CClientDC *dc;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CProduct::CProduct(CDialog* w)
{
www=(CChessDlg*)w;
dc=new CClientDC(www);
int x;
for (x=0;x<10;x++)
{
memset(board,0,90);
for (int z=0;z<9;z++) board[x][z]=1;
for (z=0;z<9;z++) {BitCreate(board,chex[x][z]);BitCreate(board,paox[x][z]);}
}
for (x=0;x<9;x++)
{
memset(board,0,90);
for (int z=0;z<10;z++) board[z][x]=1;
for (z=0;z<10;z++) {BitCreate(board,chey[z][x]);BitCreate(board,paoy[z][x]);}
}
for (x=0;x<10;x++)
for (int y=0;y<9;y++)
{
memset(board,0,90);
if (x-1>=0) board[x-1][y]=1;
if (x+1<=9) board[x+1][y]=1;
if (y-1>=0) board[x][y-1]=1;
if (y+1<=8) board[x][y+1]=1;
BitCreate(board,ma[x][y]);
BitCreate(board,bin[x][y]);
BitCreate(board,jiang[x][y]);
memset(board,0,90);
if (x-1>=0&&y-1>=0) board[x-1][y-1]=1;
if (x-1>=0&&y+1<=8) board[x-1][y+1]=1;
if (x+1<=9&&y-1>=0) board[x+1][y-1]=1;
if (x+1<=9&&y+1<=8) board[x+1][y+1]=1;
BitCreate(board,xiang[x][y]);
BitCreate(board,shi[x][y]);
memset(board,0,90);
if (x-1>=0&&y-2>=0) board[x-1][y-2]=1;
if (x-1>=0&&y+2<=8) board[x-1][y+2]=1;
if (x+1<=9&&y-2>=0) board[x+1][y-2]=1;
if (x+1<=9&&y+2<=8) board[x+1][y+2]=1;
if (x-2>=0&&y-1>=0) board[x-2][y-1]=1;
if (x-2>=0&&y+1<=8) board[x-2][y+1]=1;
if (x+2<=9&&y-1>=0) board[x+2][y-1]=1;
if (x+2<=9&&y+1<=8) board[x+2][y+1]=1;
BitCreate(board,zouma[x][y]);
memset(board,0,90);
if (x-2>=0&&y-2>=0) board[x-2][y-2]=1;
if (x-2>=0&&y+2<=8) board[x-2][y+2]=1;
if (x+2<=9&&y-2>=0) board[x+2][y-2]=1;
if (x+2<=9&&y+2<=8) board[x+2][y+2]=1;
BitCreate(board,zouxiang[x][y]);
memset(board,0,90);
board[x][y]=1;
BitCreate(board,bitData[x][y]);
}
memset(board,0,90);
for (x=0;x<5;x++)
for (int y=0;y<9;y++)
board[x][y]=1;
BitCreate(board,zu[0]);
memset(board,0,90);
for (x=5;x<10;x++)
for (int y=0;y<9;y++)
board[x][y]=1;
BitCreate(board,zu[1]);
memset(board,0,90);
for (x=0;x<3;x++)
for (int y=3;y<6;y++)
board[x][y]=1;
BitCreate(board,shuai[0]);
memset(board,0,90);
for (x=7;x<10;x++)
for (int y=3;y<6;y++)
board[x][y]=1;
BitCreate(board,shuai[1]);
}
void CProduct::Print(const char s[])
{
ss[i].Format ("%s ",s);
if (i>25)
{
for (int x=0;x<i;x++) ss[x]=ss[x+1];
i=25;
}
i++;
for (int x=0;x<i;x++) dc->TextOut(48*10,20*x,ss[x]);
}
void CProduct::Print(const CString s)
{
ss[i].Format ("%s ",s);
if (i>25)
{
for (int x=0;x<i;x++) ss[x]=ss[x+1];
i=25;
}
i++;
for (int x=0;x<i;x++) dc->TextOut(48*10,20*x,ss[x]);
}
void CProduct::Draw()
{
for (int x=0;x<i;x++) dc->TextOut(48*10,20*x,ss[x]);
}
void CProduct::Print(const __int32 s)
{
ss[i].Format ("%d ",s);
if (i>25)
{
for (int x=0;x<i;x++) ss[x]=ss[x+1];
i=25;
}
i++;
for (int x=0;x<i;x++) dc->TextOut(48*10,20*x,ss[x]);
}
void CProduct::Pt(BYTE p[][9],__int32 b[][3],BYTE bitboard[][10][9],CPoint& from,CPoint& to,CPoint move[][9][20],BYTE top[][9])
{
int x=from.x;int y=from.y;
int xx=to.x;int yy=to.y;
if ((b[1][0]&chex[x][y][0])||(b[1][1]&chex[x][y][1])||(b[1][2]&chex[x][y][2]))
for (int i=0;i<9;i++) if (p[x][i]==1) www->m_ppm->Extend(CPoint(x,j),move[x][j],top[x][j],p);
if ((b[2][0]&ma[x][y])||(b[2][1]&ma[x][y])||(b[2][2]&ma[x][y])){
if (x-1>=0&&p[x-1][y]==2) www->m_ppm->Extend (CPoint(x-1,y),move[x-1][y],top[x-1][y],p);
if (x+1<=9&&p[x+1][y]==2) www->m_ppm->Extend (CPoint(x+1,y),move[x+1][y],top[x+1][y],p);
if (y-1>=0&&p[x][y-1]==2) www->m_ppm->Extend (CPoint(x,y-1),move[x][y-1],top[x][y-1],p);
if (y+1<=8&&p[x][y+1]==2) www->m_ppm->Extend (CPoint(x,y+1),move[x][y+1],top[x][y+1],p);
}
if ((b[2][0]&zouma[x][y])||(b[2][1]&zouma[x][y])||(b[2][2]&zouma[x][y])){
if (x-1>=0&&y-2>=0&&p[x-1][y-2]==2) www->m_ppm->Extend (CPoint(x-1,y),move[x-1][y],top[x-1][y],p);
if (x+1>=0&&p[x+1][y]==2) www->m_ppm->Extend (CPoint(x+1,y),move[x+1][y],top[x+1][y],p);
if (y-1>=0&&p[x][y-1]==2) www->m_ppm->Extend (CPoint(x,y-1),move[x][y-1],top[x][y-1],p);
if (y+1>=0&&p[x][y+1]==2) www->m_ppm->Extend (CPoint(x,y+1),move[x][y+1],top[x][y+1],p);
}
}
CProduct::~CProduct()
{
}
void CProduct::BitCreate(BYTE C[][9],__int32 b[])
{
int j,k;
memset(b,0,3*4);
for (j=0;j<3;j++)
for (k=0;k<10;k++)
if (C[k][j]==1) b[0]|=(1<<(30-j*10-k));
for (j=3;j<6;j++)
for (k=0;k<10;k++)
if (C[k][j]==1) b[1]|=(1<<(30-(j-3)*10-k));
for (j=6;j<9;j++)
for (k=0;k<10;k++)
if (C[k][j]==1) b[2]|=(1<<(30-(j-6)*10-k));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -