void play(char *position) { pieces = initPieces(position); char player = 'w'; int from, to; int legal; while(1) { if(isMate(pieces, player)) return; char *posString = createPosString(pieces); printBoard(posString); free(posString); from = -1; to = -1; legal = 0; printMoves(pieces, player); while(!legal) { readMove(&from, &to); legal = legalMove(pieces, from, to, player); char *fromSt, *toSt; if(!legal) { printf("%s %s is illegal\n", fromSt = stringPosToSquare(from), toSt = stringPosToSquare(to)); free(fromSt); free(toSt); } } movePiece(pieces, from, to); player = player == 'w' ? 'b' : 'w'; } }
QString Analysis::toString(const Board& board) const { Board testBoard = board; QString out; if (isMate()) { QString color = testBoard.toMove() == White ? "000080" : "800000"; QString text = "Mate in"; out = QString("<font color=\"#%1\"><b>%2 %3</b></font> ") .arg(color).arg(text).arg(movesToMate()); } else if (score() > 0) out = QString("<font color=\"#000080\"><b>+%1</b></font> ").arg(score() / 100.0, 0, 'f', 2); else out = QString("<font color=\"#800000\"><b>%1</b></font> ").arg(score() / 100.0, 0, 'f', 2); int moveNo = testBoard.moveNumber(); bool white = testBoard.toMove() == White; QString moveText; foreach (Move move, variation()) { if (white) moveText += QString::number(moveNo++) + ". "; else if (moveText.isEmpty()) moveText += QString::number(moveNo++) + "... "; moveText += testBoard.moveToSan(move); moveText += " "; testBoard.doMove(move); white = !white; } out += " <a href=\""+QString::number(-m_numpv)+"\" title=\"Click to add move to game\">[+]</a> "; out += " <a href=\""+QString::number(m_numpv)+"\" title=\"Click to add variation to game\">[*]</a> "; out += moveText; QTime t(0,0,0,0); t = t.addMSecs(time()); QString elapsed = t.toString("h:mm:ss"); out += tr(" (depth %1, %2)").arg(depth()).arg(elapsed); return out; }