void PrintRecord(Gamerec *g) { int i, len, count; unsigned char xside; Position temp; if(g->moves[0].mtype == EMPTY) { printf("\nGame record is empty.\n"); return; } StartPosition(&temp); printf("\n***** GAME RECORD *****\n"); for(len = 1; len < MAXGAMESIZE; len++) { if(g->moves[(len*(len-1)/2)].mtype != EMPTY) printf("\n %2d. ", len); count = 0; if(temp.side == WHITE) xside = BLACK; else xside = WHITE; while(count < len && !IsCheck(&temp, xside)) { i = len * (len - 1) / 2 + count; if(g->moves[i].mtype != EMPTY) { PrintMove(&temp, &(g->moves[i])); MakeMove(&temp, &(g->moves[i])); } else { printf("\n"); return; } count++; } if(temp.side == WHITE) temp.side = BLACK; else temp.side = WHITE; } }
void sBook::PrintMissingMoves(sPosition *p) { // show non-book moves leading to book positions sSelector Selector; UNDO undoData[1]; int move = 0; int flagMoveType; int unusedFlag; Selector.InitMoveList(p, 0, 0, move, MAX_PLY); while ( move = Selector.NextMove(0, &flagMoveType) ) { Manipulator.DoMove(p, move, undoData); if (IllegalPosition(p)) { Manipulator.UndoMove(p, move, undoData); continue; } if (GetPolyglotMove(p, 0)) { printf("info string missing "); PrintMove(move); printf("\n"); } Manipulator.UndoMove(p, move, undoData); } }
//again a simple function to print a move list for a given piece void PrintMoveList(MOVELIST *MoveList) { printf("COUNT - %d\n",MoveList->Count); for(int i=0;i<MoveList->Count;i++) { int Move=MoveList->MoveNum[i].Move; int Score=MoveList->MoveNum[i].Score; printf("%d %s\n",Score,PrintMove(Move)); } }
//============================================================================== // // main // //============================================================================== int main(int argc, char **argv) { int numDisks = GetNextInt(); int numPegs = GetNextInt(); std::vector<int> startState; std::vector<int> endState; for (int i = 0; i < numDisks; i++) { startState.push_back(GetNextInt()-1); } for (int i = 0; i < numDisks; i++) { endState.push_back(GetNextInt()-1); } Graph *graph = new Graph(numDisks, numPegs); int numMoves = graph->BuildAndExplore(startState, endState); std::cout << "num moves = " << numMoves << std::endl; Graph::Vertex *vtx = graph->GetVertex(endState); std::list<Graph::Vertex *> forwardList; for (int i = 0; i < numMoves; i++) { forwardList.push_front(vtx); vtx = vtx->predecessor; } std::cout << numMoves << std::endl; std::list<Graph::Vertex *>::iterator iter; for (iter = forwardList.begin(); iter != forwardList.end(); iter++) { PrintMove(*iter); } delete graph; return 0; }
void PrintComputersMove (MOVE computersMove, STRING computersName){ printf("%8s's move : ", computersName); PrintMove(computersMove); printf("\n\n"); }
//void deroulement_du_jeu() int main(int argc, char *argv[] ) { // if( !InitGUI() ){ return 0; } if( !CheckCommand(argc,argv) ){ return 0; } if( !InitLogFile() ){ printf("Fail init logFile\n"); } PrintHeaderMatch(); //Il faut nbMaxCps pour chaques joueurs, donc on multiplie par 2 nbMaxCps *= 2; if( !PrintLibInitHeader() ){ printf("Fail print libHeader\n"); } if( !LoadLibraries() ){ return(0); } PrintTLine(); SGameState* gameState = CreateBoard(); //Srand pour obtenir des nombres aléatoires srand(time(NULL)); //Initialisation des joueurs j1InitLibrary(j1Name); j2InitLibrary(j2Name); if( strlen(pathIA1) && !strlen(pathIA2) ){ PrintPhysicalPlayers(NULL,j2Name); } else if( !strlen(pathIA1) && strlen(pathIA2) ){ PrintPhysicalPlayers(j1Name,NULL); } else if( !strlen(pathIA1) && !strlen(pathIA2) ){ PrintPhysicalPlayers(j1Name,j2Name); } else { PrintPhysicalPlayers(NULL,NULL); } PrintIAPlayers(pathIA1,pathIA2); PrintMaxCps(nbMaxCps/2); j1StartMatch(); j2StartMatch(); int nbMatch = 3; int j1Win = 0; int j2Win = 0; while( nbMatch>0 && j1Win<2 && j2Win<2){ PrintMatch(4-nbMatch); // InitBoard //On initialise le nombre de coups maximums int cptCps = nbMaxCps; j1NbPenalty = 0; j2NbPenalty = 0; InitGameState(gameState); EPiece j1BoardInit[4][10]; EPiece j2BoardInit[4][10]; SetPlayerColors(); j1StartGame(j1Color,j1BoardInit); j2StartGame(j2Color,j2BoardInit); if( j1Color == ECblue ){ PrintColors(j2Name, j1Name); } else{ PrintColors(j1Name, j2Name); } //Initialisation des pions sur le plateau if( j1Color == ECblue ){ if( !InitBlueBoard(gameState,j1BoardInit) ){PrintBoardInitError(ECblue);return 0;} if( !InitRedBoard(gameState,j2BoardInit) ){PrintBoardInitError(ECred);return 0;} } else{ if( !InitRedBoard(gameState,j1BoardInit) ){PrintBoardInitError(ECred);return 0;} if( !InitBlueBoard(gameState,j2BoardInit) ){PrintBoardInitError(ECblue);return 0;} } //Le premier joueur est le rouge EColor player = ECred; EColor winner = 0; PrintLine(); PrintGameState(gameState); while( !winner && cptCps>0 ){ SMove move; //Duplication du plateau SGameState *gameStateCpy = (SGameState*) malloc(sizeof(SGameState)); GameStateCpy(gameState,gameStateCpy); //Si c'est le tour du joueur rouge, on inverse son plateau if( player == ECred ){ RevertGame(gameStateCpy); } //On cache les pions du joueur ennemi HideColor(gameStateCpy,abs((player+1)%2)+2); if( player == j1Color ){ move = j1NextMove(gameStateCpy); } else{ move = j2NextMove(gameStateCpy); } if( player == ECred ){ move.start.line = 9-move.start.line; move.end.line = 9-move.end.line; } int moveType = CorrectMove(gameState,move,player); PrintMove(player,move); //Mouvement incorrecte if( moveType == 0 ){ if( player == j1Color ){ j1NbPenalty++; j1Penalty(); PrintInvalidMove(player,j1NbPenalty); if( j1NbPenalty == 3 ){ PrintPenalty(j1Name,j1Color); winner = abs((j1Color+1)%2)+2; break; } } else{ j2NbPenalty++; j2Penalty(); PrintInvalidMove(player,j2NbPenalty); if( j2NbPenalty == 3 ){ PrintPenalty(j2Name,j2Color); winner = abs((j2Color+1)%2)+2; break; } } } else{ //Attaque if( moveType == 1 ){ EPiece army = gameState->board[move.start.line][move.start.col].piece; EPiece enemy = gameState->board[move.end.line][move.end.col].piece; if( player == j1Color ){ j1AttackResult(move.start,army,move.end,enemy); j2AttackResult(move.end,enemy,move.start,army); } else{ j1AttackResult(move.end,enemy,move.start,army); j2AttackResult(move.start,army,move.end,enemy); } PrintAttackResult(player,move.start,army,move.end,enemy); } ExecuteMove(gameState,move,player); } PrintGameState(gameState); free(gameStateCpy); if( player == ECred ){ player = ECblue; } else{ player = ECred; } winner = Finished(gameState); cptCps--; } if( cptCps == 0){ PrintMaxMoveReached(); } else{ if( j1Color == winner ){ PrintMatchWinner(j1Name, winner, 4-nbMatch);j1Win++; } else{ PrintMatchWinner(j2Name, winner, 4-nbMatch);j2Win++; } } nbMatch--; j1EndGame(); j2EndGame(); printf("j1Win : %d\nj2Win : %d\n",j1Win,j2Win); } if( j1Win >= 2 ){ PrintGameWinner(j1Name, j1Color); } else{ PrintGameWinner(j2Name, j2Color); } j1EndMatch(); j2EndMatch(); free(gameState); return(0); }
int sBook::GetPolyglotMove(sPosition *p, int printOutput) { int bestMove = 0; int bestScore = 0; int maxWeight = 0; int sumOfWeights = 0; int pos; polyglot_move entry[1]; int move; int score; int values[100]; U64 key = GetPolyglotKey(p); char moveString[6]; nOfChoices = 0; if (bookFile != NULL && bookSize != 0) { srand(Timer.GetMS() ); for (pos = FindPos(key); pos < bookSize; pos++) { ReadEntry(entry,pos); if (entry->key != key) break; move = entry->move; score = entry->weight; // ugly hack to convert polyglot move to a real one int fsq = Tsq(move); int tsq = Fsq(move); // correction for castling moves if (fsq == E1 && tsq == H1 && p->kingSquare[WHITE] == E1) tsq = G1; if (fsq == E8 && tsq == H8 && p->kingSquare[BLACK] == E8) tsq = G8; if (fsq == E1 && tsq == A1 && p->kingSquare[WHITE] == E1) tsq = C1; if (fsq == E8 && tsq == A8 && p->kingSquare[BLACK] == E8) tsq = C8; // now we want to get a move with full data, not only from and to squares int realMove = (tsq << 6) | fsq; MoveToStr(realMove, moveString); realMove = StrToMove(p, moveString); if (maxWeight < score) maxWeight = score; sumOfWeights += score; moves[nOfChoices] = realMove; values[nOfChoices] = score; nOfChoices++; } // pick a move, filtering out those with significantly lower weight for (int i = 0; i<nOfChoices; i++) { // report about possible choices and rejected moves if (values[i] > 1 || maxWeight == 1) { if (printOutput) { printf("info string "); PrintMove(moves[i]); printf(" %d %%", (values[i] * 100) / sumOfWeights ); if (IsInfrequent(values[i], maxWeight)) printf(" infrequent "); } } // shall we pick this move? if (!IsInfrequent(values[i], maxWeight)) { bestScore += values[i]; if (my_random(bestScore) < values[i]) bestMove = moves[i]; } printf("\n"); } } //if (printOutput) PrintMissingMoves(p); return bestMove; }
void DisplayCurrmove(int move, int tried) { printf("info currmove "); PrintMove(move); printf(" currmovenumber %d \n", tried); }