1、黑白棋算法要求
实现黑白棋,判断是否可以落子,思路上难度不大,细节问题较多,细节很重要,代码实现可以有很多种,第一次实现难免有冗余的代码,冗余部分可以使用函数实现,尽量保证代码的可复用性。另外,输出黑白棋子数量的时候,数字要格式化输出占两位(%2d)。
2、思路
见代码。
3、代码实现
#include <stdio.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <string.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <time.h>
using namespace std;
char mp[10][10];//储存棋局
int f[2][10][10];//标记黑白子可执行合法操作的点
int dx[] = {-1,-1,-1, 1,1,1,0, 0};//八个方向
int dy[] = {-1, 0, 1,-1,0,1,1,-1};
void is(int a, char b, int x, int y)//判断是否可以落子
{
for(int k=0;k<8;k++)
{
int tx = x+dx[k];
int ty = y+dy[k];
int num = 0;
while(tx>=0 && ty>=0
&a