智能五子棋.doc_第1页
智能五子棋.doc_第2页
智能五子棋.doc_第3页
智能五子棋.doc_第4页
智能五子棋.doc_第5页
已阅读5页,还剩51页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

types.h#ifndef _H_TYPE_H#define _H_TYPE_H#include #include #include #include #include /#define MULTI_THREAD_ENV#define PR_DEBUG#define HASHPROBEtypedef unsigned int u32;typedef unsigned char u8;typedef unsigned short u16;typedef unsigned long long u64;typedef long long int64;typedef int int32;struct POINT1 int x; int y; int color; POINT1(); POINT1(int ix,int iy,int icolor) x=ix; y=iy; color=icolor; void operator=(const POINT1& pt) x = pt.x; y = pt.y; color = pt.color; ;const int BOARD_ROW=15;const int BOARD_COL=15;#define COLR_BLK (0x0)#define COLR_WHT (0x1)#define ASSERT1(MSG) /assert(MSG)#define PAIR(X,Y) ( (X)4)+(Y) )#define HASH_NOFIND (0x7fffffffL)#define MK_PT(X,Y) ( (X)4)-(X)+(Y) )#endif_MULTICBS_H#ifndef _MULTICBS_H#define _MULTICBS_H#includetypes.h#includechessboard.h#includeconst int MAXTHREAD=8;const int THREAD_C=1;struct CutStatis volatile long cutoff1515;public: CutStatis()clear(); void clear() memset(void*)cutoff,0,sizeof(cutoff); void Increment(int x,int y,long num) #ifdef MULTI_THREAD_ENV /increase cutoffxy #else cutoffxy+=num; #endif ;struct MULTI_CB_STRCUT POINT1 TreeNode225; long iter; long ptNum; int clk; #ifdef MULTI_THREAD_ENV /two kinds of locks and pid #endif POINT1 thread_best_plotMAXTHREAD; int thread_best_scoreMAXTHREAD; CutStatis statis;class MultiBoardpublic: int Threads; chessboard objectMAXTHREAD; int board1515; hashtable* table; MULTI_CB_STRCUT multi_th_info; int tableprobe; int totalvis ;public: MultiBoard(); MultiBoard(); void getphase(FILE* fd); void ComStep(); void ComStep(int *x,int *y); void ManStep(int x,int y); int checkend(); bool undo(int *x,int *y); void reset(); void printtable();private: void init_multi_thread_env(); int HisHeuristic(POINT1* best_choice); void BegThreadsWork(bool first_time); void BegThreadsWork(bool first_time,vector& allowpt); void WaitThreadsFin(); int select_best_nodes(POINT1* pts,int pts_sz);#endifMY_HASHTABLE_H#ifndef MY_HASHTABLE_H#define MY_HASHTABLE_H#include types.hstruct HASHtagpublic: u64 identify; int value; short vflag; short depth; void set_identify(u64 key)identify=key; void set_depth(int i_depth)depth=i_depth; u64 get_identify()return identify; int get_value()return value; int get_flag()return vflag; int get_depth()return depth; void clear()vflag=0; HASHtag():vflag(0); bool trylock() #ifdef MULTI_THREAD_ENV /return 0 = InterlockedCompareExchange(&vflag,-1,0); #else return (vflag=0); #endif ; void set_flag(long i_flag) #ifdef MULTI_THREAD_ENV /InterlockedExchange(&vflag,i_flag); #else vflag = i_flag; #endif ; void set_value(int i_value) #ifdef MULTI_THREAD_ENV /InterlockedExchange(&value,&i_value); #else value=i_value; #endif ;const u32 HASHSIZE_C=4999999;const int hashfEXACT=1;const int hashfALPHA=2;const int hashfBETA=4;class hashtablepublic: HASHtag tableHASHSIZE_C; int total_num; int success_num;public: void hash(int value,int flag,u64 ikey,int depth); HASHtag* search(u64 i_key,int depth); u64 makekey(u64 i_key); void clear(); void display(); hashtable():total_num(0),success_num(0);#endifCONSULT_H_#ifndef CONSULT_H_#define CONSULT_H_const int V_V = 0;const int V_0 = 1;const int V_1 = 5;const int V_2 = 25;const int V_3 = 125;const int V_4 = 625;/*const int V_2 = 40;const int V_3 = 120;const int V_4 = 320;*/*const int V_2 = 50;const int V_3 = 250;const int V_4 = 900;*/const int V_5 = 9900;const int V_0STEP = 160000;const int V_1STEP = 80000;const int V_2STEP = 40000;const int V_2D5STEP = 30000;const int V_3STEP = 20000;const int V_4STEP = 10000;const int V_NSTEP = 500;const static int consult15 = V_0,V_1,V_1,V_2,V_1,V_2,V_2,V_3,V_1,V_2,V_2,V_3,V_2,V_3,V_3,V_4,V_1,V_2,V_2,V_3,V_2,V_3,V_3,V_4,V_2,V_3,V_3,V_4,V_3,V_4,V_4,V_5,;const static unsigned char bdy_lft4225 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29, 44, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29, 44, 59, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29, 44, 59, 74, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 44, 59, 74, 89, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 59, 74, 89,104, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 74, 89,104,119, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 89,104,119,134, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,104,119,134,149, 94, 95, 96, 97, 98, 99,100,101,102,103,104,119,134,149,164,109,110,111,112,113,114,115,116,117,118,119,134,149,164,179,124,125,126,127,128,129,130,131,132,133,134,149,164,179,194,139,140,141,142,143,144,145,146,147,148,149,164,179,194,209,154,155,156,157,158,159,160,161,162,163,164,179,194,209,224, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 30, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 45, 30, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 60, 45, 30, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 75, 60, 45, 30, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 90, 75, 60, 45, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,105, 90, 75, 60, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,120,105, 90, 75, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,135,120,105, 90, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,150,135,120,105, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,165,150,135,120,105,106,107,108,109,110,111,112,113,114,115,180,165,150,135,120,121,122,123,124,125,126,127,128,129,130,195,180,165,150,135,136,137,138,139,140,141,142,143,144,145,210,195,180,165,150,151,152,153,154,155,156,157,158,159,160, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 15, 15, 15, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 30, 30, 30, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 45, 45, 45, 45, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 60, 60, 60, 60, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 75, 75, 75, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 90, 90, 90, 90, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,105,105,105,105,105,106,107,108,109,110,111,112,113,114,115,120,120,120,120,120,121,122,123,124,125,126,127,128,129,130,135,135,135,135,135,136,137,138,139,140,141,142,143,144,145,150,150,150,150,150,151,152,153,154,155,156,157,158,159,160,165,165,165,165,165,166,167,168,169,170,171,172,173,174,175,180,180,180,180,180,181,182,183,184,185,186,187,188,189,190,195,195,195,195,195,196,197,198,199,200,201,202,203,204,205,210,210,210,210,210,211,212,213,214,215,216,217,218,219,220,;const static unsigned char bdy_rht4225 = 0, 15, 30, 45, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 15, 30, 45, 60, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 30, 45, 60, 75, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100, 45, 60, 75, 90,105,106,107,108,109,110,111,112,113,114,115, 60, 75, 90,105,120,121,122,123,124,125,126,127,128,129,130, 75, 90,105,120,135,136,137,138,139,140,141,142,143,144,145, 90,105,120,135,150,151,152,153,154,155,156,157,158,159,160,105,120,135,150,165,166,167,168,169,170,171,172,173,174,175,120,135,150,165,180,181,182,183,184,185,186,187,188,189,190,135,150,165,180,195,196,197,198,199,200,201,202,203,204,205,150,165,180,195,210,211,212,213,214,215,216,217,218,219,220,165,180,195,210,211,212,213,214,215,216,217,218,219,220,221,180,195,210,211,212,213,214,215,216,217,218,219,220,221,222,195,210,211,212,213,214,215,216,217,218,219,220,221,222,223,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 59, 44, 29, 14, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 74, 59, 44, 29, 94, 95, 96, 97, 98, 99,100,101,102,103,104, 89, 74, 59, 44,109,110,111,112,113,114,115,116,117,118,119,104, 89, 74, 59,124,125,126,127,128,129,130,131,132,133,134,119,104, 89, 74,139,140,141,142,143,144,145,146,147,148,149,134,119,104, 89,154,155,156,157,158,159,160,161,162,163,164,149,134,119,104,169,170,171,172,173,174,175,176,177,178,179,164,149,134,119,184,185,186,187,188,189,190,191,192,193,194,179,164,149,134,199,200,201,202,203,204,205,206,207,208,209,194,179,164,149,214,215,216,217,218,219,220,221,222,223,224,209,194,179,164,213,214,215,216,217,218,219,220,221,222,223,224,209,194,179,212,213,214,215,216,217,218,219,220,221,222,223,224,209,194,211,212,213,214,215,216,217,218,219,220,221,222,223,224,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14, 14, 14, 14, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 29, 29, 29, 29, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 44, 44, 44, 44, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 59, 59, 59, 59, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 74, 74, 74, 74, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 89, 89, 89, 89, 94, 95, 96, 97, 98, 99,100,101,102,103,104,104,104,104,104,109,110,111,112,113,114,115,116,117,118,119,119,119,119,119,124,125,126,127,128,129,130,131,132,133,134,134,134,134,134,139,140,141,142,143,144,145,146,147,148,149,149,149,149,149,154,155,156,157,158,159,160,161,162,163,164,164,164,164,164,169,170,171,172,173,174,175,176,177,178,179,179,179,179,179,184,185,186,187,188,189,190,191,192,193,194,194,194,194,194,199,200,201,202,203,204,205,206,207,208,209,209,209,209,209,214,215,216,217,218,219,220,221,222,223,224,224,224,224,224,;struct ChessLand int pos5; int num;const static ChessLand nxt_land_pos15 = 0,1,2,3,4,5,1,2,3,4,0,4,0,2,3,4,0,4,2,3,4,0,0,3,0,1,3,4,0,4,1,3,4,0,0,3,0,3,4,0,0,3,3,4,0,0,0,2,0,1,2,4,0,4,1,2,4,0,0,3,0,2,4,0,0,3,2,4,0,0,0,2,0,1,4,0,0,3,1,4,0,0,0,2,0,4,0,0,0,2,4,0,0,0,0,1,0,1,2,3,0,4,1,2,3,0,0,3,0,2,3,0,0,3,2,3,0,0,0,2,0,1,3,0,0,3,1,3,0,0,0,2,0,3,0,0,0,2,3,0,0,0,0,1,0,1,2,0,0,3,1,2,0,0,0,2,0,2,0,0,0,2,2,0,0,0,0,1,0,1,0,0,0,2,1,0,0,0,0,1,0,0,0,0,0,1,0,1,2,3,4,5,;#endifCHESSBOARD_H_#ifndef CHESSBOARD_H_#define CHESSBOARD_H_#include bitrate1.h#include BoardHash.h#include hashTable.h#include Eval.h#include #include types.husing namespace std;class chessboard;struct MULTI_CB_STRCUT;struct CutStatis;struct CHESS_BD_SHARE POINT1* ptNode; long* ptNum; long* iter; int* clk;#ifdef MULTI_THREAD_ENV /HANDLE* pTH_BEGIN; /HANDLE* pTH_FINISH;#endif POINT1* best_plot; int* best_score; bool inited; CHESS_BD_SHARE():inited(false); CutStatis* pstatis;struct chessnode u32 code; unsigned char live3; unsigned char live4;public: void inc_lv4() live4 = 1; void dec_lv4() live4 = 0; int getlv4()return live4; int getlv3()return live3; int clr(int dir,int i) register int sht = 4-i+(dir3); code &= (0xf(i+1)i) | (i_code&(1i)-1); register int sht = 4-i+(dir3); code &= (0xfsht); code |= i_codesht; live3 = 0; for(unsigned int i=code;i!=0;i=i&(i-1) live3+; return live3; bool operator!=(const chessnode& node) if(code!=node.code)|(live3!=node.live3)|(live4!=node.live4) return true; return false; ;struct vfc_managepublic: chessnode nodes225; vector number; vector bkup; vector bkpt; vector lv3; vector lv4; vector lv5; int lv3_num; int lv4_num; int lv5_num; vfc_manage() number.push_back(0); lv3_num = 0; lv4_num = 0; lv5_num = 0; int mark(bool myturn);public: void set(int xy,int dir,u32 code); void clr(int xy,int dir,u32 code); void save_val(int xy,int dir,u32 code,int num); void return_val();class chessboardpublic: CHESS_BD_SHARE thread_env; void touch_thread_info(MULTI_CB_STRCUT* info,int index);public: bitMatrix bitbd_blk; bitMatrix bitbd_wht; BoardHash hcode; hashtable* table; Evalution stat; vector blkeval; vector whteval; vector steps; vector stat_need; int tablehit; int totalvis; int STEPS_C; vfc_manage blkmanage; vfc_manage whtmanage; bool vfc_flag;public: int check_game_fin(); int PVS(int alpha,int beta,int depth,int* flagtype); void init_eval(); chessboard(); chessboard(); void attach(hashtable* tlb)table=tlb; void ManStep(int x,int y,int color); int ComStep(); int Alpha_Beta(int alpha,int beta,int depth); int findVFC(int color); int probehash(int64 alpha,int64 beta,int depth); void recordstatusandplot(int value,int flag,int depth); int evaluate()return blk_evaluate()-wht_evaluate(); int make_step(const POINT1& pt); bool unmake_step(); bool unmake_step(POINT1& pt) if(steps.empty() return false; pt = steps.back(); return unmake_step(); int update_eval(const POINT1& pt); void return_eval(const POINT1& pt,int num); int update_manage(const POINT1& pt); void return_manage(); int blk_evaluate()return blkeval.back(); int wht_evaluate()return whteval.back(); int select_best_nodes(POINT1* i_pt,int num,int mycolor); int select_best_nodes(POINT1* i_pt,vector& allowpt); bool getEmergency(vector& pts); void reset() while(unmake_step() ; ;void getPhase(chessboard& bd,FILE* fd);void print_table(chessboard& bd);#endifBITRATE_H_#ifndef BITRATE_H_#define BITRATE_H_#includetypes.hconst int VIEW_C=4;class bitMatrixpublic: u32 bitpoolVIEW_C29;public: bitMatrix() memse

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论