#include "stdafx.h"
#pragma warning(disable:4996)
int ChessBox[8][8] = {0};//0为空,1为黑,2为白
int MrcWhile(int x,int y);
int MrcBlack(int x,int y);
void L(void);
int main()//少判断是否无可走步数
{
char order[5] = { 0 };
ChessBox[3][3] = ChessBox[4][4] = 1;
ChessBox[3][4] = ChessBox[4][3] = 2;
for (int step = 0, Merber=1;; )
{
scanf("%s", &order);
if (order[0] == 'L')
{
L();
printf("%s", order);
}
if (order[0] == 'M' && order[1] == 'r' && order[2] == 'c')
{
int x, y;
if (step % 2 == 0)
{
scanf("%d%d", &x, &y);
MrcBlack(x, y);
}
else
{
scanf("%d%d", &x, &y);
MrcWhile(x, y);
}
printf("%s", order);
step++;
}
if (order[0] == 'Q')
{
printf("%s", order);
L();
break;
}
}
return 0;
}
void L(void) //打印
{
int x = 0, y = 0;
for (;x<=7 ;x++){
printf("\n");
for (y=0;y<=7 ;y++) {
printf("%d ", ChessBox[x][y]);
}
}
}
int MrcBlack(int x,int y)
{
for (;x<=7;x++){
if (ChessBox[x][y]!=0){
if (ChessBox[x + 1][y] == 1 && ChessBox[x][y + 1] == 1 &&
ChessBox[x - 1][y] == 1 && ChessBox[x][y - 1] == 1 &&
ChessBox[x + 1][y + 1] == 1 && ChessBox[x - 1][y - 1] == 1
&& ChessBox[x + 1][y - 1] == 1 && ChessBox[x - 1][y + 1] == 1){
if (ChessBox[x + 1][y] == 1) {//右
for (int _x = x, _y = y; _x <= 7; _x++) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; --_x) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x - 1][y] == 1) {//左
for (int _x = x, _y = y; _x >= 0; _x--) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; ++_x) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x][y + 1] == 1) {//上
for (int _x = x, _y = y; _y <= 7; _y++) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; --_y) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x + 1][y] == 1) {//x\下
for (int _x = x, _y = y; _y >= 0; _y--) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; ++y) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x + 1][y] == 1) {//右上
for (int _x = x, _y = y; _x <= 7,_y <= 7;_y++,_x++) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; --_x,--_y) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x + 1][y] == 1) {//左下
for (int _x = x, _y = y; _x >= 0, _y >= 0; _y--, _x--) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; ++_x) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x + 1][y] == 1) {//右下
for (int _x = x, _y = y; _x <= 7, _y >= 0; _y--, _x++) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; --_x,++_y) {
ChessBox[_x][_y] = 2;
}
}
}
}
if (ChessBox[x + 1][y] == 1) {
for (int _x = x, _y = y; _x >= 0, _y <= 7; _y++, _x--) {
if (ChessBox[_x][_y] == 2) {
ChessBox[x][y] = 2;
for (; ChessBox[_x][_y] != 2; ++_x,--_y) {//改变
ChessBox[_x][_y] = 2;
}
}
}
}
}
}
}
return 0;
}
int MrcWhile(int x, int y)
{
for (; x <= 7; x++) {
if (ChessBox[x][y] != 0) {
if (ChessBox[x + 1][y] == 2 && ChessBox[x][y + 1] == 2 &&
ChessBox[x - 1][y] == 2 && ChessBox[x][y - 1] == 2 &&
ChessBox[x + 1][y + 1] == 2 && ChessBox[x - 1][y - 1] == 2
&& ChessBox[x + 1][y - 1] == 2 && ChessBox[x - 1][y + 1] == 2) {
if (ChessBox[x + 1][y] == 2) {
for (int _x = x, _y = y; _x <= 7; _x++) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; --_x) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x - 1][y] == 2) {
for (int _x = x, _y = y; _x >= 0; _x--) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; ++_x) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x][y + 1] == 2) {//上
for (int _x = x, _y = y; _y <= 7; _y++) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; --_y) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x + 1][y] == 2) {//x\下
for (int _x = x, _y = y; _y >= 0; _y--) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; ++y) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x + 1][y] == 2) {
for (int _x = x, _y = y; _x <= 7, _y <= 7; _y++, _x++) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; --_x, --_y) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x + 1][y] == 2) {
for (int _x = x, _y = y; _x >= 0, _y >= 0; _y--, _x--) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; ++_x) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x + 1][y] == 2) {
for (int _x = x, _y = y; _x <= 7, _y >= 0; _y--, _x++) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; --_x, ++_y) {
ChessBox[_x][_y] = 1;
}
}
}
}
if (ChessBox[x + 1][y] == 2) {
for (int _x = x, _y = y; _x >= 0, _y <= 7; _y++, _x--) {
if (ChessBox[_x][_y] == 1) {
ChessBox[x][y] = 1;
for (; ChessBox[_x][_y] != 1; ++_x, --_y) {
ChessBox[_x][_y] = 1;
}
}
}
}
}
}
}
return 0;
}
/*是否为空位?->是否有对方棋子相邻?->是否超对方棋子方向有己方棋子?->将中间对方子变为己方棋子*/
总体的思路是最后一行注释,另写完才发现少了个检测代码的功能,我的想法是在每次输入指令前对所有的格子进行判断
就酱``
ps:其实本来有好多注释的,但因为一些原因都被删了,补又太麻烦,各位稍微忍忍,下次不敢了~