📄 chlist.cpp
字号:
#include "stdafx.h"
#include "chList.h"
#include <iostream>
using namespace std;
extern char position[19][19];
chList::chList()
{
int i,j;
int count=0;
for(j=0; j<=18; j++)
{
for(i=0; i<=13; i++)
{
strInfo[count][0] = i;
strInfo[count][1] = j;
strInfo[count][2] = 0;
count++;
}
}
for(j=0; j<=18; j++)
{
for(i=0; i<=13; i++)
{
strInfo[count][0] = j;
strInfo[count][1] = i;
strInfo[count][2] = 2;
count++;
}
}
for(i=13; i>=0; i--)
{
for(j=0; j<=13-i; j++)
{
strInfo[count][0] = i+j;
strInfo[count][1] = j;
strInfo[count][2] = 1;
count++;
}
}
for(i=1; i<=13; i++)
{
for(j=0; j<=13-i; j++)
{
strInfo[count][0] = j;
strInfo[count][1] = i+j;
strInfo[count][2] = 1;
count++;
}
}
for(i=5; i<=18; i++)
{
for(j=0; j<=i-5; j++)
{
strInfo[count][0] = j;
strInfo[count][1] = i-j;
strInfo[count][2] = 3;
count++;
}
}
for(i=1; i<=13; i++)
{
for(j=0; j<=13-i; j++)
{
strInfo[count][0] = i+j;
strInfo[count][1] = 18-j;
strInfo[count][2] = 3;
count++;
}
}
/*for(int p=0; p < 924; p++)
{
cout << p<<':'<<strInfo[p][0] << ' ' << strInfo[p][1] << ' '<< strInfo[p][2] <<" ";
if(p%5 == 4)
cout <<endl;
}*/
}
void chList::GetStr(int n,int s[])
{
int x,y,forw;
int i;
const int dx[4] = {1,1,0,1};
const int dy[4] = {0,1,1,-1};
x = strInfo[n][0];
y = strInfo[n][1];
forw = strInfo[n][2];
for(i=0; i<6; i++)
s[i] = position[x + i*dx[forw]][y + i*dy[forw]];
}
void chList::GetCoor(int n,int s[][2])
{
int x,y,forw;
int i;
const int dx[4] = {1,1,0,1};
const int dy[4] = {0,1,1,-1};
x = strInfo[n][0];
y = strInfo[n][1];
forw = strInfo[n][2];
for(i=0; i<6; i++)
{
s[i][0] = x + i*dx[forw];
s[i][1] = y + i*dy[forw];
}
}
void chList::StrOfPoint(int x,int y,int s[])
{
int i,count=0;
for(i=0; i<=5; i++)
{
if(x-i>=0 && x+5-i<19)
s[count] = 14*y + x-i;
else
s[count] = -1;
count++;
}
for(i=0; i<=5; i++)
{
if(y-i>=0 && y+5-i<19)
s[count] = 14*19 + 14*x + y-i;
else
s[count] = -1;
count++;
}
for(i=0; i<=5; i++)
{
if(x-i>=0 && y-i>=0 && x+5-i<19 && y+5-i<19)
{
int hl;
if( x-y >=0 )
{
hl = y-x + 13;
s[count] = 14*19*2 + (1+hl)*hl/2 + y-i;
}
else
{
hl = y-x - 1;
s[count] = 14*19*2 + (1+14)*14/2 + (13+14-hl)*hl/2 + x-i;
}
}
else
s[count] = -1;
count++;
}
for(i=0; i<=5; i++)
{
if(x-i>=0 && y+i <19 && x+5-i<19 && y-(5-i)>=0)
{
int hl;
if( x+y <= 18)
{
hl = x+y-5;
s[count] = 14*19*2 + (1+14)*14/2 + (13+1)*13/2 + (1+hl)*hl/2 + x-i;
}
else
{
hl = x+y - 19;
s[count] = 14*19*2 + (1+14)*14/2 + (13+1)*13/2 + (1+14)*14/2 + (13+14-hl)*hl/2 + 18-(y+i);
}
}
else
s[count] = -1;
count++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -