void LoadEPD (char *p) /************************************************************************** * * This routine reads in the next or the Nth position in the file. * **************************************************************************/ { char file[MAXSTR]; int N = 1; sscanf (p, "%127s %d ", file, &N); if (strcmp (file, "next") == 0) { ReadEPDFile (file, 0); } else { ReadEPDFile (file, 1); while (--N) { if (ReadEPDFile (file, 2) == false) { printf ("File position exceeded\n"); return; } } ReadEPDFile (file, 0); } ShowBoard (); NewPosition (); }
bool Player::isCollision(Direction direction) { char graphicAtNewPos; Position NewPosition(pos); switch (direction) { case Up: NewPosition.y--; graphicAtNewPos=Game::display.GetPos(pos); return (graphicAtNewPos == snakeGraphic_); case Down: NewPosition.y++; graphicAtNewPos=Game::display.GetPos(pos); return(graphicAtNewPos == snakeGraphic_); case Left: NewPosition.x--; graphicAtNewPos=Game::display.GetPos(pos); return (graphicAtNewPos == snakeGraphic_); case Right: NewPosition.x++; graphicAtNewPos=Game::display.GetPos(pos); return (graphicAtNewPos == snakeGraphic_); default: return true; } }
bool System::newStepMetropolis() { int i, j; double wf_new, wf_old; // taking a new, random step for (i=0; i<NumberOfParticles; i++) { for (j=0; j<NumberOfDimensions; j++) { NewPosition(i,j) = OldPosition(i,j)+StepLength*(ran0(&RandomSeed)-0.5); } } // calculating new wave-function wf_new = Wavefunction->evaluateWavefunction(NewPosition); wf_old = Wavefunction->getOldWavefunction(); // metropolis test: if(ran0(&RandomSeed) <= (wf_new*wf_new)/(wf_old*wf_old)) // STEP ACCEPTED { OldPosition = NewPosition; Wavefunction->setOldWavefunction(wf_new); return true; } else // STEP REFUSED { return false; } }
/* ----------------------------------------------------------------------- */ int main(int argc, char *argv[]) { Loc x(1); Loc y(5); Direction dir(0); char *ratName; signal(SIGHUP, quit); signal(SIGINT, quit); signal(SIGTERM, quit); struct timeval zero; struct timeval now; gettimeofday(&now, NULL); start_time = time_diff(now, zero); getName("Welcome to CS244B MazeWar!\n\nYour Name", &ratName); ratName[strlen(ratName)-1] = 0; M = MazewarInstance::mazewarInstanceNew(string(ratName)); MazewarInstance* a = M.ptr(); strncpy(M->myName_, ratName, NAMESIZE); free(ratName); MazeInit(argc, argv); NewPosition(M); play(); return 0; }
void cmd_new(void) { InitVars (); NewPosition (); /* Protocol specification for ANALYZE says "new" does not end analysis */ if (!(flags & ANALYZE)) CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; SetDataToEngine( token[0] ); }
hgeVector c_gameobject::GetNewPosition_Tilt(hgeRect BoundingBox1, hgeRect BoundingBox2, int tilt_type, int tilt_level, int tilt_number) { hgeVector A = PreviousPosition; hgeVector B = Position; hgeVector C; hgeVector NewPosition(0, 0); hgeVector SwapPosition; c_bool PointUnderLine; c_bool A_coef_negative, B_coef_negative; c_bool A_coef_zero, B_coef_zero; c_bool Y_fixed; return NewPosition; }
BOOL SearchAgain(WORD Flags) /*Flags: 1=Reverse (search in opposite direction) * 2=pop up dialog if not searched before */ { BOOL Return; ULONG OldLength; HideEditCaret(); if (Flags & 2 && !MatchValid) { SearchDialog(); return (TRUE); } OldLength = SelectCount; if (OldLength) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)((Flags & 1) | 2)); if (Return) { if ((OldLength==0 && Mode!=InsertMode) || ComparePos(&SelectStart, &CurrPos) == 0) { if (CountBytes(&EndMatch) - CountBytes(&StartPos) == OldLength) { SelectStart = CurrPos; Return = SearchAndStatus(&SelectStart, (WORD)(Flags & 1)); } } if (Return) { NewPosition(&SelectStart); UpdateWindow(hwndMain); SelectStart = StartPos; SelectBytePos = CountBytes(&StartPos); SelectCount = CountBytes(&EndMatch) - SelectBytePos; InvalidateArea(&SelectStart, SelectCount, 0); UpdateWindow(hwndMain); } } CheckClipboard(); ShowEditCaret(); GetXPos(&CurrCol); return (Return); }
void Solve (char *file) /***************************************************************************** * * * *****************************************************************************/ { int total, correct, found; long TotalNodes; char *p; total = correct = 0; TotalNodes = 0; SET (flags, SOLVE); while (ReadEPDFile (file, 0)) { NewPosition (); total++; ShowBoard (); Iterate (); TotalNodes += NodeCnt + QuiesCnt; p = solution; found = false; while (*p != '\0') { if (!strncmp (p, SANmv, strlen(SANmv))) { correct++; found = true; break; } while (*p != ' ' && *p != '\0') p++; while (*p == ' ' && *p != '\0') p++; } printf ("%s : ", id); printf (found ? "Correct: " : "Incorrect: "); printf ("%s %s\n", SANmv, solution); printf ("Correct=%d Total=%d\n", correct, total); } printf ("\nTotal nodes = %ld\n", TotalNodes); CLEAR (flags, SOLVE); }
void MazeInit(int argc, char **argv) { getMaze(); setRandom(); InitDisplay(argc, argv); NewPosition(M); printf("%d X LOC \n",M->xloc().value()); /* * We don't do ShowPosition() or ShowView() here, but let the update * routine in the window handler do it for the first time when * the window is exposed. */ netInit(); StartDisplay(); RatCursor(); }
void stepproc(float step) { NewPosition(electrodeDepth+(int)(step * 1000)); }
void BookPGNReadFromFile (const char *file) /**************************************************************************** * * To read a game from a PGN file and store out the hash entries to book. * ****************************************************************************/ { FILE *fp; char s[100], wmv[8], bmv[8]; int c; unsigned int i; char header[2000]; int moveno, result, ngames = 0; leaf *p; time_t t1, t2; double et; int examinecolor, playerfound[2]; /* Only players in the table below are permitted into the opening book from the PGN files. Please expand the table as needed. Generally, I would recommend only acknowledged GM's and IM's and oneself, but because of the self-changing nature of the book, anything inferior will eventually be eliminated through automatic play as long as you feed the games the program plays back to itself with "book add pgnfile" */ /* XXX: Is it really a good idea to have a list like this hardcoded? */ const char *const player[] = { "Alekhine", "Adams", "Anand", "Anderssen", "Andersson", "Aronin", "Averbakh", "Balashov", "Beliavsky", "Benko", "Bernstein", "Bird", "Bogoljubow", "Bolbochan", "Boleslavsky", "Byrne", "Botvinnik", "Bronstein", "Browne", "Capablanca", "Chigorin", "Christiansen", "De Firmian", "Deep Blue", "Deep Thought", "Donner", "Dreev", "Duras", "Euwe", "Evans", "Filip", "Fine", "Fischer", "Flohr", "Furman", "Gelfand", "Geller", "Gereben", "Glek", "Gligoric", "GNU", "Golombek", "Gruenfeld", "Guimard", "Hodgson", "Ivanchuk", "Ivkov", "Janowsky", "Kamsky", "Kan", "Karpov", "Kasparov", "Keres", "Korchnoi", "Kortschnoj", "Kotov", "Kramnik", "Kupreich", "Lasker", "Lautier", "Letelier", "Lilienthal", "Ljubojevic", "Marshall", "Maroczy", "Mieses", "Miles", "Morphy", "Mueller", /* Every other German has this name... */ "Nimzowitsch", "Nunn", "Opocensky", "Pachman", "Petrosian", "Piket", "Pilnik", "Pirc", "Polgar", "Portisch", "Psakhis", "Ragozin", "Reshevsky", "Reti", "Romanish", "Rubinstein", "Saemisch", "Seirawan", "Shirov", "Short", "Silman", "Smyslov", "Sokolsky", "Spassky", "Sveshnikov", "Stahlberg", "Steinitz", "Tal", "Tarjan", "Tartakower", "Timman", "Topalov", "Torre", "Vidmar" }; et = 0.0; t1 = time(NULL); result = -1; fp = fopen (file, "r"); if (fp == NULL) { fprintf(stderr, "Cannot open file %s: %s\n", file, strerror(errno)); return; } /* Maybe add some more clever error handling later */ if (BookBuilderOpen() != BOOK_SUCCESS) return; newpos = existpos = 0; nextgame: header[0] = 0; InitVars (); NewPosition (); CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; playerfound[black] = playerfound[white] = 0; /* Skip all the tags */ /* * XXX: This has two problems: 1) Leading whitespace leads to * undefined stuff in s, and completely confuses the program. * 2) If there is a game between two players in the list, only * the moves of the white player will be added. */ /* Skip whitespace */ while ((c=fgetc(fp)) != EOF) { if (c != ' ' && c != '\t' && c != '\n') { ungetc(c, fp); break; } } while ((c=fgetc(fp)) == '[') { ungetc(c, fp); fgets(s, 100, fp); strcat(header,s); if (strncmp(s+1, "White ",6) == 0) { examinecolor = white; ngames++; } else if (strncmp(s+1, "Black ",6) == 0) { examinecolor = black; } else if (strncmp(s+1, "Result", 6) == 0) { if (strncmp(s+7," \"1-0",5) == 0) { result = R_WHITE_WINS; } else if (strncmp(s+7," \"0-1",5) == 0) { result = R_BLACK_WINS; } else if (strncmp(s+7," \"1/2-1/2",9) == 0) { result = R_DRAW; } else { result = R_NORESULT; } continue; } else continue; /* * We get only here if White or Black matched, it is ugly but it * works. Attention: If at some point we want to put this array * of authorized players in some external file, we have to keep * track of the size of that array in some other way. */ for (i = 0; i < (sizeof(player) / sizeof(*player)); i++) { if (strstr(s+7, player[i]) != NULL) { playerfound[examinecolor] = 1; } } } ungetc(c, fp); while (1) { if (fscanf(fp, "%d. %7s ", &moveno, wmv) < 2) break; if (wmv[0] == '1' || wmv[0] == '[' || wmv[0] == '*' || strcmp(wmv, "0-1") == 0) break; p = ValidateMove (wmv); if (!p) { puts(header); ShowBoard(); printf ("Illegal move %d. %s\n", moveno, wmv); break; } MakeMove (white, &p->move); if (playerfound[white]) { if (BookBuilder (result, white) != BOOK_SUCCESS) break; } strcpy (Game[GameCnt].SANmv, wmv); if (fscanf(fp, "%7s ", bmv) < 1) break; if (bmv[0] == '1' || bmv[0] == '[' || bmv[0] == '*' || strcmp(bmv, "0-1") == 0) break; p = ValidateMove (bmv); if (!p) { puts (header); ShowBoard(); printf ("Illegal move %d. ... %s\n", moveno, bmv); break; } MakeMove (black, &p->move); if (playerfound[black] ) { if (BookBuilder (result, black) != BOOK_SUCCESS) break; } strcpy (Game[GameCnt].SANmv, bmv); } /* Read to end of game but don't parse */ while (!feof(fp)) { fgets(s,100,fp); if (s[0] == '\n') break; } /* printf ("%d(%d)\n", GameCnt,BOOKDEPTH); */ if (!feof(fp)) { if (ngames % 10 == 0) printf("%d\r",ngames); fflush(stdout); goto nextgame; } fclose (fp); if (BookBuilderClose() != BOOK_SUCCESS) { perror("Error writing opening book"); } /* Reset the board otherwise we leave the last position in the book on the board. */ header[0] = 0; InitVars (); NewPosition (); CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; t2 = time(NULL); et += difftime(t2, t1); putchar('\n'); /* Handle divide-by-zero problem */ if (et < 0.5) { et = 1.0; }; printf("Time = %.0f seconds\n", et); printf("Games compiled: %d\n",ngames); printf("Games per second: %f\n",ngames/et); printf("Positions scanned: %d\n",newpos+existpos); printf("Positions per second: %f\n",(newpos+existpos)/et); printf("New & unique added: %d positions\n",newpos); printf("Duplicates not added: %d positions\n",existpos); }
void UGripMotionControllerComponent::TickGrip() { if (GrippedActors.Num()) { FTransform WorldTransform; FTransform InverseTransform = this->GetComponentTransform().Inverse(); for (int i = GrippedActors.Num() - 1; i >= 0; --i) { if (GrippedActors[i].Actor || GrippedActors[i].Component) { // GetRelativeTransformReverse had some serious f*****g floating point errors associated with it that was f*****g everything up // Not sure whats wrong with the function but I might want to push a patch out eventually WorldTransform = GrippedActors[i].RelativeTransform.GetRelativeTransform(InverseTransform); UPrimitiveComponent *root = GrippedActors[i].Component; AActor *actor = GrippedActors[i].Actor; if (!root) root = Cast<UPrimitiveComponent>(GrippedActors[i].Actor->GetRootComponent()); if (!root) continue; if (!actor) actor = root->GetOwner(); if (!actor) continue; if (bIsServer) { // Handle collision intersection detection, this is used to intelligently manage some of the networking and late update features. switch (GrippedActors[i].GripCollisionType.GetValue()) { case EGripCollisionType::InteractiveCollisionWithPhysics: case EGripCollisionType::InteractiveHybridCollisionWithSweep: { TArray<FOverlapResult> Hits; FComponentQueryParams Params(NAME_None, this->GetOwner()); Params.bTraceAsyncScene = root->bCheckAsyncSceneOnMove; Params.AddIgnoredActor(actor); Params.AddIgnoredActors(root->MoveIgnoreActors); if(GetWorld()->ComponentOverlapMulti(Hits, root, root->GetComponentLocation(), root->GetComponentQuat(), Params)) { GrippedActors[i].bColliding = true; } else { GrippedActors[i].bColliding = false; } } // Skip collision intersects with these types, they dont need it case EGripCollisionType::PhysicsOnly: case EGripCollisionType::SweepWithPhysics: case EGripCollisionType::InteractiveCollisionWithSweep: default:break; } } // Need to figure out best default behavior /*if (GrippedActors[i].bHasSecondaryAttachment && GrippedActors[i].SecondaryAttachment) { WorldTransform.SetRotation((WorldTransform.GetLocation() - GrippedActors[i].SecondaryAttachment->GetComponentLocation()).ToOrientationRotator().Quaternion()); }*/ if (GrippedActors[i].GripCollisionType == EGripCollisionType::InteractiveCollisionWithPhysics) { UpdatePhysicsHandleTransform(GrippedActors[i], WorldTransform); } else if (GrippedActors[i].GripCollisionType == EGripCollisionType::InteractiveCollisionWithSweep) { if (bIsServer) { FHitResult OutHit; // Need to use without teleport so that the physics velocity is updated for when the actor is released to throw root->SetWorldTransform(WorldTransform, true, &OutHit); if (OutHit.bBlockingHit) { GrippedActors[i].bColliding = true; if (!actor->bReplicateMovement) actor->SetReplicateMovement(true); } else { GrippedActors[i].bColliding = false; if (actor->bReplicateMovement) actor->SetReplicateMovement(false); } } else { if (!GrippedActors[i].bColliding) { root->SetWorldTransform(WorldTransform, true); } } } else if (GrippedActors[i].GripCollisionType == EGripCollisionType::InteractiveHybridCollisionWithSweep) { // Need to use without teleport so that the physics velocity is updated for when the actor is released to throw //if (bIsServer) //{ FBPActorPhysicsHandleInformation * GripHandle = GetPhysicsGrip(GrippedActors[i]); if (!GrippedActors[i].bColliding) { // Make sure that there is no collision on course before turning off collision and snapping to controller if (bIsServer && actor && actor->bReplicateMovement) { FCollisionQueryParams QueryParams(NAME_None, false, this->GetOwner()); FCollisionResponseParams ResponseParam; root->InitSweepCollisionParams(QueryParams, ResponseParam); QueryParams.AddIgnoredActor(actor); QueryParams.AddIgnoredActors(root->MoveIgnoreActors); if (GetWorld()->SweepTestByChannel(root->GetComponentLocation(), WorldTransform.GetLocation(), root->GetComponentQuat(), ECollisionChannel::ECC_Visibility, root->GetCollisionShape(), QueryParams, ResponseParam)) { GrippedActors[i].bColliding = true; } else { GrippedActors[i].bColliding = false; } } // If still not colliding if (!GrippedActors[i].bColliding) { if (bIsServer && actor->bReplicateMovement) // So we don't call on on change event over and over locally actor->SetReplicateMovement(false); if (bIsServer && GripHandle) { DestroyPhysicsHandle(GrippedActors[i]); if(GrippedActors[i].Actor) GrippedActors[i].Actor->DisableComponentsSimulatePhysics(); else root->SetSimulatePhysics(false); } root->SetWorldTransform(WorldTransform, false); } else { if (bIsServer && GrippedActors[i].bColliding && GripHandle) UpdatePhysicsHandleTransform(GrippedActors[i], WorldTransform); } } else if (GrippedActors[i].bColliding && !GripHandle) { if (bIsServer && !actor->bReplicateMovement) actor->SetReplicateMovement(true); root->SetSimulatePhysics(true); if (bIsServer) SetUpPhysicsHandle(GrippedActors[i]); } else { if (bIsServer && GrippedActors[i].bColliding && GripHandle) UpdatePhysicsHandleTransform(GrippedActors[i], WorldTransform); } } else if (GrippedActors[i].GripCollisionType == EGripCollisionType::SweepWithPhysics) { if (bIsServer) { FVector OriginalPosition(root->GetComponentLocation()); FRotator OriginalOrientation(root->GetComponentRotation()); FVector NewPosition(WorldTransform.GetTranslation()); FRotator NewOrientation(WorldTransform.GetRotation()); // Now sweep collision separately so we can get hits but not have the location altered if (bUseWithoutTracking || NewPosition != OriginalPosition || NewOrientation != OriginalOrientation) { FVector move = NewPosition - OriginalPosition; // ComponentSweepMulti does nothing if moving < KINDA_SMALL_NUMBER in distance, so it's important to not try to sweep distances smaller than that. const float MinMovementDistSq = (FMath::Square(4.f*KINDA_SMALL_NUMBER)); if (bUseWithoutTracking || move.SizeSquared() > MinMovementDistSq || NewOrientation != OriginalOrientation) { if (CheckComponentWithSweep(root, move, NewOrientation, false)) { } } } // Move the actor, we are not offsetting by the hit result anyway root->SetWorldTransform(WorldTransform, false); } else { // Move the actor, we are not offsetting by the hit result anyway root->SetWorldTransform(WorldTransform, false); } } else if (GrippedActors[i].GripCollisionType == EGripCollisionType::PhysicsOnly) { // Move the actor, we are not offsetting by the hit result anyway root->SetWorldTransform(WorldTransform, false); } } else { if (bIsServer) { DestroyPhysicsHandle(GrippedActors[i]); GrippedActors.RemoveAt(i); // If it got garbage collected then just remove the pointer, won't happen with new uproperty use, but keeping it here anyway } } } } }
void Undo(WORD Flags) /* Flags: 0 = called as vi-like undo: * undo of whole last operation, * a second undo reverts the undo operation, * entered as character 'u'; * 1 = called as Windows-like undo: * undo last change at one position, * repeated undos go further back in history, * entered as <Alt+Bksp>, menu, or tool button; * 2 = repeated vi-like undo ('.'): * can repeat both undo and redo; * 4 = vi-like undo of whole line: * not yet implemented, * entered as character 'U'; */ { LPUNDO lpUndo; BOOL fUndone = FALSE; ULONG StartSkip = (ULONG)-1; extern INT HexEditFirstNibble; if (Flags & 3) lpUndo = NextSequenceUndo; else { lpUndo = NextSequenceUndo = LastUndo; if (LastUndo != NULL) { LastUndo->Flags |= UD_START; if (LastUndo->Flags & UD_BYUNDO) { if (Redoing && LastUndo->UndoRef!=NULL) lpUndo = LastUndo->UndoRef; Redoing ^= TRUE^FALSE; } else Redoing = FALSE; } } if (lpUndo==NULL || (Redoing && !(lpUndo->Flags & UD_BYUNDO))) { Error(219); return; } if (IsViewOnly()) return; if (UtfEncoding == 16) { /*any undo ops must be double-byte, check before doing anything...*/ LPUNDO lp = lpUndo; ULONG Skip; while (lp != NULL) { if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (lp->DelFill & 1 || lp->Inserted & 1) { ErrorBox(MB_ICONSTOP, 260); return; } if (StartSkip == (ULONG)-1) StartSkip = Skip; if (Flags & 1) break; } if (lp->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lp = lp->Prev; } StartSkip = (ULONG)-1; } HideEditCaret(); wsprintf(QueryString, "%s %s, used mem %lu", Redoing ? "redoing" : "undoing", lpUndo->Flags & UD_BYUNDO ? "undo" : "non-undo", UndoMemUsed); QueryTime = GetTickCount(); GlobalUndoFlags |= UD_BYUNDO; StartWithRemove = lpUndo->Flags & UD_START; StartUndoSequence(); if (FirstUndo == NULL || (FirstUndo->Next == NULL && FirstUndo != lpUndo)) lpUndo = NULL; StartWithRemove = TRUE; HexEditFirstNibble = -1; while (lpUndo != NULL) { POSITION Pos; ULONG Skip; if ((Skip = lpUndo->Pos) != (ULONG)-1) { if (StartSkip == (ULONG)-1) StartSkip = Skip; Pos.p = FirstPage; while (Skip >= Pos.p->Fill) { if (!Pos.p->Next) { if (Skip != Pos.p->Fill) { /*must not occur*/ assert(Skip == Pos.p->Fill); /*!?*/ return; } break; } Skip -= Pos.p->Fill; Pos.p = Pos.p->Next; } if (SelectCount) { InvalidateArea(&SelectStart, SelectCount, 1); SelectCount = 0; UpdateWindow(hwndMain); } Pos.i = (UINT)Skip; Pos.f = 0; /*TODO: check flags to be filled here*/ if (lpUndo->Inserted) { SelectStart = Pos; SelectCount = lpUndo->Inserted; SelectBytePos = CountBytes(&SelectStart); DeleteSelected(3); fUndone = TRUE; Indenting = FALSE; } if (lpUndo->DelFill) { LPSTR Buf; LONG ByteCount = CountBytes(&Pos); if (lpUndo->Flags & UD_GLOBALMEM) Buf = GlobalLock(lpUndo->DelMem); else Buf = (LPBYTE)lpUndo + sizeof(UNDO); if (Buf != NULL) { NewPosition(&Pos); InsertBuffer(Buf, lpUndo->DelFill, 0); fUndone = TRUE; if (lpUndo->Flags & UD_GLOBALMEM) GlobalUnlock(lpUndo->DelMem); /*reposition to current position...*/ Pos.p = FirstPage; Pos.i = 0; Advance(&Pos, ByteCount); if (lpUndo->Flags & UD_SELECT && Flags & 1) { SelectStart = Pos; SelectCount = lpUndo->DelFill; SelectBytePos = CountBytes(&SelectStart); InvalidateArea(&SelectStart, SelectCount, 0); CheckClipboard(); } } else ErrorBox(MB_ICONSTOP, 313); } if (Flags & 1) break; } if (lpUndo->Flags & UD_NEWOP && StartSkip != (ULONG)-1) break; lpUndo = lpUndo->Prev; } GlobalUndoFlags = 0; if (lpUndo != NULL) { if (lpUndo->Flags & UD_SAFE) { EnableToolButton(IDB_SAVE, FALSE); SetSafe(FALSE); GlobalUndoFlags = UD_SAFE; } else if (fUndone) SetUnsafe(); LastUndo->UndoRef = NextSequenceUndo = lpUndo->Prev; #if 0 // if (NextSequenceUndo!=NULL && lpUndo->Flags & UD_BYUNDO // && !(NextSequenceUndo->Flags&UD_BYUNDO)) // NextSequenceUndo->Flags &= ~UD_START; #endif } else { if (fUndone) SetUnsafe(); NextSequenceUndo = NULL; } if (Redoing) CheckForUndoneToRelease(FALSE); /*...undo information about redo and previous undo is not needed anymore * because the original undo information will be used instead. */ if (StartSkip != (ULONG)-1) { CurrPos.p = FirstPage; CurrPos.i = 0; Advance(&CurrPos, StartSkip); FindValidPosition(&CurrPos, (WORD)(Mode==InsertMode || Mode==ReplaceMode)); GetXPos(&CurrCol); } if (lpUndo==NULL || NextSequenceUndo==NULL) EnableToolButton(IDB_UNDO, FALSE); ShowEditCaret(); }
void BookPGNReadFromFile (const char *file) /**************************************************************************** * * To read a game from a PGN file and store out the hash entries to book. * ****************************************************************************/ { FILE *fp; int moveno, ngames = 0; time_t t1, t2; double et; int error; /* TODO: Fix reading from file */ et = 0.0; t1 = time(NULL); fp = fopen (file, "r"); if (fp == NULL) { fprintf(stderr, "Cannot open file %s: %s\n", file, strerror(errno)); return; } yyin = fp; /* Maybe add some more clever error handling later */ if (BookBuilderOpen() != BOOK_SUCCESS) return; newpos = existpos = 0; data_dest = DEST_BOOK; while(1) { InitVars (); NewPosition (); CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; error = yylex(); if (error) break; ngames++; if (ngames % 10 == 0) printf("Games processed: %d\r",ngames); fflush(stdout); } fclose (fp); if (BookBuilderClose() != BOOK_SUCCESS) { perror("Error writing opening book during BookBuilderClose"); } /* Reset the board otherwise we leave the last position in the book on the board. */ InitVars (); NewPosition (); CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; t2 = time(NULL); et += difftime(t2, t1); putchar('\n'); /* Handle divide-by-zero problem */ if (et < 0.5) { et = 1.0; }; printf("Time = %.0f seconds\n", et); printf("Games compiled: %d\n",ngames); printf("Games per second: %f\n",ngames/et); printf("Positions scanned: %d\n",newpos+existpos); printf("Positions per second: %f\n",(newpos+existpos)/et); printf("New & unique added: %d positions\n",newpos); printf("Duplicates not added: %d positions\n",existpos); }
void System::importanceSampling() { int NOA; // Number Of Accepted steps double I, I2, dx; // total energy integral double T, T2, dt; // kinetic energy integral double V, V2, dv; // potential energy integral int a,b,c,i,j; // loop variables: a->alpha, b->beta, c->cycles, i->particle, j-> dimension int amax = Alpha.n_elem; // number of total alpha values int bmax = Beta.n_elem; // number of total beta values double wf_new, wf_old; double greensfunction; double D = 0.5; // diffusion constant for (a=0; a<amax; a++) // LOOP OVER ALPHA VALUES { Wavefunction->setAlpha(a); TypeHamiltonian->getWavefunction()->setAlpha(a); for (b=0; b<bmax; b++) // LOOP OVER BETA VALUES { Wavefunction->setBeta(b); TypeHamiltonian->getWavefunction()->setBeta(b); dx = I = I2 = NOA = 0; dt = T = T2 = 0; dv = V = V2 = 0; // IMPORTANCE SAMPLING: for (c=0; c<NumberOfCycles; c++) { dx = 0; for (i=0; i<NumberOfParticles; i++) { // Taking a new, random step, moving one particle only: NewPosition = OldPosition; NewPosition.row(i) = OldPosition.row(i)+Rnd->nextGauss(0,sqrt(StepLength))+QuantumForceOld.row(i)*StepLength*D; wf_new = Wavefunction->evaluateWavefunction(NewPosition); quantumForce(NewPosition,QuantumForceNew,wf_new); // Metropolis-Hastings algorithm: greensfunction = 0.0; for(j=0;j<NumberOfDimensions;j++) { greensfunction += 0.5*(QuantumForceOld(i,j) + QuantumForceNew(i,j))*(D*StepLength*0.5*(QuantumForceOld(i,j)-QuantumForceNew(i,j)) - NewPosition(i,j) + OldPosition(i,j)); } greensfunction = exp(greensfunction); // Metropolis test: if (ran0(&RandomSeed) <= greensfunction*wf_new*wf_new/(wf_old*wf_old)) { OldPosition.row(i) = NewPosition.row(i); QuantumForceOld.row(i) = QuantumForceNew.row(i); Wavefunction->setOldWavefunction(wf_new); wf_old = wf_new; } } // Updating integral: // LOCAL ENERGY dx = TypeHamiltonian->evaluateLocalEnergy(OldPosition); I += dx; I2 += dx*dx; // LOCAL KINETIC ENERGY dt = TypeHamiltonian->getKineticEnergy(); T += dt; T2 += dt*dt; // LOCAL POTENTIAL ENERGY dv = TypeHamiltonian->getPotentialEnergy(); V += dv; V2 += dv*dv; NOA++; } NumberOfAcceptedSteps(a,b) = NOA; Energy(a,b) = I/double(NumberOfCycles); EnergySquared(a,b) = I2/double(NumberOfCycles); Variance(a,b) = (EnergySquared(a,b) - Energy(a,b)*Energy(a,b)); KineticEnergy(a,b) = T/double(NumberOfCycles); KineticEnergySquared(a,b) = T2/double(NumberOfCycles); PotentialEnergy(a,b) = V/double(NumberOfCycles); PotentialEnergySquared(a,b) = V2/double(NumberOfCycles); //AvgDistance = 0; } } }
hgeVector c_gameobject::GetNewPosition_Rect(hgeRect BoundingBox1,hgeRect BoundingBox2) { hgeVector A = PreviousPosition; hgeVector B = Position; hgeVector C; hgeVector NewPosition(0,0); hgeVector SwapPosition; c_bool PointUnderLine; c_bool A_coef_negative, B_coef_negative; c_bool A_coef_zero, B_coef_zero; c_bool Y_fixed; float Size_x = (BoundingBox1.x2 - BoundingBox1.x1) / 2; float Size_y = (BoundingBox1.y2 - BoundingBox1.y1) / 2; //Определим номер угла спрайта, который мы пересекли //Верхний левый - 1, далее по часовой size_t angle_number = 0; //1.Верхний левый if (BoundingBox1.TestPoint(BoundingBox2.x1, BoundingBox2.y1)) { angle_number = 1; C = hgeVector(BoundingBox2.x1, BoundingBox2.y1); } //2.Верхний правый if (BoundingBox1.TestPoint(BoundingBox2.x2, BoundingBox2.y1)) { angle_number = 2; C = hgeVector(BoundingBox2.x2, BoundingBox2.y1); } //3.Нижний правый if (BoundingBox1.TestPoint(BoundingBox2.x2, BoundingBox2.y2)) { angle_number = 3; C = hgeVector(BoundingBox2.x2, BoundingBox2.y2); } //4.Нижний левый if (BoundingBox1.TestPoint(BoundingBox2.x1, BoundingBox2.y2)) { angle_number = 4; C = hgeVector(BoundingBox2.x1, BoundingBox2.y2); } //Смещаем точки, так как 'AB' - линия перемещения угла (который пересёк другой спрайт), а не центра switch (angle_number) { case 1: A.x = A.x + Size_x; A.y = A.y + Size_y; B.x = B.x + Size_x; B.y = B.y + Size_y; NewPosition.x -= Size_x; NewPosition.y -= Size_y; break; case 2: A.x = A.x - Size_x; A.y = A.y + Size_y; B.x = B.x - Size_x; B.y = B.y + Size_y; NewPosition.x += Size_x; NewPosition.y -= Size_y; break; case 3: A.x = A.x - Size_x; A.y = A.y - Size_y; B.x = B.x - Size_x; B.y = B.y - Size_y; NewPosition.x += Size_x; NewPosition.y += Size_y; break; case 4: A.x = A.x + Size_x; A.y = A.y - Size_y; B.x = B.x + Size_x; B.y = B.y - Size_y; NewPosition.x -= Size_x; NewPosition.y += Size_y; break; default: break; } // Уравнения прямых // AB: (A.y - B.y)*X + (B.x - A.x)*Y + (A.x*B.y - B.x*A.y) = 0 // C-h: Y - C.y = 0 // C-v: X - C.x = 0 //Узнаем знак коэф. при Y //Если коэф. при Y меньше 0, то меняем точки местами (нужно для однозначности дальнейших результатов) if ((B.x - A.x) < 0) { B_coef_negative.SetTrue(); SwapPosition = A; A = B; B = SwapPosition; } if ((B.x - A.x) == 0) { B_coef_zero.SetTrue(); } //Узнаем знак коэф. при X if ((A.y - B.y) < 0) { A_coef_negative.SetTrue(); } if ((A.y - B.y) == 0) { A_coef_zero.SetTrue(); } //Проверяем ниже ли точка C относительно прямой AB //Так как ось Y инвертрована (отсчёт идёт сверху вниз), //то значение больше нуля означает, что точка лежит под линией if ((A.y - B.y)*C.x + (B.x - A.x)*C.y + (A.x*B.y - B.x*A.y) > 0) { PointUnderLine.SetTrue(); } // 1\/2 3\/4 // 16\ /5 // 15/ \6 // o // 14\ /7 // 13/ \8 // 12/\11 10/\9 // // POINT_UNDER : 1, 4, 7, 8, 10, 11, 13, 14 // !POINT_UNDER: 2, 3, 5, 6, 9, 12, 15, 16 // // A_NEGATIVE : 1, 3, 6, 8, 9, 11, 14, 16 // !A_NEGATIVE : 2, 4, 5, 7, 10, 12, 13, 15 // // B_NEGATIVE : 2, 4, 5, 6, 7, 8, 9, 11, // !B_NEGATIVE : 1, 3, 10, 12, 13, 14, 15, 16 // // Y_fixed: 1, 2, 3, 4, 9, 10, 11, 12 // X_fixed: 5, 6, 7, 8, 13, 14, 15, 16 switch (angle_number) { case 1: if (!A_coef_zero.GetState() && !B_coef_zero.GetState()) { //1 if (PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //2 if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //15 if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } //16 if (!PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } } else { //a if (B_coef_zero.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //h if (A_coef_zero.GetState()) { Velocity.x = 0; Acceleration = 0; } } break; case 2: if (!A_coef_zero.GetState() && !B_coef_zero.GetState()) { //3 if (!PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //4 if (PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //5 if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } //6 if (!PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } } else { //b if (B_coef_zero.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //c if (A_coef_zero.GetState()) { Velocity.x = 0; Acceleration = 0; } } break; case 3: if (!A_coef_zero.GetState() && !B_coef_zero.GetState()) { //9 if (!PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //10 if (PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //7 if (PointUnderLine.GetState() && !A_coef_negative.GetState() && B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } //8 if (PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } } else { //e if (B_coef_zero.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //d if (A_coef_zero.GetState()) { Velocity.x = 0; Acceleration = 0; } } break; case 4: if (!A_coef_zero.GetState() && !B_coef_zero.GetState()) { //11 if (PointUnderLine.GetState() && A_coef_negative.GetState() && B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //12 if (!PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //13 if (PointUnderLine.GetState() && !A_coef_negative.GetState() && !B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } //14 if (PointUnderLine.GetState() && A_coef_negative.GetState() && !B_coef_negative.GetState()) { Velocity.x = 0; Acceleration = 0; } } else { //f if (B_coef_zero.GetState()) { Y_fixed.SetTrue(); Velocity.y = 0; JumpImpulse = 0; } //g if (A_coef_zero.GetState()) { Velocity.x = 0; Acceleration = 0; } } break; default: break; } //Вычисляем новую позицию куда должны переместить угол нашего объекта (попавший внутрь другого спрайта) if (angle_number) { if (!A_coef_zero.GetState() && !B_coef_zero.GetState()) { if (Y_fixed.GetState()) { NewPosition.y += C.y; NewPosition.x += -(((A.x*B.y - B.x*A.y) - (-C.y)*(B.x - A.x)) / (A.y - B.y)); } else { NewPosition.x += C.x; NewPosition.y += -(((A.y - B.y)*(-C.x) - (A.x*B.y - B.x*A.y)) / -(B.x - A.x)); } } else { if (Y_fixed.GetState()) { NewPosition.x += B.x; NewPosition.y += C.y; } else { NewPosition.x += C.x; NewPosition.y += B.y; } } } else //Если углы спрайтов не пересекались, то проверяем стороны { //1.Верхняя сторона if (PreviousPosition.y < BoundingBox2.y1) { NewPosition.y = BoundingBox2.y1 - Size_y; Velocity.y = 0; JumpImpulse = 0; } //2.Нижняя сторона if (PreviousPosition.y > BoundingBox2.y2) { NewPosition.y = BoundingBox2.y2 + Size_y; Velocity.y = 0; JumpImpulse = 0; } //3.Левая сторона if (PreviousPosition.x < BoundingBox2.x1) { NewPosition.x = BoundingBox2.x1 - Size_x; Velocity.x = 0; Acceleration = 0; } //4.Правая сторона if (PreviousPosition.x > BoundingBox2.x2) { NewPosition.x = BoundingBox2.x2 + Size_x; Velocity.x = 0; Acceleration = 0; } } return NewPosition; };
void processPacket (MWEvent *eventPacket) { MW244BPacket *p = new MW244BPacket ; p = eventPacket->eventDetail; /*cout << p->ID<< endl; cout << p->sequence_number<< endl; cout << p->score<< endl; cout << p->x_pos<< endl; cout << p->y_pos<< endl; cout << p->dir<< endl; cout << p->tagged_rat<< endl; cout << p->globalID<< endl; ConvertIncoming(p); cout << p->ID<< endl; cout << p->sequence_number<< endl; cout << p->score<< endl; cout << p->x_pos<< endl; cout << p->y_pos<< endl; cout << p->dir<< endl; cout << p->tagged_rat<< endl; cout << p->globalID<< endl; exit(0);*/ cout << "PP " << p->ID << endl; if (myPacket(p, &eventPacket->eventSource) && join)// BECAUSE WHILE YOU ARE STILL 0, you will get packets with ID 0 { return; } else { if (!join && expected_seqno[p->ID] <= p->sequence_number){ if (p->globalID == 7) // What if there is only player with global ID 7? :/ { cout << "You are one player too many :(" << endl; cout << "Please try again later." << endl; exit(0); } else { for (int i = 0; i < 100; i++) cout << "Incrementing for no reason" << endl; join = true; GLOBAL_ID = p->globalID+1; M->myRatIdIs(GLOBAL_ID); setMapping(); UpdateScoreCard(0); MW244BPacket q; makePacket(&q,'h',-1, updateSeqNo); sendPacketToPlayers(q); participants[p->ID]++; Rat r; r.playing = 1; cout << "NEW " << p->ID << endl; r.x=p->x_pos; r.y=p->y_pos; r.dir=(p->dir); M->mazeRats_[Mapping_idToIndex.find(p->ID)->second] = r; rat_array[p-> ID]=new MW244BPacket; rat_array[Mapping_idToIndex.find(p->ID)->second]=p; Loc x(p->x_pos); Loc y(p->y_pos); Direction dir(p-> dir); RatIndexType ratId(Mapping_idToIndex.find(p->ID)->second); SetRatPosition(ratId, x, y, dir); UpdateScoreCard(Mapping_idToIndex.find(p-> ID)->second); expected_seqno[p->ID] = p->sequence_number + 1; return; } } if (GLOBAL_ID < p->globalID && expected_seqno[p->ID] <= p->sequence_number ) GLOBAL_ID = p->globalID; if (p->status == 'a' && p->tagged_rat == M->myRatId().value()) { // cannot discard expected_seqno[p->ID] <= p->sequence_number // because we're getting this packet because the other side didn't get b :( // MUST send b MW244BPacket q; makePacket(&q,'b',-1, updateSeqNo); sendPacketToPlayers(q); cout<<p->sequence_number<<"Seq number"<<endl; cout<<prevseq_a[p->ID]<<"Previous Seq number"<<endl; if (p->sequence_number > prevseq_a[p->ID]) { // dealing with duplicates DrawString("You have been tagged!",21,200,250); M->scoreIs( M->score().value()-5 ); UpdateScoreCard(0); NewPosition(M); } prevseq_a[p->ID] = p->sequence_number; } else if (p->status == 'a' && expected_seqno[p->ID] <= p->sequence_number){ //RatIndexType ratId(p-> ID); //ClearRatPosition(ratId); RatIndexType ratId( Mapping_idToIndex.find(p->ID)->second); ClearRatPosition(ratId); } if (p->status == 'b' && expected_seqno[p->ID] <= p->sequence_number) { checkingzero = 1; updateSeqNo = true; } if (p->status == 'f' && expected_seqno[p->ID] <= p->sequence_number) { //player has left cout << "Player has gone :(" << endl; participants[p->ID] = -1;// in next section, will be incremented to 0 // automatically dealt with in ratstates RatIndexType ratId( Mapping_idToIndex.find(p->ID)->second); ClearRatPosition(ratId); // WHY IS THIS NOT WORKING? :/ clearSquare(p->x_pos, p->y_pos); cout << p->x_pos << "," << p->y_pos << endl; cout << M->mazeRats_[Mapping_idToIndex.find(p->ID)->second].x.value() << "," << M->mazeRats_[Mapping_idToIndex.find(p->ID)->second].y.value() << endl; } if (expected_seqno[p->ID] <= p->sequence_number) { // if this condition is false, then we are discarding the packet. Rat r; r.playing = 1; cout << "IF " << p->ID << endl; r.x=p->x_pos; r.y=p->y_pos; r.dir=(p->dir); M->mazeRats_[Mapping_idToIndex.find(p->ID)->second] = r; rat_array[p-> ID]=new MW244BPacket; rat_array[Mapping_idToIndex.find(p->ID)->second]=p; Loc x(p->x_pos); Loc y(p->y_pos); Direction dir(p-> dir); RatIndexType ratId(Mapping_idToIndex.find(p->ID)->second); SetRatPosition(ratId, x, y, dir); UpdateScoreCard(Mapping_idToIndex.find(p-> ID)->second); expected_seqno[p->ID] = p->sequence_number + 1; participants[p->ID]++; } } }
void InputCmd () /************************************************************************* * * This is the main user command interface driver. * *************************************************************************/ { const char *color[2] = { "White", "Black" }; int suffix; int i; leaf *ptr; int ncmds; char *x,*trim; CLEAR (flags, THINK); memset(userinput,0,sizeof(userinput)); memset(cmd,0,sizeof(cmd)); #ifndef HAVE_LIBREADLINE /* Why is this necessary anyway? */ memset(inputstr,0,sizeof(inputstr)); #endif #ifdef HAVE_LIBREADLINE if (isatty(STDIN_FILENO)) { sprintf(s,"%s (%d) %c ", color[board.side], (GameCnt+1)/2 + 1, prompt); inputstr = readline(s); if (inputstr == NULL) return; if (*inputstr) { add_history(inputstr); } if (strlen(inputstr) > INPUT_SIZE-1) { printf("Warning: Input line truncated to %d characters.\n", INPUT_SIZE -1 ); inputstr[INPUT_SIZE-1] = '\000'; } } else { inputstr = malloc(INPUT_SIZE); if (inputstr == NULL) { perror("InputCmd"); exit(EXIT_FAILURE); } fgets(inputstr, INPUT_SIZE, stdin); if (inputstr[0]) { inputstr[strlen(inputstr)-1] = 0; } } #else /* !HAVE_LIBREADLINE */ if (!(flags & XBOARD)) { printf ("%s (%d) %c ", color[board.side], (GameCnt+1)/2 + 1, prompt); fflush(stdout); } fgets (inputstr, INPUT_SIZE, stdin) ; #endif /* HAVE_LIBREADLINE */ cmd[0] = '\n'; strcpy(userinput,inputstr); sscanf (inputstr, "%s %[^\n]", cmd, inputstr); if (cmd[0] == '\n') goto done; cmd[0] = subcmd[0] = setting[0] = subsetting[0] = '\0'; ncmds = sscanf (userinput,"%s %s %s %[^\n]", cmd,subcmd,setting,subsetting); /* Put options after command back in inputstr - messy */ sprintf(inputstr,"%s %s %s",subcmd,setting,subsetting); trim = inputstr + strlen(inputstr) - 1; while ( trim>=inputstr && *trim==' ') *trim--='\0'; if (strcmp (cmd, "quit") == 0 || strcmp (cmd, "exit") == 0) SET (flags, QUIT); else if (strcmp (cmd, "help") == 0) ShowHelp (inputstr); else if (strcmp (cmd, "show") == 0) ShowCmd (inputstr); else if (strncmp (cmd, "book", 4) == 0) { if (strncmp(inputstr, "add",3) == 0) { sscanf (inputstr, "add %s", file); if (access(file,F_OK) < 0) { printf("The syntax to add a new book is:\n\n\tbook add file.pgn\n"); } else { BookPGNReadFromFile (file); } } else if (strncmp (inputstr, "on", 2) == 0 || strncmp (inputstr, "prefer", 6) == 0) { bookmode = BOOKPREFER; printf("book now on.\n"); } else if (strncmp (inputstr, "off", 3) == 0) { bookmode = BOOKOFF; printf("book now off.\n"); } else if (strncmp (inputstr, "best", 4) == 0) { bookmode = BOOKBEST; printf("book now best.\n"); } else if (strncmp (inputstr, "worst", 5) == 0) { bookmode = BOOKWORST; printf("book now worst.\n"); } else if (strncmp (inputstr, "random", 6) == 0) { bookmode = BOOKRAND; printf("book now random.\n"); } } else if (strcmp (cmd, "test") == 0) TestCmd (inputstr); else if (strcmp (cmd, "version") == 0) ShowVersion (); else if (strcmp (cmd, "pgnsave") == 0) { if ( strlen(inputstr) > 0 && strlen(inputstr) < INPUT_SIZE ) PGNSaveToFile (inputstr,""); else printf("Invalid filename.\n"); } else if (strcmp (cmd, "pgnload") == 0) PGNReadFromFile (inputstr); else if (strcmp (cmd, "manual") == 0) SET (flags, MANUAL); else if (strcmp (cmd, "debug") == 0) { SET (flags, DEBUGG); Debugmvl = 0; if (strcmp (inputstr, "debug") == 0) { while (strcmp (inputstr, s)) { sscanf (inputstr, "%s %[^\n]", s, inputstr); ptr = ValidateMove (s); Debugmv[Debugmvl++] = ptr->move; MakeMove (board.side, &ptr->move); } i = Debugmvl; while (i) { UnmakeMove (board.side, &Debugmv[--i]); } } } else if (strcmp (cmd, "force") == 0) SET (flags, MANUAL); else if (strcmp (cmd, "white") == 0) ; else if (strcmp (cmd, "black") == 0) ; else if (strcmp (cmd, "hard") == 0) ; else if (strcmp (cmd, "easy") == 0) ; else if (strcmp (cmd, "list") == 0) { if (inputstr[0] == '?') { printf("name - list known players alphabetically\n"); printf("score - list by GNU best result first \n"); printf("reverse - list by GNU worst result first\n"); } else { sscanf (inputstr, "%s %[^\n]", cmd, inputstr); if (inputstr == '\000') DBListPlayer("rscore"); else DBListPlayer(inputstr); } } else if (strcmp (cmd, "post") == 0) SET (flags, POST); else if (strcmp (cmd, "nopost") == 0) CLEAR (flags, POST); else if (strcmp (cmd, "name") == 0) { strcpy(name, inputstr); x = name; while (*x != '\000') { if (*x == ' ') { *x = '\000'; break; } x++; } suffix = 0; for (;;) { sprintf(logfile,"log.%03d",suffix); sprintf(gamefile,"game.%03d",suffix); if (access(logfile,F_OK) < 0) { ofp = fopen(logfile,"w"); break; } else suffix++; } } else if (strcmp (cmd, "result") == 0) { if (ofp != stdout) { fprintf(ofp, "result: %s\n",inputstr); fclose(ofp); ofp = stdout; printf("Save to %s\n",gamefile); PGNSaveToFile (gamefile, inputstr); DBUpdatePlayer (name, inputstr); } } else if (strcmp (cmd, "rating") == 0) { sscanf(inputstr,"%d %d",&myrating,&opprating); fprintf(ofp,"my rating = %d, opponent rating = %d\n",myrating,opprating); /* Change randomness of book based on opponent rating. */ /* Basically we play narrower book the higher the opponent */ if (opprating >= 1700) bookfirstlast = 2; else if (opprating >= 1700) bookfirstlast = 2; else bookfirstlast = 2; } else if (strcmp (cmd, "activate") == 0) { CLEAR (flags, TIMEOUT); CLEAR (flags, ENDED); } else if (strcmp (cmd, "new") == 0) { InitVars (); NewPosition (); CLEAR (flags, MANUAL); CLEAR (flags, THINK); myrating = opprating = 0; } else if (strcmp (cmd, "time") == 0) { sscanf (inputstr, "%s %[^\n]", s, inputstr); TimeLimit[1^board.side] = atoi(s) / 100.0f ; } else if (strcmp (cmd, "otim") == 0) ; else if (strcmp (cmd, "random") == 0) ; else if (strcmp (cmd, "hash") == 0) { sscanf (inputstr, "%s %[^\n]", cmd, inputstr); if (strcmp (cmd, "off") == 0) CLEAR (flags, USEHASH); else if (strcmp (cmd, "on") == 0) SET (flags, USEHASH); printf ("Hashing %s\n", flags & USEHASH ? "on" : "off"); } else if (strcmp (cmd, "hashsize") == 0) { if (inputstr[0] == 0) { printf("Current HashSize is %u slots\n", HashSize); } else { i = atoi (inputstr); TTHashMask = 0; while ((i >>= 1) > 0) { TTHashMask <<= 1; TTHashMask |= 1; } HashSize = TTHashMask + 1; printf ("Adjusting HashSize to %u slots\n", HashSize); InitHashTable (); } } else if (strcmp (cmd, "null") == 0)