int ConsoleGame::run() { // std::string cmdString("4"); // std::istringstream iss(cmdString); // handlePerft(iss); // return 0; while (true) { std::cout << "\nsc: "; std::string inputString; std::getline(std::cin, inputString); std::istringstream iss(inputString); std::string commandString; iss >> commandString; if (commandString.empty()) continue; if (commandString == "quit") break; else if (commandString == "divide") handleDivide(iss); else if (commandString == "help") handleHelp(); else if (commandString == "print") handlePrint(); else if (commandString == "disp") handlePrint(); else if (commandString == "fen") handleFen(); else if (commandString == "perft") handlePerft(iss); // else if (commandString == "table") // handleTable(iss); else if (commandString == "move") handleMove(iss); else if (commandString == "setboard") handleSetBoard(iss); else if (commandString == "testmovegen") handleTestMoveGen(); else if (commandString == "new") handleNewGame(); else if (commandString == "show") handleShow(); else if (commandString == "undo") handleUndo(); else if (commandString == "twoplayer") handleTwoPlayer(); else if (commandString == "singleplayer") handleSinglePlayer(); else { std::cout << "Unrecognized command " << commandString << "\n"; std::cout << "Type help to show command list\n"; } } return 0; }
/** * Entry function which will process the assembled code and perform the required actions */ void processAssembledCode(char * assembled, unsigned int length, unsigned short numberSymbols, int coreId, int numberActiveCores, int baseHostPid) { stopInterpreter=0; currentSymbolEntries=0; localCoreId=coreId; numActiveCores=numberActiveCores; symbolTable=initialiseSymbolTable(numberSymbols); hostCoresBasePid=baseHostPid; unsigned int i; for (i=0;i<length;) { unsigned short command=getUShort(&assembled[i]); i+=sizeof(unsigned short); if (command == LET_TOKEN) i=handleLet(assembled, i); if (command == ARRAYSET_TOKEN) i=handleArraySet(assembled, i); if (command == DIMARRAY_TOKEN) i=handleDimArray(assembled, i, 0); if (command == DIMSHAREDARRAY_TOKEN) i=handleDimArray(assembled, i, 1); if (command == PRINT_TOKEN) i=handlePrint(assembled, i); if (command == STOP_TOKEN) return; if (command == SYNC_TOKEN) i=handleSync(assembled, i); if (command == IF_TOKEN) i=handleIf(assembled, i); if (command == IFELSE_TOKEN) i=handleIf(assembled, i); if (command == FOR_TOKEN) i=handleFor(assembled, i); if (command == GOTO_TOKEN) i=handleGoto(assembled, i); if (command == INPUT_TOKEN) i=handleInput(assembled, i); if (command == INPUT_STRING_TOKEN) i=handleInputWithString(assembled, i); if (command == SEND_TOKEN) i=handleSend(assembled, i); if (command == RECV_TOKEN) i=handleRecv(assembled, i); if (command == RECVTOARRAY_TOKEN) i=handleRecvToArray(assembled, i); if (command == SENDRECV_TOKEN) i=handleSendRecv(assembled, i); if (command == SENDRECVARRAY_TOKEN) i=handleSendRecvArray(assembled, i); if (command == BCAST_TOKEN) i=handleBcast(assembled, i); if (command == REDUCTION_TOKEN) i=handleReduction(assembled, i); if (stopInterpreter) return; } }
void ConsoleGame::handleMove(std::istringstream & iss) { static std::map<char, int> columnMap, rowMap; if (columnMap.size() == 0) { columnMap['a'] = 0; columnMap['b'] = 1; columnMap['c'] = 2; columnMap['d'] = 3; columnMap['e'] = 4; columnMap['f'] = 5; columnMap['g'] = 6; columnMap['h'] = 7; rowMap['1'] = 0; rowMap['2'] = 1; rowMap['3'] = 2; rowMap['4'] = 3; rowMap['5'] = 4; rowMap['6'] = 5; rowMap['7'] = 6; rowMap['8'] = 7; } if (isGameOver()) { std::cout << "The game is over. Type new to start a new game\n"; return; } std::string moveString; iss >> moveString; if (moveString.empty()) { std::cout << "A move string must be provided\n"; return; } if (moveString.find_first_not_of("123456789abcdefghpnbrqkEcCNBRQ") != std::string::npos) { std::cout << "Invalid move string " << moveString << "\n"; return; } if (moveString.length() < 4) { std::cout << "Invalid move string " << moveString << "\n"; return; } int srcCol = columnMap[moveString.at(0)]; int srcRow = rowMap[moveString.at(1)]; int dstCol = columnMap[moveString.at(2)]; int dstRow = rowMap[moveString.at(3)]; uchar moveIndex = 0; bool moveFound = false; MoveList moveList; uchar totalMoves = mBoard->generateMoves(moveList); for (uchar i = 0; i < totalMoves; i++) { Move move = moveList[i]; uchar sourceRow = move.sourceRow; uchar sourceCol = move.sourceCol; uchar destRow = move.destRow; uchar destCol = move.destCol; if (srcRow == sourceRow && dstRow == destRow && srcCol == sourceCol && dstCol == destCol) { moveIndex = i; moveFound = true; break; } } if (!moveFound) { std::cout << "Sorry " << moveString << " is not a valid move\n"; for (uint i = 0; i < totalMoves; i++) std::cout << getSmithNotation(moveList[i]) << "\n"; return; } doMove(moveList[moveIndex]); if (isGameOver()) { showEndGame(); return; } bool doEngineMove = false; // if (gameType() == HumanVsComputer && !isWhiteToMove()) // doEngineMove = true; // if (gameType() == ComputerVsHuman && isWhiteToMove()) // doEngineMove = true; if (doEngineMove) { executeEngineMove(); handlePrint(); if (isGameOver()) { showEndGame(); } } }
PropertiesPalette_XYZ::PropertiesPalette_XYZ( QWidget* parent) : QWidget(parent) { m_ScMW=0; m_doc=0; m_haveDoc = false; m_haveItem = false; m_lineMode = false; m_oldRotation = 0; m_unitRatio = 1.0; setupUi(this); setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); _userActionOn = false; userActionSniffer = new UserActionSniffer(this); connect(userActionSniffer, SIGNAL(actionStart()), this, SLOT(spinboxStartUserAction())); connect(userActionSniffer, SIGNAL(actionEnd()), this, SLOT(spinboxFinishUserAction())); nameEdit->setFocusPolicy(Qt::ClickFocus); installSniffer(xposSpin); installSniffer(yposSpin); installSniffer(widthSpin); installSniffer(heightSpin); xposLabel->setBuddy(xposSpin); yposLabel->setBuddy(yposSpin); widthLabel->setBuddy(widthSpin); heightLabel->setBuddy(heightSpin); keepFrameWHRatioButton->setCheckable( true ); keepFrameWHRatioButton->setAutoRaise( true ); keepFrameWHRatioButton->setMaximumSize( QSize( 15, 32767 ) ); keepFrameWHRatioButton->setChecked(false); rotationSpin->setWrapping( true ); installSniffer(rotationSpin); rotationSpin->setNewUnit(6); rotationLabel->setBuddy(rotationSpin); levelUp->setIcon(QIcon(loadIcon("16/go-up.png"))); levelDown->setIcon(QIcon(loadIcon("16/go-down.png"))); levelTop->setIcon(QIcon(loadIcon("16/go-top.png"))); levelBottom->setIcon(QIcon(loadIcon("16/go-bottom.png"))); levelLabel->setAlignment( Qt::AlignCenter ); doGroup->setIcon(QIcon(loadIcon("group.png"))); doUnGroup->setIcon(QIcon(loadIcon("ungroup.png"))); flipH->setIcon(QIcon(loadIcon("16/flip-object-horizontal.png"))); flipH->setCheckable( true ); flipV->setIcon(QIcon(loadIcon("16/flip-object-vertical.png"))); flipV->setCheckable( true ); doLock->setCheckable( true ); QIcon a = QIcon(); a.addPixmap(loadIcon("16/lock.png"), QIcon::Normal, QIcon::On); a.addPixmap(loadIcon("16/lock-unlocked.png"), QIcon::Normal, QIcon::Off); doLock->setIcon(a); noPrint->setCheckable( true ); QIcon a2 = QIcon(); a2.addPixmap(loadIcon("NoPrint.png"), QIcon::Normal, QIcon::On); a2.addPixmap(loadIcon("16/document-print.png"), QIcon::Normal, QIcon::Off); noPrint->setIcon(a2); noResize->setCheckable( true ); QIcon a3 = QIcon(); a3.addPixmap(loadIcon("framenoresize.png"), QIcon::Normal, QIcon::On); a3.addPixmap(loadIcon("frameresize.png"), QIcon::Normal, QIcon::Off); noResize->setIcon(a3); m_lineMode = false; languageChange(); connect(xposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewX())); connect(yposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewY())); connect(widthSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewW())); connect(heightSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewH())); connect(rotationSpin, SIGNAL(valueChanged(double)), this, SLOT(handleRotation())); connect(flipH, SIGNAL(clicked()), this, SLOT(handleFlipH())); connect(flipV, SIGNAL(clicked()), this, SLOT(handleFlipV())); connect(levelUp, SIGNAL(clicked()), this, SLOT(handleRaise())); connect(levelDown, SIGNAL(clicked()), this, SLOT(handleLower())); connect(levelTop, SIGNAL(clicked()), this, SLOT(handleFront())); connect(levelBottom, SIGNAL(clicked()), this, SLOT(handleBack())); connect(basePointWidget, SIGNAL(buttonClicked(int)), this, SLOT(handleBasePoint(int))); connect(nameEdit , SIGNAL(Leaved()) , this, SLOT(handleNewName())); connect(doLock , SIGNAL(clicked()), this, SLOT(handleLock())); connect(noPrint , SIGNAL(clicked()), this, SLOT(handlePrint())); connect(noResize , SIGNAL(clicked()), this, SLOT(handleLockSize())); connect(doGroup , SIGNAL(clicked()), this, SLOT(handleGrouping()) ); connect(doUnGroup, SIGNAL(clicked()), this, SLOT(handleUngrouping()) ); m_haveItem = false; xposSpin->showValue(0); yposSpin->showValue(0); widthSpin->showValue(0); heightSpin->showValue(0); rotationSpin->showValue(0); }
void PropertiesPalette_XYZ::setCurrentItem(PageItem *i) { if (!m_ScMW || m_ScMW->scriptIsRunning()) return; //CB We shouldnt really need to process this if our item is the same one //maybe we do if the item has been changed by scripter.. but that should probably //set some status if so. //FIXME: This wont work until when a canvas deselect happens, m_item must be NULL. //if (m_item == i) // return; if (!m_doc) setDoc(i->doc()); disconnect(nameEdit, SIGNAL(Leaved()), this, SLOT(handleNewName())); m_haveItem = false; m_item = i; nameEdit->setText(m_item->itemName()); QString tm; levelLabel->setText(tm.setNum(m_item->ItemNr + 1)); connect(nameEdit, SIGNAL(Leaved()), this, SLOT(handleNewName())); //CB replaces old emits from PageItem::emitAllToGUI() disconnect(xposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewX())); disconnect(yposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewY())); disconnect(widthSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewW())); disconnect(heightSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewH())); disconnect(doLock, SIGNAL(clicked()), this, SLOT(handleLock())); disconnect(noPrint, SIGNAL(clicked()), this, SLOT(handlePrint())); disconnect(noResize, SIGNAL(clicked()), this, SLOT(handleLockSize())); disconnect(flipH, SIGNAL(clicked()), this, SLOT(handleFlipH())); disconnect(flipV, SIGNAL(clicked()), this, SLOT(handleFlipV())); disconnect(rotationSpin, SIGNAL(valueChanged(double)), this, SLOT(handleRotation())); double selX = m_item->xPos(); double selY = m_item->yPos(); double selW = m_item->width(); double selH = m_item->height(); if (m_doc->m_Selection->count() > 1) m_doc->m_Selection->getGroupRect(&selX, &selY, &selW, &selH); displayXY(selX, selY); displayWH(selW, selH); bool checkableFlip = (i->isImageFrame() || i->isTextFrame() || i->isLatexFrame() || i->isOSGFrame() || i->isSymbol() || i->isGroup() || i->isSpiral()); flipH->setCheckable(checkableFlip); flipV->setCheckable(checkableFlip); noPrint->setChecked(!i->printEnabled()); displayFlippedH(i->imageFlippedH()); displayFlippedV(i->imageFlippedV()); m_oldRotation = i->rotation(); double rr = i->rotation(); if (i->rotation() > 0) rr = 360 - rr; rotationSpin->setValue(fabs(rr)); //CB TODO reconnect PP signals from here connect(xposSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewX())); connect(yposSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewY())); connect(widthSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewW())); connect(heightSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewH())); connect(doLock , SIGNAL(clicked()), this, SLOT(handleLock())); connect(noPrint , SIGNAL(clicked()), this, SLOT(handlePrint())); connect(noResize, SIGNAL(clicked()), this, SLOT(handleLockSize())); connect(flipH , SIGNAL(clicked()), this, SLOT(handleFlipH())); connect(flipV , SIGNAL(clicked()), this, SLOT(handleFlipV())); connect(rotationSpin, SIGNAL(valueChanged(double)), this, SLOT(handleRotation())); bool setter = false; if ((m_item->isTableItem) && (m_item->isSingleSel)) { setter = true; rotationSpin->setEnabled(false); } xposSpin->setEnabled(!setter); yposSpin->setEnabled(!setter); levelGroup->setEnabled(!setter); if ((m_item->isGroup()) && (!m_item->isSingleSel)) { setEnabled(true); } if ((m_item->itemType() == PageItem::Line) && m_lineMode) { xposLabel->setText( tr( "&X1:" ) ); widthLabel->setText( tr( "X&2:" ) ); yposLabel->setText( tr( "Y&1:" ) ); heightLabel->setText( tr( "&Y2:" ) ); rotationSpin->setEnabled(false); } else { xposLabel->setText( tr( "&X-Pos:" ) ); widthLabel->setText( tr( "&Width" ) ); yposLabel->setText( tr( "&Y-Pos:" ) ); heightLabel->setText( tr( "&Height:" ) ); rotationSpin->setEnabled(!((m_item->isTableItem) && (m_item->isSingleSel))); } m_haveItem = true; if (m_item->asLine()) { keepFrameWHRatioButton->setEnabled(false); heightSpin->setEnabled(m_lineMode && !m_item->locked()); } else { heightSpin->setEnabled(true); keepFrameWHRatioButton->setEnabled(true); } displayXY(selX, selY); displayWH(selW, selH); displayLocked(i->locked()); displaySizeLocked(i->sizeLocked()); double rrR = i->imageRotation(); if (i->imageRotation() > 0) rrR = 360 - rrR; noResize->setEnabled(!m_item->isArc()); doGroup->setEnabled(false); doUnGroup->setEnabled(false); if (m_doc->m_Selection->count() > 1) doGroup->setEnabled(true); if (m_doc->m_Selection->count() == 1) doUnGroup->setEnabled(m_item->isGroup()); if (m_item->asOSGFrame()) { setEnabled(true); rotationSpin->setEnabled(false); } if (m_item->asSymbolFrame()) { setEnabled(true); } updateSpinBoxConstants(); }