bool TTrailBoard::playGame( TForm *caller, int gameid ) { m_startTime = Now(); game->m_returnDataHeader.partid= L"0"; game->m_returnDataHeader.sessionid= L"0"; game->m_returnDataHeader.sectionid= L"hm05"; String startDate = m_startTime.FormatString("yyyy-mm-dd") + "T" + m_startTime.FormatString("hh:mm:ss"); game->m_returnDataHeader.dateStarted=startDate; //L"2013-08-30T10:16:30:000"; game->m_returnDataHeader.abandon= 0; game->m_returnDataHeader.introelapsed=0; //Intro elasped time game->m_returnDataHeader.totelapsed=0; game->m_returnDataHeader.practiceaelapsed=0; game->m_returnDataHeader.practiceaerrors=0; game->m_returnDataHeader.practicebelapsed=0; game->m_returnDataHeader.practiceberrors=0; game->m_returnDataHeader.partaelapsed=0; game->m_returnDataHeader.partaerrors=0; game->m_returnDataHeader.partbelapsed=0; game->m_returnDataHeader.partberrors=0; resetBoard(); game->initGame(); Show(); panel_abandon->Visible = true; caller->Hide(); if (results) delete results; game->run( ); while ( game->isRunning() ) // WAIT FOR END SIGNAL { Application->ProcessMessages(); } panel_abandon->Visible = false; game->m_returnDataHeader.totelapsed = MilliSecondsBetween(Now(),m_startTime); //milliseconds elapsed since 1 January 1970 std::stringstream timeString; timeString << game->getRunTime(); /* if (!game->wasAbandoned()) fm_tmessage->msgOk("Congratulations!\n\nYou completed the test in " + timeString.str() + " deci-seconds " + "\n\nWell done.","WHOOOT!", POPUP_COLOUR ); */ extractResults(); /* std::string resultString = results->serializeOut(); if (SaveTextFileDialog->Execute()) { int iFileHandle = FileCreate(SaveTextFileDialog->FileName); if (iFileHandle > 0) FileWrite(iFileHandle,(void*)AnsiString(resultString.c_str()).c_str(),resultString.length()); FileClose(iFileHandle); } */ caller->Show(); Hide(); return( true ); }
void redo(Game* game) { int turn = 0; int maxTurn = 0; char cmd[7]; int rst = 0; int debug = 0; int in = 0; Piece* piece; clock_t start = 0; assert(game); maxTurn = game->turn-2; game->turn = 0; resetBoard(game); if (maxTurn <= 0) { printBoard(game); return; } for (turn = 1;turn <= maxTurn;turn++) { rst = getStepFromLog(game, turn, cmd); rst = movePieceNotation(game, cmd); if (cmd[4] > 'A' && cmd[4] < 'R') { piece = getPiece(game, cmd[2]-'a', cmd[3]-'1'); piece->type = cmd[4]; } game->turn = turn; } printBoard(game); }
void generateUniqueBoard(sudokuGrid *game) { int i, j; int positions[GRID_SIZE]; int targetValue, position; //start by generating a random board resetBoard(game); generateRandomBoard(game); //populate and shuffle positions array - these are targets for cell removal j = 0; for (i = 0; i <= GRID_SIZE; i++) { positions[j] = i; j++; } shuffleArr(positions,GRID_SIZE); //clear cells until we no longer have a unique solution j = 0; while (j < (GRID_SIZE - GRID_SIZE/PRINCIPAL_NUM)) { if (solutionCount(game,2) > 1) { //restore the last cell that we removed to ensure that we still have a unique solution commitMove(game,position,targetValue); } targetValue = game->values[positions[j]]; position = positions[j]; commitMove(game,position,BLANK_VALUE); j++; } //restore the last cell that we removed to ensure that we still have a unique solution commitMove(game,position,targetValue); }
//--------------------------------------------------------------------------- bool Tfm_board::playGame( TForm *caller, LAYOUT *ly ) { current_layout = ly; current_layout->match = 0; current_layout->miss = 0; current_layout->duration = 0; resetBoard(); int npairs = ( current_layout->rows * current_layout->cols ) / 2; if ( npairs > (int) game->pack.size() ) {MESS::bug( "Insufficient cards in playGame pack for next level"); abandon = true; return( false ); } if ( ! game->initPairs( npairs, current_layout ) ) {MESS::bug( "Error in playGame random allocation" ); return( false ); } Show(); caller->Hide(); game->run( timer_preview, ( npairs < 5 ) ? 3000 : 5000 ); while ( game->isRunning() ) // WAIT FOR END SIGNAL {Application->ProcessMessages(); } current_layout->duration = game->getRunTime(); caller->Show(); Hide(); return( true ); }
void factoryReset() { UART_PRINT("[Blink] Factory reset\r\n"); resetParseClient(); resetConfig(); resetNetwork(); resetBoard(); }
void BoardWindow::revokeMoves() { while (!moves.empty()) moves.removeLast(); updateLabel(); resetBoard(); loadBoard(); }
Board::Board(int x, int y) { size_.x = x; size_.y = y; calculateBoardPos(); allocBoard(); resetBoard(); }
void Board::newBoard(int x, int y) { deleteBoard(); size_.x = x; size_.y = y; calculateBoardPos(); allocBoard(); resetBoard(); }
int main (int argc, char *argv[]) { double total[SIZE*SIZE] = {0}; double current[SIZE*SIZE] = {0}; resetBoard(total, SIZE); for (int i = 0; i < SIZE; i++) { for (int j = 0; j < SIZE; j++) { //printBoard("total", total, SIZE); resetBoard(current, SIZE); current[curIndex] = 1.0; // seed board with a flea. iterate(current, SIZE, NUM_ITERATIONS); //printBoard("current", current, SIZE); addToTotal(current, total, SIZE); } } //printBoard("total", total, SIZE); printf("Expected Number of Empty %lf\n", calculateExpectation(total, SIZE)); return 0; }
void BoardWindow::parseResponse() { QString data = Socket::readData(); QJsonDocument d = QJsonDocument::fromJson(data.toUtf8()); QJsonObject json = d.object(); if (json.contains("request")) { std::string request_type = json["request"].toString().toStdString(); if (request_type == "message") { QDateTime timestamp; timestamp.setTime_t(json["timestamp"].toString().toInt()); ui->chatTextEdit->append("[" + timestamp.toString("hh:mm") + "] " + json["nick"].toString() + ": " + json["message"].toString()); } else if (request_type == "board") { waiting = false; resetBoard(); time = json["time"].toString(); ui->turnsLabel->setText("Turn: " + json["current color"].toString()); yourTurn = json["current color"].toString() == color ? true : false; // ui->chatTextEdit->append("Loading board"); for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) board[i][j] = json["board"].toArray()[i].toArray()[j].toString()[0].toLatin1(); loadBoard(); } else if (request_type == "game_over") { ui->chatTextEdit->append("GAME OVER!"); if (json["winner"] == color) { ui->chatTextEdit->append("Congratulatons, you won!"); } else { ui->chatTextEdit->append("Unfortunately, you lost. Maybe next time?"); } } } else if (json.contains("status")) { auto status = json["status"].toString(); if (status != "ok") { if (status == "wrong move") { waiting = false; revokeMoves(); } ui->chatTextEdit->append("Error: " + status); } } }
void ChessGame::generateOpening() { if (m_book[Chess::Side::White] == 0 || m_book[Chess::Side::Black] == 0) return; resetBoard(); // First play moves that are already in the opening foreach (const Chess::Move& move, m_moves) { Q_ASSERT(m_board->isLegalMove(move)); m_board->makeMove(move); if (!m_board->result().isNone()) return; }
void multiPlayer() { do { system("CLS"); gameName(); draw(); setMove(getMove()); checkWin(); checkBoard(); }while(gameFinished!=true); printBoard(); system("PAUSE"); resetBoard(); }
void replay(Game* game) { int turn = 0; int maxTurn = game->turn; char cmd[7]; int rst = 0; int debug = 0; int in = 0; Piece* piece; clock_t start = 0; assert(game); game->turn = 0; resetBoard(game); if (maxTurn <= 1) { printBoard(game); return; } for (turn = 1;turn <= maxTurn;turn++) { rst = getStepFromLog(game, turn, cmd); rst = movePieceNotation(game, cmd); /* rst = directMoveNotation(game, cmd);*/ if (cmd[4] > 'A' && cmd[4] < 'R') { piece = getPiece(game, cmd[2]-'a', cmd[3]-'1'); piece->type = cmd[4]; } game->turn = turn; if (debug) { printf("%s : valid = %d \n", cmd, rst); } printBoard(game); if (rst <0) { printf("Position is outside the chessboard? \n"); printf("The log may be incorrect. \n"); system("PAUSE"); } /* printf("press x to stop \n"); start = clock(); while ((clock() - start)/CLOCKS_PER_SEC < 1) { if (kbhit()) in = getch(); if (in == 'x') { break; } } */ } }
void singlePlayer() { do { system("CLS"); gameName(); draw(); if(player==1) {setRmove(getRmove());} else {setMove(getMove());} checkWin(); checkBoard(); }while(gameFinished!=true); printBoard(); system("PAUSE"); resetBoard(); }
void iterate(double *board, int size, int times) { static double workBoard[SIZE*SIZE] = {0}; double *curBoard = board; double *nextBoard = workBoard; for (int k = 0; k < times; k++) { resetBoard(nextBoard, size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (i != 0) { double a = curBoard[(i-1)*size + j] * prob(i-1, j); double b = nextBoard[curIndex]; nextBoard[curIndex] += a;//1.0 - (1.0 - a)*(1.0 - b); } if (i != size-1) { double a = curBoard[(i+1)*size + j] * prob(i+1, j); double b = nextBoard[curIndex]; nextBoard[curIndex] += a;//1.0 - (1.0 - a)*(1.0 - b); } if (j != 0) { double a = curBoard[i*size + j-1] * prob(i, j-1); double b = nextBoard[curIndex]; nextBoard[curIndex] += a;//1.0 - (1.0 - a)*(1.0 - b); } if (j != size-1) { double a = curBoard[i*size + j+1] * prob(i, j+1); double b = nextBoard[curIndex]; nextBoard[curIndex] += a;//1.0 - (1.0 - a)*(1.0 - b); } } } double *tmp = curBoard; curBoard = nextBoard; nextBoard = tmp; } if (curBoard != board) for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) board[curIndex] = curBoard[curIndex]; }
void ChessGame::setMoves(const PgnGame& pgn) { Q_ASSERT(pgn.variant() == m_board->variant()); setStartingFen(pgn.startingFenString()); resetBoard(); m_moves.clear(); foreach (const PgnGame::MoveData& md, pgn.moves()) { Chess::Move move(m_board->moveFromGenericMove(md.move)); Q_ASSERT(m_board->isLegalMove(move)); m_board->makeMove(move); if (!m_board->result().isNone()) return; m_moves.append(move); } }
bool ChessGame::setMoves(const PgnGame& pgn) { setStartingFen(pgn.startingFenString()); if (!resetBoard()) return false; m_scores.clear(); m_moves.clear(); foreach (const PgnGame::MoveData& md, pgn.moves()) { Chess::Move move(m_board->moveFromGenericMove(md.move)); if (!m_board->isLegalMove(move)) return false; m_board->makeMove(move); if (!m_board->result().isNone()) return true; m_moves.append(move); } return true; }
int main() { REG_DISPCTL = MODE3 | BG2_ENABLE; //Draw Start Screen drawImage3(0, 0, TITLESCREEN_WIDTH, TITLESCREEN_HEIGHT, titleScreen); //var to keep track of current position in game int inGame = 0; int inTitle = 1; while(1) { //START GAME if(inTitle == 1 && KEY_DOWN_NOW(BUTTON_START)) { inGame = 1; inTitle = 0; int bgcolor = GRAY; DMA[3].src = &bgcolor; DMA[3].dst = videoBuffer; DMA[3].cnt = 38400 | DMA_SOURCE_FIXED | DMA_DESTINATION_INCREMENT | DMA_ON; drawLevel1Board(); refillLives(); resetBoard(); } //JUMP BACK TO TITLE SCREEN if(KEY_DOWN_NOW(BUTTON_SELECT)) { inGame = 0; inTitle = 1; drawImage3(0, 0, TITLESCREEN_WIDTH, TITLESCREEN_HEIGHT, titleScreen); } //GAME PLAY if(inGame == 1) { if(KEY_DOWN_NOW(BUTTON_RIGHT)) { moveRight(); } else if(KEY_DOWN_NOW(BUTTON_LEFT)) { moveLeft(); } else if(KEY_DOWN_NOW(BUTTON_UP)) { moveUp(); } else if(KEY_DOWN_NOW(BUTTON_DOWN)) { moveDown(); } waitForVblank(); clearOld(); drawCurr(); //test if reach end of level if(isWin() == 1) { drawImage3(0, 0, YOUWIN_WIDTH, YOUWIN_HEIGHT, youwin); inGame = 0; inTitle = 0; } //test for Collisions with Enemies if(isCollide() > 0) { if(currLives() > 0) { resetBoard(); } else { //out of lives = game over inGame = 0; inTitle = 0; drawImage3(0, 0, GAMEOVER_WIDTH, GAMEOVER_HEIGHT, gameover); } } } } return 0; }
pair<double,double> CoCheckersExperiment::playGame( shared_ptr<NEAT::GeneticIndividual> ind1, shared_ptr<NEAT::GeneticIndividual> ind2 ) { //You get 1 point just for entering the game, wahooo! pair<double,double> rewards(1.0,1.0); #if DEBUG_GAME_ANNOUNCER cout << "Playing game\n"; #endif populateSubstrate(ind1,0); populateSubstrate(ind2,1); uchar b[8][8]; //cout << "Playing games with HyperNEAT as black\n"; //for (handCodedType=0;handCodedType<5;handCodedType++) for (testCases=0;testCases<2;testCases++) { if (testCases==0) { individualBlack = ind1; individualWhite = ind2; } else //testCases==1 { individualBlack = ind2; individualWhite = ind1; } resetBoard(b); int retval=-1; int rounds=0; for (rounds=0;rounds<CHECKERS_MAX_ROUNDS&&retval==-1;rounds++) { //cout << "Round: " << rounds << endl; moveToMake = CheckersMove(); if (testCases==0) { currentSubstrateIndex=0; } else //testCases==1 { currentSubstrateIndex=1; } //cout << "Black is thinking...\n"; evaluatemax(b,CheckersNEATDatatype(INT_MAX/2),0,2); #if CHECKERS_EXPERIMENT_DEBUG cout << "BLACK MAKING MOVE\n"; printBoard(b); #endif if (moveToMake.from.x==255) { //black loses cout << "BLACK LOSES!\n"; retval = WHITE; } else { makeMove(moveToMake,b); retval = getWinner(b,WHITE); } #if CHECKERS_EXPERIMENT_LOG_EVALUATIONS memcpy(gameLog[rounds*2],b,sizeof(uchar)*8*8); #endif #if COCHECKERS_EXPERIMENT_DEBUG printBoard(b); CREATE_PAUSE(""); #endif if (retval==-1) { //printBoard(b); moveToMake = CheckersMove(); { //progress_timer t; if (testCases==0) { currentSubstrateIndex=1; } else //testCases==1 { currentSubstrateIndex=0; } //cout << "White is thinking...\n"; evaluatemin(b,CheckersNEATDatatype(INT_MAX/2),0,3); //cout << "SimpleCheckers time: "; } #if COCHECKERS_EXPERIMENT_DEBUG cout << "WHITE MAKING MOVE\n"; printBoard(b); #endif if (moveToMake.from.x==255) { //white loses cout << "WHITE LOSES BECAUSE THERE'S NO MOVES LEFT!\n"; retval = BLACK; #if COCHECKERS_EXPERIMENT_DEBUG printBoard(b); CREATE_PAUSE(""); #endif } else { makeMove(moveToMake,b); retval = getWinner(b,BLACK); } #if COCHECKERS_EXPERIMENT_DEBUG printBoard(b); CREATE_PAUSE(""); #endif } #if CHECKERS_EXPERIMENT_LOG_EVALUATIONS memcpy(gameLog[rounds*2+1],b,sizeof(uchar)*8*8); #endif } if (retval==BLACK) { #if DEBUG_GAME_ANNOUNCER cout << "BLACK WON!\n"; #endif if (ind1==individualBlack) { rewards.first += 800; rewards.first += (CHECKERS_MAX_ROUNDS-rounds); } else { rewards.second += 800; rewards.second += (CHECKERS_MAX_ROUNDS-rounds); } } else if (retval==-1) //draw { #if DEBUG_GAME_ANNOUNCER cout << "WE TIED!\n"; #endif //rewards.first += 200; //rewards.second += 200; } else //White wins { #if DEBUG_GAME_ANNOUNCER cout << "WHITE WON\n"; #endif if (ind1==individualWhite) { rewards.first += 800; rewards.first += (CHECKERS_MAX_ROUNDS-rounds); } else { rewards.second += 800; rewards.second += (CHECKERS_MAX_ROUNDS-rounds); } } int whiteMen,blackMen,whiteKings,blackKings; //countPieces(gi.board,whiteMen,blackMen,whiteKings,blackKings); countPieces(b,whiteMen,blackMen,whiteKings,blackKings); if (ind1==individualWhite) { rewards.first += (2 * (whiteMen) ); rewards.first += (3 * (whiteKings) ); rewards.second += (2 * (blackMen) ); rewards.second += (3 * (blackKings) ); } else { rewards.first += (2 * (blackMen) ); rewards.first += (3 * (blackKings) ); rewards.second += (2 * (whiteMen) ); rewards.second += (3 * (whiteKings) ); } } #if DEBUG_GAME_ANNOUNCER cout << "Fitness earned: " << rewards.first << " & " << rewards.second << endl; CREATE_PAUSE(""); #endif return rewards; }
int parseFen(char* fen, board& b){ int row = ROW_8; int file = FILE_A; int piece = 0; // number of pieces int count = 0; // number of empty squares int sq64 = 0; int sq120 = 0; resetBoard(b); while (row >= ROW_1){ count = 1; switch (*fen) { case 'p': piece = bP; break; case 'r': piece = bR; break; case 'n': piece = bN; break; case 'b': piece = bB; break; case 'k': piece = bK; break; case 'q': piece = bQ; break; case 'P': piece = wP; break; case 'R': piece = wR; break; case 'N': piece = wN; break; case 'B': piece = wB; break; case 'K': piece = wK; break; case 'Q': piece = wQ; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': piece = EMPTY; count = *fen - '0'; break; case '/': case ' ': row--; file = FILE_A; fen++; continue; default: std::cout << "FEN ERROR" << std::endl; return -1; } for (int i=0; i<count; ++i){ sq64 = row*8 + file; sq120 = SQ64[sq64]; if (piece != EMPTY){ b.pieces[sq120] = piece; } file++; } fen++; } if (*fen == 'w'){ b.side = WHITE; } else if (*fen == 'b'){ b.side = BLACK; } fen += 2; for (int i=0; i<4; ++i){ if (*fen == ' '){ break; } switch (*fen){ case 'K': b.castlePermission |= whiteKingCastle; break; case 'Q': b.castlePermission |= whiteQueenCastle; break; case 'k': b.castlePermission |= blackKingCastle; break; case 'q': b.castlePermission |= blackQueenCastle; break; default: break; } fen++; } fen++; if (b.castlePermission < 0 || b.castlePermission > 15){ throw castlePermBounds(); } if (*fen != '-'){ file = fen[0] - 'a'; row = fen[1] - '1'; b.enPassent = toSquareNumber(file, row); } b.posKey = generatePosKey(b); updateMateriaList(b); return 0; }
int main() { memcpy(board2,board,sizeof(int)*rows*columns); int height=800,width=800; //height and width of screen gfx_open(width,height,"Pacman"); gfx_clear_color(0,0,0); gfx_clear(); int boardHeight=radius*rows,boardWidth=radius*columns;//Height of the board int xtopleft=width/2-boardWidth/2; //x coord of top left corner of board int ytopleft=height/2-boardHeight*9/16; //y coord of top left corner of board char movement; int i,lives=3;//start with 3 lives int win=0; int active=0; //this changes depending on number of dots left int initialDots=dotsNumber(); int remainingDots=dotsNumber(); int score=0; int loop[4]={0,0,0,0}; int frightenLoop[4]={0}; int newScore[3]={0,0,0};//values [0]:new score to display(when ghost is killed),[1]:xvalue,[2]:yvalue Location pacman; Location ghosts[4];// enumerated to blinky, pinky, inky, clyde; /*There are four states: 0: Chase, 1: Scatter, 2: Frighten, 3: Dead, and 4: Housed */ int state[4]={scatter,scatter,scatter,scatter}; while(1){ titleScreen(height,width,ghosts,&pacman,state); score=0; lives=3; win=0; for(i=0;i<=3;i++) loop[i]=0; //reset the game resetBoard(); gfx_wait(); /* This is the gameplay loop, will repeat every time a life is lost */ while(lives>0){ gfx_clear(); /* Initialize pacman's location */ pacman.x=pacman.prevX=7; pacman.y=pacman.prevY=12; pacman.orientation=right; /* Initialize ghost's locations */ for(i=blinky;i<=clyde;i++){state[i]=scatter;} ghosts[blinky].x=7; ghosts[blinky].prevX=8; ghosts[blinky].y=ghosts[blinky].prevY=6; ghosts[blinky].orientation=left; ghosts[pinky].x=7; ghosts[pinky].prevX=7; ghosts[pinky].y=7; ghosts[pinky].prevY=8; ghosts[pinky].orientation=up; ghosts[inky].x=ghosts[inky].prevX=6; ghosts[inky].y=7; ghosts[inky].prevY=8; ghosts[inky].orientation=right; ghosts[clyde].x=ghosts[clyde].prevX=8; ghosts[clyde].y=7; ghosts[clyde].prevY=8; ghosts[clyde].orientation=left; /* These two statements draw pacman and the board to begin the program */ drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,2,score); drawPacman(xtopleft+radius*pacman.x+radius/2,ytopleft+radius*pacman.y+radius/2,pacman.orientation,0); for(i=blinky;i<=clyde;i++){ drawGhost(xtopleft+radius*ghosts[i].x+radius/2,ytopleft+radius*ghosts[i].y+radius/2,i,ghosts[i].orientation,state,frightenLoop[i]); } /* This loop is the gameplay after all initialization */ while(1){ /*if(gfx_event_waiting()){prevMovement=movement;*/ movement=gfx_wait();//} /* This block updates pacman position, checks for death * then updates ghosts' positions, then checks for death again */ movePacman(&pacman,ghosts,movement,xtopleft,ytopleft,boardHeight,boardWidth,active,state,&score,frightenLoop); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } targetGhosts(ghosts,&pacman,xtopleft,ytopleft,boardHeight,boardWidth,active,state); if(checkDeath(&pacman,ghosts,xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,state,&score,newScore,frightenLoop,loop[0])){ //pacman's death? for(i=0;i<=3;i++) loop[i]=0; //reset the game lives--; //decrease the lives printf("LIVES: %i\n",lives); break; } ghostState(loop,state,frightenLoop); active=activeGhosts(ghosts,loop); /* The next function animates the motion of all of the objects (pacman and ghosts */ animateMotion(xtopleft,ytopleft,boardHeight,boardWidth,&pacman,ghosts,height,width,lives,state,score,newScore,frightenLoop,loop[0]); /* The case to exit the loop is winning, when there are no dots left */ if(dotsNumber()==0){ //The player got all the dots, they won the game win=1; break; } } if(lives<=0){ gfx_clear(); printf("\n\nGAME OVER\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,0,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will start the entire game over including the title screen else break;} else if(win){ printf("\n\nWINNER!\n\n"); drawBoard(xtopleft,ytopleft,boardHeight,boardWidth,height,width,lives,win,score); if(tolower(gfx_wait())=='n'){ return 0; }//This will end the game else break;} } } }
void checkForInput(Game* game){ char input[100]; while(1){ if(fgets(input,100,stdin)){ printf("#XBoardSentCommand %s",input); if(strncmp(input,"xboard",6)==0){ //output newline printf("\n"); }else if(strncmp(input,"accepted",8)==0){ //ignore }else if(strncmp(input,"rejected",8)==0){ printf("Error accepting %s please fix that\n",input); exit(-1); }else if(strncmp(input,"protover",8)==0){ printf("feature playother=0\n"); printf("feature sigterm=0\n"); printf("feature sigint=0\n"); printf("feature analyze=0\n"); printf("feature colors=0\n"); printf("feature myname=\"Chengine\"\n"); printf("feature reuse=0\n"); printf("feature ping=1\n"); printf("feature san=0\n"); printf("feature debug=1\n"); printf("feature time=1\n"); printf("feature variants=\"normal\"\n"); printf("feature done=1\n"); //comes immidiately after xboard command if version 2 or above //else new command might follow from old version //set xboard version to N from "protover N" string //reply with feature string answers are "accepted" "rejected" }else if(strncmp(input,"fen",3)==0){ readFENString(&game->board, &input[4]); //reset board white to move engine is black, reset clocks //do not ponder even if pondering is on }else if(strncmp(input,"new",3)==0){ resetBoard(&game->board); game->Player[WHITE].depth=200; game->Player[WHITE].timelimit=30000; game->Player[WHITE].isAi=0; game->Player[WHITE].useOpeningTable=1; game->Player[BLACK].depth=200; game->Player[BLACK].timelimit=30000; game->Player[BLACK].isAi=1; game->Player[BLACK].useOpeningTable=1; //reset board white to move engine is black, reset clocks //do not ponder even if pondering is on }else if(strncmp(input,"variant",6)==0){ }else if(strncmp(input,"quit",4)==0){ //exit chess engine game->isRunning=0; return; }else if(strncmp(input,"random",6)==0){ //can use it to add small random to eval function to vary play }else if(strncmp(input,"force",5)==0){ //engine plays neither color, stop clocks, //engine just checks that moves coming are legal and proper color is moving game->Player[BLACK].isAi=0; game->Player[WHITE].isAi=0; }else if(strncmp(input,"go",2)==0){ game->Player[game->board.colorToPlay].isAi=1; game->Player[game->board.colorToPlay ^ 1].isAi=0; return; //leave force mode, set engine to play color that is on move //start thinking and clock }else if(strncmp(input,"white",5)==0){ //leave force mode and let engine play other color //begin pondering if enabled /* game->board.colorToPlay=WHITE; Properties player=game->Player[WHITE]; game->Player[WHITE]=game->Player[BLACK]; game->Player[BLACK]=player; game->Player[BLACK].isAi=1;*/ }else if(strncmp(input,"black",5)==0){ //leave force mode and let engine play other color //begin pondering if enabled /* game->board.colorToPlay=BLACK; Properties player=game->Player[WHITE]; game->Player[WHITE]=game->Player[BLACK]; game->Player[BLACK]=player; game->Player[WHITE].isAi=1; //state->isPlayerAi[WHITE]=true; //state->isPlayerAi[BLACK]=false;*/ }else if(strncmp(input,"playother",9)==0){ //leave force mode and let engine play other color //begin pondering if enabled //game->Player[game->board.colorToPlay==WHITE?BLACK:WHITE].isAi=1; /* Properties player=game->Player[WHITE]; game->Player[WHITE]=game->Player[BLACK]; game->Player[BLACK]=player;*/ }else if(strncmp(input,"level",5)==0){ // set time controls level MPS BASE INC }else if(strncmp(input,"st",2)==0){ // set time controls st TIME game->Player[WHITE].timelimit=(int)(input[3]-'0'); game->Player[BLACK].timelimit=(int)(input[3]-'0'); }else if(strncmp(input,"sd",2)==0){ game->Player[WHITE].depth=(int)(input[3]-'0'); game->Player[BLACK].depth=(int)(input[3]-'0'); }else if(strncmp(input,"nps",3)==0){ /*The engine should not use wall-clock time to make its timing decisions, but an own internal time measure based on the number of nodes it has searched (and will report as "thinking output", see section 10), converted to seconds through dividing by the given NODE_RATE. Example: after receiving the commands "st 8" and "nps 10000", the engine should never use more that 80,000 nodes in the search for any move. In this mode, the engine should report user CPU time used (in its thinking output), rather than wall-clock time. This even holds if NODE_RATE is given as 0, but in that case it should also use the user CPU time for its timing decisions. The effect of an "nps" command should persist until the next "new" command.*/ printf("Error (unkown command): nps\n"); }else if(strncmp(input,"time",4)==0){ // set a clock that belongs to the engine, even if color changes in 1/1000 sec if(game->Player[WHITE].isAi==1){ game->Player[WHITE].timelimit=atoi(&input[5]); }else{ game->Player[BLACK].timelimit=atoi(&input[5]); } }else if(strncmp(input,"otim",2)==0){ // set clock that belongs to the opponent, even is color changes if(game->Player[WHITE].isAi==1){ game->Player[BLACK].timelimit=atoi(&input[5]); }else{ game->Player[WHITE].timelimit=atoi(&input[5]); } }else if(strncmp(input,"usermove",8)==0){ // xboard version2 feature can enable form // usermove MOVE //e2e4 <-- normal move //e7e8q <--- pawn promotion //e1g1, e1c1, e8g8, e8c8 <-- castling }else if(strncmp(input,"pins",4)==0){ }else if(strncmp(input,"?",1)==0){ // force move if thinking, else ignore }else if(strncmp(input,"ping",4)==0){ // reply to ping N with pong N only when all other commands finished printf("pong %d",(int)(input[5]-'0')); }else if(strncmp(input,"draw",4)==0){ // opponent offers a draw //accept with "offer draw" }else if(strncmp(input,"edit",4)==0){ //xboard wants to edit board //will send edit (enter edit mode) then c,pa4,+ or . meaning change color initially white, pawn a4 current color, # clear board, .leave edit mode then something like }else if(strncmp(input,"hint",4)==0){ //user wants a hint" }else if(strncmp(input,"undo",4)==0){ // undo move, engine switches color undoLastMove(&game->board); }else if(strncmp(input,"remove",6)==0){ // 2x undo }else if(strncmp(input,"hard",4)==0){ // enable pondering }else if(strncmp(input,"easy",4)==0){ // disable pondering }else if(strncmp(input,"post",4)==0){ // turn on thinking output }else if(strncmp(input,"nopost",6)==0){ // turn off thinking output }else if(strncmp(input,"analyze",6)==0){ // enter analyze mode }else if(strncmp(input,"print",5)==0){ printBoardE(&game->board); }else if(strncmp(input,"name",4)==0){ // name X inform engine of opponent name }else if(strncmp(input,"divide",6)==0){ divide(&game->board, (int)(input[7]-'0')); }else{ //try if is a move input e.g. //a2a3 if(input[0]>='a'&&input[0]<='h'){ if(input[1]>='1'&&input[1]<='8'){ if(input[2]>='a'&&input[2]<='h'){ if(input[3]>='1'&&input[3]<='8'){ Move move={-5}; move.from=(int)(input[0]-'a')+0x10*(7-(int)(input[1]-'1')); move.to=(int)(input[2]-'a')+0x10*(7-(int)(input[3]-'1')); if(input[4]=='q') move.promote=queen; else if(input[4]=='r') move.promote=rook; else if(input[4]=='b') move.promote=bishop; else if(input[4]=='n') move.promote=knight; if(isLegal(&game->board,&move)){ doMove(&game->board, &move); printBoardE(&game->board); return; }else{ printf("Illegal Move\n"); } } } } } } for(int i=0;i<100;i++) input[i]=' '; } } }