void Board8x8::generateMoves( std::list<uint> & indexList, uint row, uint col, MoveList & moveList, bool isSlider) { for (std::list<uint>::iterator itr = indexList.begin(); itr != indexList.end(); ++itr) { uint destIndex(*itr); uint destRow = destIndex >> 3; uint destCol = destIndex & 7; PieceType otherPiece = mPieceType[destIndex]; if (otherPiece != NoPiece) { if ( (mWhiteToMove && isBlackPiece(otherPiece)) || (!mWhiteToMove && isWhitePiece(otherPiece)) ) { Move newMove(row, col, destRow, destCol, otherPiece); moveList.addMove(newMove); } if (isSlider) break; } else { Move newMove(row, col, destRow, destCol); moveList.addMove(newMove); } } }
/// \brief Initiate the ultracopier event dispatcher and check if no other session is running EventDispatcher::EventDispatcher() { copyServer=new CopyListener(&optionDialog); connect(&localListener,SIGNAL(cli(QStringList,bool,bool)),&cliParser,SLOT(cli(QStringList,bool,bool)),Qt::QueuedConnection); connect(themes, SIGNAL(newThemeOptions(QString,QWidget*,bool,bool)), &optionDialog, SLOT(newThemeOptions(QString,QWidget*,bool,bool))); connect(&cliParser, SIGNAL(newCopy(QStringList)), copyServer, SLOT(newCopy(QStringList))); connect(&cliParser, SIGNAL(newCopy(QStringList,QString)), copyServer, SLOT(newCopy(QStringList,QString))); connect(&cliParser, SIGNAL(newMove(QStringList)), copyServer, SLOT(newMove(QStringList))); connect(&cliParser, SIGNAL(newMove(QStringList,QString)), copyServer, SLOT(newMove(QStringList,QString))); copyMoveEventIdIndex=0; backgroundIcon=NULL; stopIt=false; sessionloader=new SessionLoader(&optionDialog); copyEngineList=new CopyEngineManager(&optionDialog); core=new Core(copyEngineList); qRegisterMetaType<CatchState>("CatchState"); qRegisterMetaType<ListeningState>("ListeningState"); qRegisterMetaType<QList<QUrl> >("QList<QUrl>"); qRegisterMetaType<QList<ProgressionItem> >("QList<ProgressionItem>"); qRegisterMetaType<QList<returnActionOnCopyList> >("QList<returnActionOnCopyList>"); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"start"); //show the ultracopier information ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("ULTRACOPIER_VERSION: ")+ULTRACOPIER_VERSION); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("Qt version: %1 (%2)").arg(qVersion()).arg(QT_VERSION)); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("ULTRACOPIER_PLATFORM_NAME: ")+ULTRACOPIER_PLATFORM_NAME); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("Application path: %1 (%2)").arg(QCoreApplication::applicationFilePath()).arg(QCoreApplication::applicationPid())); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,COMPILERINFO); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Information,QString("Local socket: ")+ExtraSocket::pathSocket(ULTRACOPIER_SOCKETNAME)); //To lunch some initialization after QApplication::exec() to quit eventually lunchInitFunction.setInterval(0); lunchInitFunction.setSingleShot(true); connect(&lunchInitFunction,SIGNAL(timeout()),this,SLOT(initFunction()),Qt::QueuedConnection); lunchInitFunction.start(); //add the options to use QList<QPair<QString, QVariant> > KeysList; //add the options hidden, will not show in options pannel KeysList.clear(); KeysList.append(qMakePair(QString("Last_version_used"),QVariant("na"))); KeysList.append(qMakePair(QString("ActionOnManualOpen"),QVariant(1))); KeysList.append(qMakePair(QString("GroupWindowWhen"),QVariant(0))); options->addOptionGroup("Ultracopier",KeysList); if(options->getOptionValue("Ultracopier","Last_version_used")!=QVariant("na") && options->getOptionValue("Ultracopier","Last_version_used")!=QVariant(ULTRACOPIER_VERSION)) { //then ultracopier have been updated } options->setOptionValue("Ultracopier","Last_version_used",QVariant(ULTRACOPIER_VERSION)); int a=options->getOptionValue("Ultracopier","ActionOnManualOpen").toInt(); if(a<0 || a>2) options->setOptionValue("Ultracopier","ActionOnManualOpen",QVariant(1)); a=options->getOptionValue("Ultracopier","GroupWindowWhen").toInt(); if(a<0 || a>5) options->setOptionValue("Ultracopier","GroupWindowWhen",QVariant(0)); KeysList.clear(); KeysList.append(qMakePair(QString("List"),QVariant(QStringList() << "Ultracopier-0.3"))); options->addOptionGroup("CopyEngine",KeysList); connect(&cliParser, SIGNAL(newTransferList(QString,QString,QString)),core, SLOT(newTransferList(QString,QString,QString))); }
void ServerCatchcopy::emitNewMove(quint32 client,quint32 orderId,QStringList sources,QString destination) { emit newMove(client,orderId,sources,destination); LinkGlobalToLocalClient newAssociation; newAssociation.idClient=client; newAssociation.orderId=orderId; newAssociation.globalOrderId=incrementOrderId(); LinkGlobalToLocalClientList << newAssociation; emit newMove(newAssociation.globalOrderId,sources,destination); }
/// \brief Called when event loop is setup void EventDispatcher::initFunction() { if(core==NULL || copyEngineList==NULL) { ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"Unable to initialize correctly the software"); return; } ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"Initialize the variable of event loop"); connect(copyServer, SIGNAL(newCopy(quint32,QStringList,QStringList)), core, SLOT(newCopy(quint32,QStringList,QStringList))); connect(copyServer, SIGNAL(newCopy(quint32,QStringList,QStringList,QString,QString)), core, SLOT(newCopy(quint32,QStringList,QStringList,QString,QString))); connect(copyServer, SIGNAL(newMove(quint32,QStringList,QStringList)), core, SLOT(newMove(quint32,QStringList,QStringList))); connect(copyServer, SIGNAL(newMove(quint32,QStringList,QStringList,QString,QString)), core, SLOT(newMove(quint32,QStringList,QStringList,QString,QString))); connect(core, SIGNAL(copyFinished(quint32,bool)), copyServer, SLOT(copyFinished(quint32,bool))); connect(core, SIGNAL(copyCanceled(quint32)), copyServer, SLOT(copyCanceled(quint32))); if(localListener.tryConnect()) { stopIt=true; //why before removed??? QCoreApplication::quit(); return; } localListener.listenServer(); //load the systray icon if(backgroundIcon==NULL) { backgroundIcon=new SystrayIcon(); //connect the slot //quit is for this object // connect(core, SIGNAL(newCanDoOnlyCopy(bool)), backgroundIcon, SLOT(newCanDoOnlyCopy(bool))); connect(backgroundIcon, SIGNAL(quit()),this,SLOT(quit())); //show option is for OptionEngine object connect(backgroundIcon, SIGNAL(showOptions()), &optionDialog, SLOT(show())); connect(copyServer, SIGNAL(listenerReady(ListeningState,bool,bool)), backgroundIcon, SLOT(listenerReady(ListeningState,bool,bool))); connect(copyServer, SIGNAL(pluginLoaderReady(CatchState,bool,bool)), backgroundIcon, SLOT(pluginLoaderReady(CatchState,bool,bool))); connect(backgroundIcon, SIGNAL(tryCatchCopy()), copyServer, SLOT(listen())); connect(backgroundIcon, SIGNAL(tryUncatchCopy()), copyServer, SLOT(close())); if(options->getOptionValue("CopyListener","CatchCopyAsDefault").toBool()) copyServer->listen(); ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"copyServer.oneListenerIsLoaded(): "+QString::number(copyServer->oneListenerIsLoaded())); //backgroundIcon->readyToListen(copyServer.oneListenerIsLoaded()); connect(backgroundIcon, SIGNAL(addWindowCopyMove(CopyMode,QString)), core, SLOT(addWindowCopyMove(CopyMode,QString))); connect(backgroundIcon, SIGNAL(addWindowTransfer(QString)), core, SLOT(addWindowTransfer(QString))); connect(copyEngineList, SIGNAL(addCopyEngine(QString,bool)), backgroundIcon, SLOT(addCopyEngine(QString,bool))); connect(copyEngineList, SIGNAL(removeCopyEngine(QString)), backgroundIcon, SLOT(removeCopyEngine(QString))); copyEngineList->setIsConnected(); copyServer->resendState(); } //conntect the last chance signal before quit connect(QCoreApplication::instance(),SIGNAL(aboutToQuit()),this,SLOT(quit())); //connect the slot for the help dialog connect(backgroundIcon,SIGNAL(showHelp()),&theHelp,SLOT(show())); }
void Board8x8::generateKingMoves(uint row, uint col, MoveList & moveList) { uint index = getIndex(row, col); generateMoves(mKingMoves[index], row, col, moveList, false); bool queenSide = (mWhiteToMove) ? mWhiteCastleQueenSide : mBlackCastleQueenSide; bool kingSide = (mWhiteToMove) ? mWhiteCastleKingSide : mBlackCastleKingSide; uint rowCheck = (mWhiteToMove) ? WHITE_KING_START_ROW : BLACK_KING_START_ROW; if (kingSide && getPieceType(rowCheck, 5) == NoPiece && getPieceType(rowCheck, 6) == NoPiece) { bool canCastle = true; uint attackCol = 4; while (attackCol <= 6) { if (isCellAttacked(rowCheck, attackCol, mWhiteToMove)) { canCastle = false; break; } attackCol++; } if (canCastle) { Move newMove(rowCheck, 4, rowCheck, 6); newMove.setKingCastle(); moveList.addMove(newMove); } } if (queenSide && getPieceType(rowCheck,3) == NoPiece && getPieceType(rowCheck,2) == NoPiece && getPieceType(rowCheck,1) == NoPiece) { bool canCastle = true; uint attackCol = 4; while (attackCol >= 2) { if (isCellAttacked(rowCheck, attackCol, mWhiteToMove)) { canCastle = false; break; } attackCol--; } if (canCastle) { Move newMove(rowCheck, 4, rowCheck, 2); newMove.setQueenCastle(); moveList.addMove(newMove); } } }
void ServerCatchcopy::emitNewMove(const uint32_t &client,const uint32_t &orderId,const std::vector<std::string> &sources,const std::string &destination) { LinkGlobalToLocalClient newAssociation; newAssociation.idClient=client; newAssociation.orderId=orderId; newAssociation.globalOrderId=incrementOrderId(); LinkGlobalToLocalClientList << newAssociation; emit newMove(newAssociation.globalOrderId,sources,destination); }
void CopyListener::newPluginMove(const quint32 &orderId,const QStringList &sources,const QString &destination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"sources: "+sources.join(";")+", destination: "+destination); PluginInterface_Listener *plugin = qobject_cast<PluginInterface_Listener *>(sender()); CopyRunning newCopyInformation; newCopyInformation.listenInterface = plugin; newCopyInformation.pluginOrderId = orderId; newCopyInformation.orderId = incrementOrderId(); copyRunningList << newCopyInformation; emit newMove(orderId,QStringList() << "file",stripSeparator(sources),"file",destination); }
void Connection::processData() { m_buffer = read(m_numBytesForCurrentDataType); if(m_buffer.size() != m_numBytesForCurrentDataType) { abort(); return; } switch(m_currentDataType) { case Greeting: if(m_identity == PrimaryServer || m_identity == BackupServer) { emit newClient(this); } else if(m_identity == Client) { emit newGreeting(m_buffer); } break; case Direction: if(m_identity == PrimaryServer || m_identity == BackupServer) { emit newMove(m_buffer); } break; case GameState: if(m_identity == BackupServer || m_identity == Client) { emit newState(m_buffer); } break; case SelectServer: if(m_identity == Client) { emit newBackupServer(m_buffer); } break; case Acknowledge: if(m_identity == PrimaryServer) { emit newAck(); } break; case PlayerAddr: if(m_identity == BackupServer) { emit newPlayerAddr(m_buffer); } break; default: break; } m_currentDataType = Undefined; m_numBytesForCurrentDataType = 0; m_buffer.clear(); }
/* make a new add command */ static Move *makeAdd(char* beg, char* end, Move* last) { register Move *ip; ip = newMove(DELTA_ADD,(long)(end-beg),(long)(beg-Btar),NiL); if(!ip) return 0; /* remove small previous adjacent moves */ while(last) { register int a_size, cost_m, cost_a; if(last->type == DELTA_ADD) break; cost_m = NBYTE(last->size) + NBYTE(last->addr) + NBYTE(ip->size) + ip->size; a_size = ip->size + last->size; cost_a = NBYTE(a_size) + a_size; if(cost_m < cost_a) break; ip->size = a_size; ip->addr -= last->size; last = delMove(last); } /* merge with adjacent adds */ if(last && last->type == DELTA_ADD) { ip->size += last->size; ip->addr -= last->size; last = delMove(last); } if(last) { last->next = ip; ip->last = last; } return ip; }
int main(int argc, char **argv) { newMapFile(); GtkBuilder *builder; GtkWidget *window; gtk_init (&argc, &argv); builder = gtk_builder_new (); gtk_builder_add_from_file (builder, "MoveMakerWind.glade", NULL); window = GTK_WIDGET (gtk_builder_get_object (builder, "window")); cbt_move = GTK_WIDGET(gtk_builder_get_object(builder, "cbt_move")); cbt_type = GTK_WIDGET(gtk_builder_get_object(builder, "cbt_type")); e_name = GTK_WIDGET(gtk_builder_get_object(builder, "e_name")); tv_script = GTK_WIDGET(gtk_builder_get_object(builder, "tv_script")); b_update = GTK_WIDGET(gtk_builder_get_object(builder, "b_update")); sb_pp = GTK_WIDGET(gtk_builder_get_object(builder, "sb_pp")); gtk_builder_connect_signals(builder, NULL); g_object_unref(G_OBJECT(builder)); newMove("NEW"); updateMoves(); loadTypes("../resources/data/types.pke"); toggleEditable(FALSE); gtk_widget_show(window); gtk_main(); pk_freeMoveFile(&moveFile); return 0; }
int getMovesCommands(board Game, Piece piece, Move *movesTable, Point point) { int n = 1; Move result = moveBuilder(point, piece, Game); int board_Size = boardSize(Game); int x = point->x; int y = point->y; result->command = MOVE; for (int j=-1; j<=1; j++) { for (int i=-1; i<=1; i++) { if ( (j != 0 || i != 0) && validatePoint(makePoint(x + i, y + j), board_Size)) { Piece piece1 = pieceOnPosition(Game, x + i, y + j); if (piece1 != NULL && piece1->owner == piece->owner) { continue; } constructMoveCommand(x+i, y+j, result, Game); movesTable[n] = newMove(); copyMoveData(movesTable[n], result); n++; } } } free(result); return n; }
/** new move with destination have been pased by the CLI */ void CopyListener::move(QStringList sources,QString destination) { ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,"start"); emit newMove(incrementOrderId(),QStringList() << "file",stripSeparator(sources),"file",destination); }
/* the real thing */ int delta(char* src, long n_src, char* tar, long n_tar, int delfd) { register char *sp, *tp, *esrc, *etar; register long size, addr; Suftree *tree; Move *moves, *last; char inst, buf[BUFSIZE]; /* initialize the output area */ delinit(buf,delfd); /* output file sizes */ inst = DELTA_TYPE | ((NBYTE(n_src)&07) << 3) | (NBYTE(n_tar)&07); if(delputc(inst) < 0) return -1; if(delputl(NBYTE(n_src),n_src) < 0 || delputl(NBYTE(n_tar),n_tar) < 0) return -1; /* bases */ Bsrc = src; Btar = tar; esrc = src + n_src - 1; etar = tar + n_tar - 1; /* initialize list and last block */ moves = 0; last = 0; /* try making suffix tree */ if(!(tree = n_tar > 0 ? bldsuftree(src,n_src) : (Suftree*)0)) { /* not enough space for tree, remove matching prefix and suffix */ for(; src <= esrc && tar <= etar; ++src, ++tar) if(*src != *tar) break; if((size = src-Bsrc) > 0) { register int cost_m, cost_a; cost_m = NBYTE(size) + NBYTE(0); cost_a = NBYTE(size) + size; if(cost_m < cost_a) { moves = newMove(DELTA_MOVE,size,0L,NiL); if(!moves) return -1; n_src -= src-Bsrc; n_tar -= tar-Btar; } else { src = Bsrc; tar = Btar; } } for(sp = esrc, tp = etar; sp >= src && tp >= tar; --sp, --tp) if(*sp != *tp) break; if((size = esrc-sp) > 0) { addr = sp+1-Bsrc; if(chkMove(size,addr,0L) > 0) { last = newMove(DELTA_MOVE,size,addr,NiL); if(!last) return -1; esrc = sp; etar = tp; n_tar = etar-tar+1; n_src = esrc-src+1; } } /* try making the tree again */ tree = n_tar > 0 ? bldsuftree(src,n_src) : (Suftree*)0; } /* compute block moves */ tp = 0; while(n_tar > 0) { char *match; if(tree) size = mtchsuftree(tree,tar,n_tar,&match); else size = mtchstring(src,n_src,tar,n_tar,&match); if(size < 0) return -1; if(size > 0) size = chkMove(size,(long)(match-Bsrc),(long)(tp ? tp-tar : 0)); /* output a block move */ if(size > 0) { if(tp) { moves = makeAdd(tp,tar,moves); if(!moves) return -1; tp = 0; } moves = newMove(DELTA_MOVE,size,(long)(match-Bsrc),moves); if(!moves) return -1; tar += size; n_tar -= size; } else { if(!tp) tp = tar; tar += 1; n_tar -= 1; } } /* add any remaining blocks */ if(tp) { if(last && chkMove(last->size,last->addr,(long)(tar-tp)) <= 0) { tar += last->size; last = delMove(last); } moves = makeAdd(tp,tar,moves); if(!moves) return -1; } if(last) { moves->next = last; last->last = moves; } /* release space use for string matching */ if(tree) delsuftree(tree); else mtchstring(NiL,0L,NiL,0L,NiL); /* optimize move instructions */ if(moves) { register Move *ip; ip = moves; while(ip->last) ip = ip->last; for(; ip; ip = ip->next) if(ip->type == DELTA_MOVE && ip->size <= (M_MAX+A_MAX)) moves = ip = optMove(ip); while(moves->last) moves = moves->last; } /* write out the move instructions */ addr = 0L; while(moves) { if(moves->type == DELTA_ADD) moves->addr = addr; addr += moves->size; if(putMove(moves) < 0) return -1; moves = delMove(moves); } /* write ending token */ delputc((char)DELTA_TYPE); /* flush buffer */ return delflush(); }
void Board8x8::generateBlackPawnMoves(uint row, uint col, MoveList & moveList) { static const PieceType promotedPieceTypes[] = { BlackQueen, BlackRook, BlackBishop, BlackKnight }; uint sourceIndex = getIndex(row, col); std::list<uint> listMoves = mBlackPawnMoves[sourceIndex]; for (std::list<uint>::iterator itr = listMoves.begin(); itr != listMoves.end(); ++itr) { uint destIndex(*itr); uint destRow = destIndex >> 3; uint destCol = destIndex & 7; if (row == 1) { if (col == destCol) { if (mPieceType[(row-1)*8+col] == NoPiece) { for (int i = 0; i < 4; i++) { Move promoMove(row, col, destRow, destCol, NoPiece, promotedPieceTypes[i]); moveList.addMove(promoMove); } } } else { PieceType otherPiece = mPieceType[destIndex]; if (isPiece(otherPiece) && isWhitePiece(otherPiece)) { for (int i = 0; i < 4; i++) { Move promoMove(row, col, destRow, destCol, otherPiece, promotedPieceTypes[i]); moveList.addMove(promoMove); } } } } else { if (col == destCol) { bool doublePush = false; bool singlePush = mPieceType[(row-1)*8+col] == NoPiece; if (singlePush) doublePush = mPieceType[(row-2)*8+col] == NoPiece; if ( (row-destRow) == 1 && singlePush) { Move newMove(row, col, destRow, destCol); moveList.addMove(newMove); } if ( (row-destRow) == 2 && doublePush) { Move newMove(row, col, destRow, destCol); newMove.setDoublePawnPush(); moveList.addMove(newMove); } } else { PieceType otherPiece = mPieceType[destIndex]; if (isPiece(otherPiece) && isWhitePiece(otherPiece)) { Move newMove(row, col, destRow, destCol, otherPiece); moveList.addMove(newMove); } } } } // Check en-passant if (mBlackEnPassant && row == 3) { if (col != 7) { PieceType pieceType = getPieceType(row, col+1); if (mEnPassantCaptureCol == col + 1 && pieceType == WhitePawn) { Move newMove(row, col, row-1, col+1, WhitePawn); newMove.setEnPassant(); moveList.addMove(newMove); } } if (col != 0) { PieceType pieceType = getPieceType(row, col-1); if (mEnPassantCaptureCol == col - 1 && pieceType == WhitePawn) { Move newMove(row, col, row-1, col-1, WhitePawn); newMove.setEnPassant(); moveList.addMove(newMove); } } } }
void b_newmove_clicked(GtkWidget *obj, gpointer user_data) { newMove("NEW"); updateMoves(); }
Move endTurnMove() { Move result = newMove(); result->command = END_TURN; return result; }
int getPossibleMoves(board Game, Piece piece, Move *movesTable, Point point) { int n = 0; movesTable[n] = newMove(); n++; if (piece->lastMove == currentTurn(Game)) { return n; } n = getMovesCommands(Game, piece, movesTable, point); Move result = moveBuilder(point, piece, Game); int board_Size = boardSize(Game); int x = point->x; int y = point->y; if (toupper(piece->letter) == 'C' && currentTurn(Game) - piece->lastMove >=3 ) { for (int j=-1; j<=1; j++) { for (int i=-1; i<=1; i++) { if ( (j != 0 || i != 0) && validatePoint(makePoint(x + i, y + j), board_Size) && isPositionFree(Game, x + i, y + j)) { result->xTo = x + i; result->yTo = y + j; result->isPieceRemoved= NULL; char letter = piece->letter; Piece pieceCreated = createNewPiece(piece->owner, letter, currentTurn(Game)); result->isPieceCreated = pieceCreated; result->command = PRODUCE_PEASANT; movesTable[n] = newMove(); copyMoveData(movesTable[n], result); n++; free(result->isPieceCreated); letter = matchingKnightLetter(letter); pieceCreated = createNewPiece(piece->owner, letter, currentTurn(Game) - 1); result->isPieceCreated = pieceCreated; result->command = PRODUCE_KNIGHT; movesTable[n] = newMove(); copyMoveData(movesTable[n], result); n++; free(result->isPieceCreated); } } } } free(result); return n; }