void castlemove(chess *q, int *kingloc, int *rookloc) { int *newkingloc, *newrookloc, i; newkingloc = (int *)malloc(sizeof(int) * 4); newrookloc = (int *)malloc(sizeof(int) * 4); newrookloc[3] = NOKILL; newkingloc[3] = NOKILL; newrookloc[0] = rookloc[0]; newkingloc[0] = kingloc[0]; q->p[kingloc[1]][kingloc[2]].name[0] = q->p[kingloc[1]][kingloc[2]].name[1] = '_'; q->p[kingloc[1]][kingloc[2]].status = NOSTATUS; if(kingloc[2] - rookloc[2] == 3 || kingloc[2] - rookloc[2] == -3) {/* Short castle */ newkingloc[1] = kingloc[1]; newkingloc[2] = rookloc[2] - 1; newrookloc[1] = rookloc[1]; newrookloc[2] = kingloc[2] + 1; } else {/* long castle */ newkingloc[1] = kingloc[1]; newkingloc[2] = rookloc[2] + 2; newrookloc[1] = rookloc[1]; newrookloc[2] = kingloc[2] - 1; } push(q, &q->s, kingloc, newkingloc); move1(q, kingloc, newkingloc, "no"); push(q, &q->s, rookloc, newrookloc); move1(q, rookloc, newrookloc, "castle"); q->s.tail->castle = CASTLE; free(newkingloc); free(newrookloc); }
int main() { char s[30],s1[30]; int i,j,n,x,y; while (scanf("%d",&n)!=EOF) { for (i=0; i<n; i++) { a[i].num=1; a[i].block[1]=i; postion[i]=i; } while (scanf("%s",&s)) { if (strcmp(s,"quit")==0) break; scanf("%d%s%d",&x,&s1,&y); if ((postion[x]!=postion[y])&&(x!=y)) { if ((strcmp(s,"move")==0)&&(strcmp(s1,"onto")==0)) { turnback(x); turnback(y); move1(x,y); } if ((strcmp(s,"move")==0)&&(strcmp(s1,"over")==0)) { turnback(x); move1(x,y); } if ((strcmp(s,"pile")==0)&&(strcmp(s1,"onto")==0)) { turnback(y); move2(x,y); } if ((strcmp(s,"pile")==0)&&(strcmp(s1,"over")==0)) { move2(x,y); } } } for (i=0; i<n; i++) { printf("%d:",i); for (j=1; j<=a[i].num; j++) printf(" %d",a[i].block[j]); printf("\n"); } } return 0; }
void EquipCard::use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const { if (targets.isEmpty()) { CardMoveReason reason(CardMoveReason::S_REASON_USE, source->objectName(), QString(), this->getSkillName(), QString()); room->moveCardTo(this, NULL, Player::DiscardPile, reason, true); } int equipped_id = Card::S_UNKNOWN_CARD_ID; ServerPlayer *target = targets.first(); if (target->getEquip(location())) equipped_id = target->getEquip(location())->getEffectiveId(); QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(getEffectiveId(), target, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_USE, target->objectName())); exchangeMove.push_back(move1); if (equipped_id != Card::S_UNKNOWN_CARD_ID) { CardsMoveStruct move2(equipped_id, NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName())); exchangeMove.push_back(move2); } LogMessage log; log.from = target; log.type = "$Install"; log.card_str = QString::number(getEffectiveId()); room->sendLog(log); room->moveCardsAtomic(exchangeMove, true); }
bool trigger(TriggerEvent, Room *room, ServerPlayer *player, QVariant &data) const{ PhaseChangeStruct change = data.value<PhaseChangeStruct>(); if (change.to != Player::NotActive) return false; int weapon_id = player->tag.value("DrJiedaoWeapon", -1).toInt(); player->tag["DrJiedaoWeapon"] = -1; if (!player->getWeapon() || weapon_id != player->getWeapon()->getEffectiveId()) return false; ServerPlayer *target = NULL; foreach (ServerPlayer *p, room->getOtherPlayers(player)) if (p->hasFlag("DrJiedaoTarget")) { p->setFlags("-DrJiedaoTarget"); target = p; break; } if (target == NULL) { room->throwCard(player->getWeapon(), NULL); } else { QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(player->getWeapon()->getEffectiveId(), target, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_GOTCARD, player->objectName())); exchangeMove.push_back(move1); if (target->getWeapon() != NULL) { CardsMoveStruct move2(target->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, target->objectName())); exchangeMove.push_back(move2); } room->moveCardsAtomic(exchangeMove, true); } return false; }
TEST_F(MouseControllerUnitTestBase, ShiftUnexpected) { MouseController mc(root); //处理意外情况 没有up直接leave MouseEvent down1(kET_MOUSE_DOWN, kMB_LEFT, root, Point::Make(45, 45), Point::Make(45, 45), 0); mc.handleEvent(down1); EXPECT_EQ(v31, mc.capture()); MouseEvent move1(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(29, 20), Point::Make(29, 20), 0); mc.handleEvent(move1); EXPECT_EQ(v31, mc.capture()); MouseEvent leave1(kET_MOUSE_LEAVE, kMB_NONE, root, Point::Make(45, 45), Point::Make(45, 45), 0); mc.handleEvent(leave1); EXPECT_EQ(nullptr, mc.capture()); EXPECT_EQ(nullptr, mc.over()); //当前capture 没有mouseable属性 mc.handleEvent(down1); EXPECT_EQ(v31, mc.capture()); v31->setMouseable(false); mc.handleEvent(move1); EXPECT_EQ(nullptr, mc.capture()); EXPECT_EQ(v2, mc.over()); v31->setMouseable(true); //当前capture 被remove mc.handleEvent(down1); EXPECT_EQ(v31, mc.capture()); v31->detachFromParent(); mc.handleEvent(move1); EXPECT_EQ(nullptr, mc.capture()); EXPECT_EQ(v2, mc.over()); }
int build(chess *q, tree **t, int start) { //printw("Entered build"); //getch(); tree *p; int i, k; if(q->depth >= DEPTH) { //printw("Ent if q->depth"); //getch(); push(q, &q->s, p->loc, &p->loc[4]); move1(q, p->loc, &p->loc[4], "exp"); q->depth--; k = eval(q); undoredo(q, "undowithoutredo"); return k; } inittree(t); p = *t; initmoveslist(p); generatemoves(q, p); printmlist(p); insertnodes(&p, p->ml, q->depth); if(start == 0) { start = 1; } else { push(q, &q->s, p->loc, &p->loc[4]); move1(q, p->loc, &p->loc[4], "exp"); } for(i = 0; i < p->numchildren; i++) { q->depth++; p->children[i]->score = build(q, &p->children[i], start); if((q->depth % 2) == 1) { p->score = min(p->score, p->children[i]->score); } else { p->score = max(p->score, p->children[i]->score); } } p->score = -p->score; if(p->parent == NULL) { return p->score; } undoredo(q, "undowithoutredo"); q->depth--; }
int main() { int array[6] = {1,3,6,9,13,1}; //BubbleSort(array, 6); QuickSort(array, 0, 5); printf("排序后:"); for (int i = 0; i < 6; ++i) { printf("%d ", array[i]); } printf("\n大小写分开:"); char str[7] = {'a','A','Z','d','B','s','b'}; func1(str, 0, 6); for (int i = 0; i < 7; ++i) { printf("%c ", str[i]); } printf("\n0与非0分开:"); int a[7] = {0,3,0,2,1,0,0}; move1(a, 0, 6); for (int i = 0; i < 7; ++i) { printf("%d ", a[i]); } puts(""); move2(a, 0, 6); for (int i = 0; i < 7; ++i) { printf("%d ", a[i]); } printf("\n荷兰国旗问题:"); int b[10] = {0,1,2,1,1,2,0,2,1,0}; helan(b, 0, 9); for (int i = 0; i < 10; ++i) { printf("%d ", b[i]); } printf("\n找最小的k个数:"); int c[10] = {1,87,4,5,7,5,4,98,5,0}; int k = 4; int out[4] = {0}; findMixk(c, 0, 9, 4, out); for (int i = 0; i < k; ++i) { printf("%d ", out[i]); } return 0; }
void DrJiedaoCard::onEffect(const CardEffectStruct &effect) const{ if (!effect.to->getWeapon()) return; effect.from->tag["DrJiedaoWeapon"] = effect.to->getWeapon()->getEffectiveId(); effect.to->setFlags("DrJiedaoTarget"); QList<CardsMoveStruct> exchangeMove; CardsMoveStruct move1(effect.to->getWeapon()->getEffectiveId(), effect.from, Player::PlaceEquip, CardMoveReason(CardMoveReason::S_REASON_ROB, effect.from->objectName())); exchangeMove.push_back(move1); if (effect.from->getWeapon() != NULL) { CardsMoveStruct move2(effect.from->getWeapon()->getEffectiveId(), NULL, Player::DiscardPile, CardMoveReason(CardMoveReason::S_REASON_CHANGE_EQUIP, effect.from->objectName())); exchangeMove.push_back(move2); } effect.to->getRoom()->moveCardsAtomic(exchangeMove, true); }
move() { register int *adt; if (Command[0] == 'M') { setdot1(); markpr(addr2 == dot ? addr1 - 1 : addr2 + 1); } else setdot(); nonzero(); adt = address(); if (adt == 0) error("%s where?|%s requires a trailing address", Command); newline(); move1(Command[0] != 'M', adt); killed(); }
void SistemWindowView::draw() { int viewWidth = viewMax.getX() - viewMin.getX(); int viewHeight = viewMax.getY() - viewMin.getY(); int windowWidth = windowMax.getX() - windowMin.getX(); int windowHeight = windowMax.getY() - windowMin.getY(); float ratio_x = (float)viewWidth/windowWidth; float ratio_y = (float)viewHeight/windowHeight; point move1(-windowMin.getX(),-windowMin.getY()); point move2(viewMin.getX(),viewMin.getY()); map.clip(windowMin,windowMax) .hasilGeser(move1) .hasilSkala(ratio_x,ratio_y) .hasilGeser(move2).draw(); drawMinimap(); }
int main(int argc, char* argv[]) { std::cout << "Inicio de la secuencia de borrado de puntero\n"; // Uso de RAII para dar ambito a la clase autoBorra { borraPuntero<std::string> point; std::cout << "Se ha creado el puntero al instanciar la clase\n"; } std::cout << "Se ha salido del ambito de la clase y el puntero se ha borrado por el destructor de la clase.\n\n"; std::string cadena1 = "Texto1"; std::string cadena2 = "Texto2"; cortaPega move1(cadena1); move1.posicionMemoria(); cortaPega move2 = std::move(move1); move2.posicionMemoria(); return 0; }
void compmove(chess *q) { //printw("Entered compmove"); //getch(); int score, i; q->depth = 0; score = build(q, &q->t, 0); for(i = 0; i < q->t->numchildren; i++) { if(q->t->children[i]->score == score) { break; } } display(stdscr, q); getch(); push(q, &q->s, q->t->children[i]->loc, &q->t->children[i]->loc[4]); move1(q, q->t->children[i]->loc, &q->t->children[i]->loc[4], "no"); free(q->t); printw("Returned from compmove"); getch(); }
TEST_F(MouseControllerUnitTestBase, ShiftCapture) { MouseController mc(root); EXPECT_EQ(nullptr, mc.capture()); MouseEvent down1(kET_MOUSE_DOWN, kMB_LEFT, root, Point::Make(45, 45), Point::Make(45, 45), 0); mc.handleEvent(down1); EXPECT_EQ(v31, mc.capture()); MouseEvent move1(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(29, 20), Point::Make(29, 20), 0); mc.handleEvent(move1); EXPECT_EQ(v31, mc.capture()); EXPECT_EQ(v31, mc.over()); MouseEvent up1(kET_MOUSE_UP, kMB_LEFT, root, Point::Make(29, 20), Point::Make(29, 20), 0); mc.handleEvent(up1); EXPECT_EQ(nullptr, mc.capture()); //鼠标弹起后 要切换over EXPECT_EQ(v2, mc.over()); }
TEST_F(MouseControllerUnitTestBase, ShiftOver) {//测试over MouseController mc(root); EXPECT_EQ(nullptr, mc.over()); MouseEvent move(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(80, 80), Point::Make(80, 80), 0); mc.handleEvent(move); EXPECT_EQ(nullptr, mc.over()); MouseEvent move1(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(29, 20), Point::Make(29, 20), 0); mc.handleEvent(move1); EXPECT_EQ(v2, mc.over()); MouseEvent move2(kET_MOUSE_MOVE, kMB_NONE, root, Point::Make(45, 45), Point::Make(45, 45), 0); mc.handleEvent(move2); EXPECT_EQ(v31, mc.over()); v31->setMouseable(false); mc.handleEvent(move2); EXPECT_NE(v31, mc.over()); }
void keyboard (unsigned char key, int x, int y) { switch (key) { case 'f': day = (day + 10) % 360; glutPostRedisplay(); break; case 'F': day = (day - 10) % 360; glutPostRedisplay(); break; case 'y': year = (year + 5) % 360; glutPostRedisplay(); break; case 'Y': year = (year - 5) % 360; glutPostRedisplay(); break; case 'l': light_angle+=2.0/90; // if(light_position1>1.0)light_position1=0.0; glutPostRedisplay(); break; case 'L': light_angle-=2.0/90; // if(light_position1>1.0)light_position1=0.0; glutPostRedisplay(); break; case 'k': cam_radius+=0.2; cPosition(); glutPostRedisplay(); /*glLoadIdentity(); camera_position+=0.1; gluLookAt(camera_position,camera_position, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);*/ glutPostRedisplay(); break; case 'K': cam_radius-=0.2; cPosition(); glutPostRedisplay(); /*glLoadIdentity(); camera_position-=0.1; gluLookAt(camera_position,camera_position, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);*/ glutPostRedisplay(); break; case'w': cam_angle_v+=1.0/30; if(cam_angle_v>1.0) { cam_angle_v=1.0; } cPosition(); glutPostRedisplay(); break; case's': cam_angle_v-=1.0/30; if(cam_angle_v<-1.0) { cam_angle_v=-1.0; } cPosition(); glutPostRedisplay(); break; case'a': cam_angle_u+=1.0/30; cPosition(); glutPostRedisplay(); break; case'd': cam_angle_u-=1.0/30; cPosition(); glutPostRedisplay(); break; case'r': cam_radius=5.0; cam_angle_u=0; cam_angle_v=0; cPosition(); glutPostRedisplay(); break; case'q': move(); glutPostRedisplay(); break; case'Q': move1(); glutPostRedisplay(); break; case 27: exit(0); break; default: break; } }
void undo(char c) { register int i, *jp, *kp; int *dolp1, *newdol, *newadot; if (inglobal) error("Can't undo in global@commands"); if (!c) somechange(); change(); if (undkind == UNDMOVE) { /* * Command to be undone is a move command. * This is handled as a special case by noting that * a move "a,b m c" can be inverted by another move. */ if ((i = (jp = unddel) - undap2) > 0) { /* * when c > b inverse is a+(c-b),c m a-1 */ addr2 = jp; addr1 = (jp = undap1) + i; unddel = jp-1; } else { /* * when b > c inverse is c+1,c+1+(b-a) m b */ addr1 = ++jp; addr2 = jp + ((unddel = undap2) - undap1); } kp = undap1; move1(0, unddel); dot = kp; Command = "move"; killed(); } else { int cnt; newadot = dot; cnt = dol - zero; newdol = dol; dolp1 = dol + 1; /* * Command to be undone is a non-move. * All such commands are treated as a combination of * a delete command and a append command. * We first move the lines appended by the last command * from undap1 to undap2-1 so that they are just before the * saved deleted lines. */ if ((i = (kp = undap2) - (jp = undap1)) > 0) { reverse(jp, kp); reverse(kp, dolp1); reverse(jp, dolp1); /* * Account for possible backward motion of target * for restoration of saved deleted lines. */ if (unddel >= jp) unddel -= i; newdol -= i; /* * For the case where no lines are restored, dot * is the line before the first line deleted. */ dot = jp-1; } /* * Now put the deleted lines, if any, back where they were. * Basic operation is: dol+1,unddol m unddel */ jp = unddel + 1; if ((i = (kp = unddol) - dol) > 0) { if (jp != dolp1) { reverse(jp, dolp1); reverse(dolp1, ++kp); reverse(jp, kp); } /* * Account for possible forward motion of the target * for restoration of the deleted lines. */ if (undap1 >= jp) undap1 += i; /* * Dot is the first resurrected line. */ dot = jp; newdol += i; } /* * Clean up so we are invertible */ unddel = undap1 - 1; undap1 = jp; undap2 = jp + i; dol = newdol; netchHAD(cnt); if (undkind == UNDALL) { dot = undadot; undadot = newadot; } } if (dot == zero && dot != dol) dot = one; }