资源简介
国科大2015级本科生c语言课程大作业。
在osx平台下使用c语言实现,在windows平台下稍作了一些修改也可使用(输出格式优化)。
采用评分机制,哈希表缓存,启发式搜索+算杀。
在5秒内可搜索12层以上(层数可自行调节)。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#define rep(ilr) for (int i=l;i<=r;++i)
#define per(irl) for (int i=r;i>=l;--i)
#define SIZE 15
void InitBoard();// Initialize Background
void DrawBoard();// Print present board
void InitTHash();
void Init();// Begin
void Go();
int main(){
InitBoard();
InitTHash();
Init();
Go();
}
#define NONE 0
#define BLACK 1
#define WHITE 2
typedef char stone_t; // 0 for none; 1 for black ; 2 for white; -1 for boundaries.
typedef unsigned char ubyte; // to storage 1-byte number (0-255)
typedef unsigned long long UI;
stone_t H_KindC_Kind; // 1 for human black ; 2 for human white.
stone_t N_board[SIZE+2][SIZE+2];// Present board
wchar_t BG_Board[SIZE+1][SIZE+1];// Background
void InitBoard(){
rep(i0SIZE+1) rep(j0SIZE+1) N_board[i][j]=-1;
rep(i1SIZE) rep(j1SIZE) N_board[i][j]=0; // N_board
//-----------
rep(i1SIZE) BG_Board[1][i]=(i==1)?L‘┏‘:((i==SIZE)?L‘┓‘:L‘┯‘);
rep(i2SIZE-1) rep(j1SIZE)
BG_Board[i][j]=(j==1)?L‘┠‘:((j==SIZE)?L‘┨‘:L‘┼‘);
rep(i1SIZE) BG_Board[SIZE][i]=(i==1)?L‘┗‘:((i==SIZE)?L‘┛‘:L‘┷‘);// Background
}
void DrawBoard(){
setlocale(LC_ALL““);
rep(i1SIZE){
printf(“%2d “SIZE-i+1); // FAN
rep(j1SIZE){
if (!N_board[i][j]) printf(“%lc%lc“BG_Board[i][j]j==SIZE?L‘ ‘:L‘─‘);
else printf(“%lc%lc“N_board[i][j]==1?L‘●‘:L‘○‘j==SIZE?L‘ ‘:L‘─‘);
}
printf(“\n“);
}
printf(“ “);
rep(i1SIZE) printf(“%c “‘A‘+i-1);
printf(“\n“);
}
void Init(){
for (char t=‘\0‘;t!=‘B‘&&t!=‘W‘;){
printf(“Black or White? (B/W) \n“);
scanf(“%c“&t);
t=toupper(t);
if (t==‘B‘) H_Kind=1C_Kind=2;
if (t==‘W‘) H_Kind=2C_Kind=1;
}
}
const int Dx[]={01110-1-1-1}
Dy[]={110-1-1-101};//Direction
#define TYPELONG ((1<<19)-1) //3^7+3^6+3^5 =3159. TYPELONG 32767 DANGEROUS !!!
#define FIVE 1
#define AFUR 2
#define GFUR 3
#define ATRE 4
#define GTRE 5
#define ATWO 6
#define GTWO 7
#define NONE 0
#define SIX 8
char S_hash[TYPELONG+1];
const UI base=37;
UI Bpow[11]={1};
UI randomi[3][SIZE+1][SIZE+1];// zobrist
stone_t Stype[][10]={ // Types . Caution: Some situations have symmetrical types.
{511111} // FIVE 0
{6011110} // AFUR 1
{70011112}{72011112}{511011}{510111} //GFUR 2-5 //2111101
{72011100}{70011100}{6010110} //ATRE 6-8
{6001112}{6010112}{6011012}{510011}{510101}{72011102} //GTRE 9-14
{6001100}{6201100}{70010100}{72010100}{6010010} //ATWO 15-19
{6211000}{6210100}{6210010}{510001}{72010102} //GTWO 20-24
{6111111}// SIX 25
};
void cBpow(){
rep(i110) Bpow[i]=(Bpow[i-1]*base)&TYPELONG;
}
void p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 17864 2017-01-06 16:57 cnt5 for mac.c
文件 17821 2017-01-12 11:54 cnt5 for windows.c
目录 0 2017-01-19 16:23 __MACOSX\
文件 522 2017-01-12 11:54 __MACOSX\._cnt5 for windows.c
- 上一篇:网络编程聊天室--操作演示文档
- 下一篇:基于vc6.0串口调试助手源码
评论
共有 条评论