bool TEngine::Tick3(board_t * board, TFindPos * fp, bool full) { mv_t pv[3]; if (SearchPos(board,fp,pv, full)) { int pv_len = 0; for (int i=0; i<3; i++) { if (pv[i]==0) break; else pv_len++; } switch (pv_len) { case 0: if (!StateNewGame) StartNewGame(); StartNewThink(); return true; case 1: if (!StateNewGame) StartNewGame(); LastMove = pv[0]; StartNewThink(); return true; } } return false; }
void SelfPlay() { printf("\n\n--------------The Bot Will Now Play itself to Some Randomized Depth-------------\n\n"); printf("Press Any Key To See The Next Move\n"); BOARD *board=new BOARD; SetStart(board); getchar(); while(1) { MOVE *list=new MOVE; GenMoves(board,list); if(list->Count==0) { printf("%c LOST THE GAME\n\n",PceSideChar[board->Side]); break; } int Depth=5+rand()%4; vector<int>BestMove=SearchPos(board,Depth); PrintBoard(board); MakeMove(board,BestMove); getchar(); getchar(); } StartGame(); }
int Do_GInfo(struct Node *n, struct Property *p, struct BoardStatus *st) { int x, y; if(st->ginfo && (st->ginfo != n->buffer)) { SearchPos(st->ginfo, sgfc->buffer, &x, &y); PrintError(E4_GINFO_ALREADY_SET, p->buffer, p->idstr, y, x); return(FALSE); } else { st->ginfo = n->buffer; if(p->id == TKN_KI) { if(Find_Property(n, TKN_KM)) PrintError(W_INT_KOMI_FOUND, p->buffer, "deleted (<KM> property found)"); else { PrintError(W_INT_KOMI_FOUND, p->buffer, "converted to <KM>"); x = atoi(p->value->value); p = New_PropValue(n, TKN_KM, "1234567890", NULL, FALSE); if(x & 1) sprintf(p->value->value, "%d.5", x/2); else sprintf(p->value->value, "%d", x/2); } return(FALSE); } return(TRUE); } }
/** \param[in] ptr Pointer to a stringHash instance containing the name to search inside the list. \return Pointer of the FstringHash in the list or NULL if not found. */ FstringHash* FlistHash::Search( evenja::FstringHash* ptr) { FstringHash** pos = SearchPos( ptr); if( pos) // if something found ... return *pos; // ...return the pointer of it else return NULL; }
/** \param[in] ptr Pointer to a stringHash instance containing the name to search inside the list. \return Pointer of the same FstringHash in the list or NULL if not found. */ FstringHash* FlistHash::addOrRemove( evenja::FstringHash* ptr) { FstringHash** pos = SearchPos( ptr); // First search if allready exist if( !pos) // if not found then add the new { add( ptr); // add the param return NULL; } else // if found then remove the pointer return ( FstringHash*) remove( ( void**) pos); }
/** \param[in] ptr Pointer to a stringHash instance containing the name to search inside the list. \return Pointer of the FstringHash in the list or NULL if not found. */ FstringHash* FlistHash::addOrGet( evenja::FstringHash * ptr) { FstringHash** pos = SearchPos( ptr); // First search if allready exist if( !pos) // if not found then ... { add( ptr); // ... add the new one return NULL; } else // if found then ... return ( FstringHash*) get( ( void**) pos); // ... get the founded }
static int get_field_record(const pKColumn current,const int id ,char * field , const int from, const int to) { if(!current || id < 0 || !field || from<0 || to < from) { debug("parameter error"); return ERR; } int res = ERR ; if(OK == IsInNullList(current,id)) { field[0]='\0'; return -2; } else { res = SearchPos(current,id,from,to); if(res != ERR) { GetUnitDscr(current,field,res); } else { debug("error: search pos in ulist"); return ERR; } } return res; }
bool TEngine::Tick2(board_t * board, TFindPos * fp, bool full) { mv_t pv[3]; if (SearchPos(board,fp,pv, full)) { int pv_len = 0; for (int i=0; i<3; i++) { if (pv[i]==0) break; else pv_len++; } switch (pv_len) { case 0: if (LastMove) { LastMove = 0; StartNewThink(); } if (!GameStarted) { StartNewGame(); GameStarted = true; } return true; case 1: StateNewGame = false; if (LastMove != pv[0]) { LastMove = pv[0]; StartNewThink(); } return true; case 2: StateNewGame = false; AddMove(pv[0]); LastMove = pv[1]; StartNewThink(); return true; } } return false; }
void PlayBot() { printf("\n\nAt Any Time In The Game If You Want To See The Grid Indexing In Which You Have To Make A Move\n\n"); printf("During Enter A Move Command...Just Press 0 And Press Enter \n\n"); BOARD *board=new BOARD; SetStart(board); printf("The Starting Board\n\n"); PrintBoard(board); char Inp[200]; int Side; printf("\nChoose Your Side...\n\n0. For Black\n1. For White\n"); scanf("%d",&Side); if(Side==0) { MOVE *list1=new MOVE; GenMoves(board,list1); vector<int>BestMove1=SearchPos(board,8); MakeMove(board,BestMove1); PrintBoard(board); } while(1) { printf("\n\nEnter Your Move\n"); getchar(); scanf("%[^\n]",&Inp); if(Inp[0]=='0') { PrintIndex(); continue; } else if(Inp[0]=='1') { printf("\nYour Possible MoveList is\n"); MOVE *YourMoveList=new MOVE; GenMoves(board,YourMoveList); PrintMoveList(YourMoveList); } vector<int>Move=ParseMove(Inp); if(MoveExists(board,Move)) MakeMove(board,Move); else { MOVE *User=new MOVE; GenMoves(board,User); if(User->Count==0) { printf("Sorry You Lost\n\n"); break; } else printf("Invalid Move...Enter Again\n\n"); continue; } PrintBoard(board); printf("-----------------------------------Bot's Turn----------------------------------\n"); MOVE *Bot=new MOVE; GenMoves(board,Bot); if(Bot->Count==0) { printf("--------------------------Congratulations You Win--------------------------\n"); break; } vector<int>BestMove=SearchPos(board,8); MakeMove(board,BestMove); PrintBoard(board); } StartGame(); }