bool isHappy(int n) { while (n != 1) { n = crazy(n); if (n == 4) { return false; } } return true; }
void ChessLegalityTest::test_movements() { ChessMove e4(Point(4, 6), Point(4, 4)); CPPUNIT_ASSERT_EQUAL(ChessMove::EN_PASSANT_TRIGGER, m_legality_check->getMoveType( m_state->board().get(Point(4, 6)), e4)); ChessMove crazy(Point(0, 0), Point(7, 4)); CPPUNIT_ASSERT_EQUAL(ChessMove::INVALID, m_legality_check->getMoveType( m_state->board().get(Point(0, 0)), crazy)); }
int QAbstractMalbolgeRunner::load_malbolge_program(QString filename) { this->clear_output_buffer(false); QFile file(filename); if(!file.open(QIODevice::ReadOnly)) { this->err(QString("Cannot open file ").append(filename).append(": ").append(file.errorString()).append("\n")); return -1; } QTextStream in(&file); a=0; c=0; d=0; while (!in.atEnd() && d < 59050){ unsigned int instr; memory[d] = 0; QString result = in.read(1); if (result.length() > 1) return -1; if (result.length() == 0) break; memory[d] = result.toUtf8().at(0); if (memory[d] == 0x1a || memory[d] == 0x04) break; instr = (memory[d] + d)%94; if (memory[d]==' ' || memory[d] == '\t' || memory[d] == '\r' || memory[d] == '\n'); else if (memory[d] >= 33 && memory[d] < 127 && (instr == 4 || instr == 5 || instr == 23 || instr == 39 || instr == 40 || instr == 62 || instr == 68 || instr == 81)) d+=result.length(); else{ this->err(QString("Invalid character %1 at %2.\n").arg(memory[d]).arg(d)); return -1; //invalid characters are not accepted. //that makes the "hacked" in-out-program unrunnable } } file.close(); if (d == 59050) { this->err("Maximum program length of 59049 exceeded.\n"); return -1; } if (d < 2) { this->err("Minimal program length of 2 deceeded.\n"); return -1; } while (d < 59049){ memory[d] = crazy(memory[d-1], memory[d-2]); d++; } d = 0; return 0; }
int QAbstractMalbolgeRunner::execute_malbolge_step(int &executed_command) { int instruction = get_instruction(memory[c],c); if (instruction < 0) { this->err(QString("Invalid command %1 at %2.\n").arg(memory[c]).arg(c)); return -1; } executed_command = instruction; switch (instruction){ case MALBOLGE_JMP: c = memory[d]; break; case MALBOLGE_OUT: { this->char_out((char)a); } break; case MALBOLGE_IN: { char read = 0; bool result = this->in(read, &abort_reading_flag); a = (int)((unsigned char)read); if (!result) a = 59048; } break; case MALBOLGE_ROT: a = (memory[d] = rotateR(memory[d])); break; case MALBOLGE_MOVD: d = memory[d]; break; case MALBOLGE_OPR: a = (memory[d] = crazy(a, memory[d])); break; case MALBOLGE_HALT: return 1; case MALBOLGE_NOP: default: break; } translate(memory[c]); c = (c+1)%59049; d = (d+1)%59049; return 0; }
void ChessLegalityTest::test_pseudolegal() { ChessMove e4(Point(4, 6), Point(4, 4)); CPPUNIT_ASSERT(m_legality_check->pseudolegal(e4)); ChessMove e5(Point(4, 6), Point(4, 3)); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(e5)); ChessMove Nf3(Point(6, 7), Point(5, 5)); CPPUNIT_ASSERT(m_legality_check->pseudolegal(Nf3)); ChessMove Bc4(Point(5, 7), Point(2, 4)); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(Bc4)); // black moves m_state->switchTurn(); ChessMove crazy(Point(0, 0), Point(4, 7)); CPPUNIT_ASSERT(!m_legality_check->pseudolegal(crazy)); ChessMove e5_(Point(4, 1), Point(4, 3)); CPPUNIT_ASSERT(m_legality_check->pseudolegal(e5_)); }
void xRinexEphemerisStore :: BCESfindEphTest (void) { ofstream fPRN1; ofstream fPRN15; ofstream fPRN32; fPRN1.open ("Logs/findEph1.txt"); fPRN15.open ("Logs/findEph15.txt"); fPRN32.open ("Logs/findEph32.txt"); gpstk::Rinex3EphemerisStore Store; Store.loadFile("TestRinex06.031"); std::list<gpstk::Rinex3NavData> R3NList; gpstk::GPSEphemerisStore GStore; std::list<gpstk::Rinex3NavData>::const_iterator it; Store.addToList(R3NList); for (it = R3NList.begin(); it != R3NList.end(); ++it) GStore.addEphemeris(gpstk::EngEphemeris(*it)); // debug dump of GStore //ofstream GDumpData; //GDumpData.open("GDumpData.txt"); //GStore.dump(GDumpData,1); const short PRN0 = 0; // Zero PRN (Border test case) const short PRN1 = 1; const short PRN15 = 15; const short PRN32 = 32; const short PRN33 = 33; //Top PRN (33) (Border test case); const gpstk::SatID sid0(PRN0,gpstk::SatID::systemGPS); const gpstk::SatID sid1(PRN1,gpstk::SatID::systemGPS); const gpstk::SatID sid15(PRN15,gpstk::SatID::systemGPS); const gpstk::SatID sid32(PRN32,gpstk::SatID::systemGPS); const gpstk::SatID sid33(PRN33,gpstk::SatID::systemGPS); gpstk::CivilTime Time(2006,1,31,11,45,0,2); gpstk::CivilTime bTime(2006,1,31,2,0,0,2); //Border Time (Time of Border test cases) const gpstk::CommonTime ComTime = (gpstk::CommonTime)Time; const gpstk::CommonTime CombTime = (gpstk::CommonTime)bTime; try { gpstk::CivilTime crazy(1950,1,31,2,0,0,2); const gpstk::CommonTime Comcrazy = (gpstk::CommonTime)crazy; CPPUNIT_ASSERT_NO_THROW(GStore.findEphemeris(sid1,ComTime)); fPRN1 << GStore.findEphemeris(sid1,ComTime); fPRN15 << GStore.findEphemeris(sid15,ComTime); fPRN32 << GStore.findEphemeris(sid32,ComTime); CPPUNIT_ASSERT_THROW(GStore.findEphemeris(sid0,CombTime),gpstk::InvalidRequest); CPPUNIT_ASSERT_THROW(GStore.findEphemeris(sid33,CombTime),gpstk::InvalidRequest); CPPUNIT_ASSERT_THROW(GStore.findEphemeris(sid32,Comcrazy),gpstk::InvalidRequest); } catch (gpstk::Exception& e) { //cout << e; } CPPUNIT_ASSERT(fileEqualTest((char*)"Logs/findEph1.txt",(char*)"Checks/findEph1.chk")); CPPUNIT_ASSERT(fileEqualTest((char*)"Logs/findEph15.txt",(char*)"Checks/findEph15.chk")); CPPUNIT_ASSERT(fileEqualTest((char*)"Logs/findEph32.txt",(char*)"Checks/findEph32.chk")); }
int DiffSet::Run(sf::RenderWindow &window) { //basic stuff running = true; IOdiff diff; selection = diff.ReadDiffSettings(); Background bg("graphics//core//settings.jpg"); //Sound IOsound iosound; iosound.ReadSoundSettings(volume); MenuSound sound; sound.LoadSoundBuffer(); sound.setBuffer(volume); //buttons Text easy("easy", 70), normal("normal", 70), crazy("crazy", 70), info("enter = save, esc = back", 40); easy.setPosition(270, 150); normal.setPosition(270, 250); crazy.setPosition(270, 350); info.setPosition(50, 500); info.setColor(sf::Color(255, 128, 0)); while (running) { while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { return -1; } //keyboard selection if (event.type == sf::Event::KeyPressed) { switch (event.key.code) { case sf::Keyboard::Up: if (selection > 1) { selection -= 1; sound.PlaySound("select"); } else { selection = 1; } break; case sf::Keyboard::Down: if (selection < 3) { selection += 1; sound.PlaySound("select"); } else { selection = 3; } break; case sf::Keyboard::Return: diff.WriteDiffSettings(selection); return 2; break; case sf::Keyboard::Escape: return 2; break; default: break; } } } //change the color depending on selection if (selection == 1)//easy { easy.setColor(sf::Color(255, 128, 0)); normal.setColor(sf::Color(255, 255, 255)); crazy.setColor(sf::Color(255, 255, 255)); } else if (selection == 2)//normal { easy.setColor(sf::Color(255, 255, 255)); normal.setColor(sf::Color(255, 128, 0)); crazy.setColor(sf::Color(255, 255, 255)); } else //crazy { easy.setColor(sf::Color(255, 255, 255)); normal.setColor(sf::Color(255, 255, 255)); crazy.setColor(sf::Color(255, 128, 0)); } //draw stuff window.clear(); bg.Render(window); easy.Render(window); normal.Render(window); crazy.Render(window); info.Render(window); window.display(); } return -1; }