bool DoKeepDistanceAndShoot( Mob* mob, Player* player, uint32_t delta ) { DoLogicAngleAdd( mob, mob->angle_to_player ); float dist = mob->player_distance; cml::vector3f mob2player = mob->transform.position - player->transform.position; if( dist < 6 ) DoMove( mob, mob2player , -4 ); if( dist > 7 ) DoMove( mob, mob2player , 4 ); DoMove( mob, mob2player , 4 ); bool shoot = mob->player_distance < SHOOT_DISTANCE; return DoShoot( &(mob->wep), shoot, delta ); }
/*归原点操作*/ void ScanThread::HomeMove() { if(spark_info->b_array[B_HOME_Z_UP]){ if(e_edge == FALL){ qDebug()<<"home up"; program.Speed = 400; program.Mode = Hand_Velocity_MODE; program.Driect = Hand_A_DRIECT; DoMove(&program); }else{ if(spark_info->b_array[B_Z_UP_ALERT]){ DoStop(&program); } } e_last = true; } else{ /*手动停止归原点操作*/ if(e_edge == RISE){ DoStop(&program); AxisSwitch(&program ,Hand_NULL_AXIS ,Hand_A_DRIECT); program.Mutex = Hand_NULL_MUTEX; spark_info->hand.Mutex = Hand_NULL_MUTEX; } e_last = false; } if(spark_info->b_array[B_HOME_Z_DOWN]){ if(f_edge == FALL){ program.Speed = 400; program.Mode = Hand_Velocity_MODE; program.Driect = Hand_B_DRIECT; DoMove(&program); }else{ if(spark_info->b_array[B_Z_DOWN_ALERT]){ DoStop(&program); } } f_last = true; } else{ /*手动停止归原点操作*/ if(f_edge == RISE){ DoStop(&program); AxisSwitch(&program ,Hand_NULL_AXIS ,Hand_B_DRIECT); spark_info->hand.Mutex = Hand_NULL_MUTEX; program.Mutex = Hand_NULL_MUTEX; } f_last = false; } }
void UserTurn (game_state_t * game) { move_t userMove = Menu_PlayUser(game); DoMove(&userMove, game); }
void VAutoDialog::OnAuto(wxCommandEvent& ev) { // Go into auto state m_Auto = true; DoDisableControls (false); // Get next object from list long selected = m_PlanList->GetNextItem (0, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (selected == -1) { if (!NextPlanTarget ()) { m_Auto = false; SetState (STATE_READY); DoDisableControls (false); return; } selected = m_PlanList->GetNextItem (0, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } TargetList& targets = m_Plan.GetAll (); m_CurrentTarget = targets[selected]; // Start to move if (!DoMove ()) { m_Auto = false; SetState (STATE_READY); DoDisableControls (false); return; } // The rest is on the notification methods... }
void WorkspaceWork::DnDInsert(int line, PasteClip& d) { if(GetActivePackage() == METAPACKAGE) return; if(GetInternalPtr<UppList>(d, "package-file") == &filelist && d.Accept()) DoMove(line < fileindex.GetCount() ? fileindex[line] : actual.file.GetCount(), true); }
void PopulateEdgelist(EDGELIST *tree) { int level; POSITION parent, child; MOVELIST *childMoves; MOVE theMove; OPEN_POS_DATA pdata, cdata; int resizeCount = 0; int resizeLevelCount = 0; if(!kLoopy || !gUseOpen) level = 0; for(parent=0; parent < gNumberOfPositions; parent++) { if(GetValueOfPosition(parent) == undecided && Remoteness(parent) != REMOTENESS_MAX) { continue; } if(Primitive(parent) != undecided) { continue; } else { childMoves = GenerateMoves(parent); } while(1) { theMove = childMoves->move; child = DoMove(parent, theMove); if(kLoopy && gUseOpen) { pdata = GetOpenData(parent); cdata = GetOpenData(child); level = GetLevelNumber(pdata); } /* If the level is more than the number in tree, resize to handle more levels */ if(level > (GameTree.NumberOfLevels - 1)) { resizeCount++; ResizeTree(&GameTree, level); } (((GameTree.edges)[level])[(GameTree.nextEdgeInLevel)[level]]).Parent = parent; (((GameTree.edges)[level])[(GameTree.nextEdgeInLevel)[level]]).Child = child; (GameTree.nextEdgeInLevel)[level] += 1; /* Resize an individual level if no room left */ if(((GameTree.edgesPerLevel)[level] - 2) <= (GameTree.nextEdgeInLevel)[level]) { resizeLevelCount++; (GameTree.edges)[level] = SafeRealloc((GameTree.edges)[level], (GameTree.edgesPerLevel)[level] * 2 * sizeof(EDGE)); (GameTree.edgesPerLevel)[level] = (GameTree.edgesPerLevel)[level] * 2; } if((childMoves = childMoves->next) == NULL) { break; } } } //printf("Levels resized: %d, tree resized: %d\n", resizeLevelCount, resizeCount); }
OPEN_POS_DATA DetermineFreAndCorDown1LevelForWin(POSITION p) { OPEN_POS_DATA dat=GetOpenData(p); MOVELIST* moves=GenerateMoves(p); MOVELIST* temp=moves; int count=0; int minFremoteness=FREMOTENESS_MAX; int minCorruption=CORRUPTION_MAX; for(; moves; moves=moves->next) { POSITION child=DoMove(p,moves->move); OPEN_POS_DATA cdat=GetOpenData(child); if(GetDrawValue(cdat)!=lose || GetLevelNumber(cdat)!=GetLevelNumber(dat)) continue; if(GetCorruptionLevel(cdat)==minCorruption && GetFremoteness(cdat)<minFremoteness) { minFremoteness=GetFremoteness(cdat); corruptedPositions[p]=corruptedPositions[p]||corruptedPositions[child]; } if(GetCorruptionLevel(cdat)<minCorruption) { minCorruption=GetCorruptionLevel(cdat); minFremoteness=GetFremoteness(cdat); corruptedPositions[p]=corruptedPositions[child]; } count++; } FreeMoveList(temp); if(count==0) return GetOpenData(p); dat=SetFremoteness(SetCorruptionLevel(dat,minCorruption),minFremoteness+1); return dat; }
static void RunAnnotate(char *fname, int side) { FILE *fin = fopen(fname, "r"); struct Position *p; if(fin) { struct PGNHeader header; char move[16]; while(!scanHeader(fin, &header)) { p = InitialPosition(); while(!scanMove(fin, move)) { int themove = ParseSAN(p, move); if(themove != M_NONE) { ShowPosition(p); Print(0, "%s(%d): ", p->turn == White ? "White":"Black", (p->ply/2)+1); Print(0, "%s\n", SAN(p, themove)); if(side == -1 || (side == p->turn)) { Iterate(p); } DoMove(p, themove); } } FreePosition(p); } } else Print(0, "Couldn't open %s\n", fname); }
void WorkspaceWork::MoveFile(int d) { int bi = filelist.GetCursor() + d; if(bi < 0 || bi >= fileindex.GetCount()) return; DoMove(fileindex[bi], false); }
void VAutoDialog::OnMove(wxCommandEvent& ev) { wxString mbTitle = _("Moving telescope"); wxLogDebug (wxT("VAutoDialog::OnMove starts telescope moving.")); // Check whether target is valid if (!m_CurrentTarget.IsValid()) { wxMessageBox (_("No valid target is selected to move."), mbTitle, wxICON_EXCLAMATION | wxOK, this); return; } // Check whether the target is above the horizon // double lon = wxAtof (Properties::Instance().Get(STATION_LONGITUDE)); // double lat = wxAtof (Properties::Instance().Get(STATION_LATITUDE)); // Station station (lon, lat); // if (!m_CurrentTarget.GetCoord().AboveHorizon(station, wxDateTime::Now().GetJulianDayNumber())) if (!IsTargetAboveHorizon (m_CurrentTarget)) { wxMessageBox (_("The object currently is under the horizon"), GetTitle(), wxICON_EXCLAMATION | wxOK, this); return; } DoMove (); }
void ExecuteCommand(struct Command *theCommand) { if(theCommand->move != M_NONE) { DoMove(CurrentPosition, theCommand->move); } else { COMMAND cfunc = theCommand->command_func; cfunc(theCommand->args); } }
/*手动按键操作*/ void ScanThread::HandleMove() { /*上升按键*/ if((spark_info->c_array[C_Z_IN0] & 0x10)) { if(a_edge == FALL){ DoMove(&spark_info->hand); a_edge = NONE; } a_last = true; return; }else{ if(a_edge == RISE){ DoStop(&spark_info->hand); AxisSwitch(&spark_info->hand ,Hand_NULL_AXIS ,Hand_A_DRIECT); spark_info->hand.Mutex = Hand_NULL_MUTEX; a_edge = NONE; } a_last = false; } /*下降按键*/ if((spark_info->c_array[C_Z_IN0] & 0x20)) { if(b_edge == FALL){ DoMove(&spark_info->hand); b_edge = NONE; } b_last = true; return; }else{ if(b_edge == RISE){ DoStop(&spark_info->hand); AxisSwitch(&spark_info->hand ,Hand_NULL_AXIS ,Hand_A_DRIECT); spark_info->hand.Mutex = Hand_NULL_MUTEX; b_edge = NONE; } b_last = false; } }
void GotoGameMove(GAME *Game, int MoveNo) { CopyBoard(Game->StartBoard,Game->Board); if (RestoreClocks) ElapsedTime[0] = ElapsedTime[1] = 0.0; for (Game->MoveNo = 0; Game->MoveNo < MoveNo && Game->Move[Game->MoveNo].Move != NO_MOVE; Game->MoveNo++) { if (RestoreClocks) ElapsedTime[Game->Board->Colour>0] += Game->Move[Game->MoveNo].Time; DoMove(Game->Board,Game->Move[Game->MoveNo].Move); } TurnBegin = CurrentTime(); }
void RedoGameMove(GAME *Game) { if (Game->Move[Game->MoveNo].Move == NO_MOVE) { Error("Game->Move[Game->MoveNo].Move == NO_MOVE in RedoGameMove()"); return; } if (RestoreClocks) ElapsedTime[Game->Board->Colour>0] += Game->Move[Game->MoveNo].Time; DoMove(Game->Board,Game->Move[Game->MoveNo].Move); Game->MoveNo++; TurnBegin = CurrentTime(); }
//one turn of the CPU. void CPUTurn (game_state_t * game) { //get CPU's color color_t color = Settings_CPUColor_Get(); //choose the next move based on minimax: //get max depth based on settings int max_depth = Settings_MaxDepth_Get(); //get initial children list from given state. //(allowed moves for CPU.) ListNode * RootChildren = GetMovesForPlayer(game, color); //child with best score will decide what move to do . int childIndex; int childScore; MinimaxChoose (game, color, RootChildren, 0, max_depth, DraughtsScoringFunction, GetMovesForPlayer, &childIndex, &childScore); DEBUG_PRINT( ("index %d was chosen. will lead to score of %d\n", childIndex, childScore)); //do the relevant move int i=0; //find index in list ListNode * pChild = RootChildren; while (i<childIndex && pChild!=NULL ) { pChild = pChild->next; i++; } //do the move if (pChild) { move_t * move = (move_t *) (pChild->data); DoMove(move, game); //print //"Computer: move <x,y> to <i,j>[<k,l>...]\n". printf("Computer: move <%c,%d> to <%c,%d>", move->src.x, move->src.y, move->dest[0].x, move->dest[0].y); printf("\n"); } }
LRESULT __declspec(dllexport) __stdcall CALLBACK Win7KeysHook(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { int bWinKeyPressed = 0; unsigned short keyState1 = GetAsyncKeyState(VK_LWIN); unsigned short keyState2 = GetAsyncKeyState(VK_RWIN); bWinKeyPressed = (keyState1 | keyState2) & 0xFF00; if(bWinKeyPressed) { if (wParam == VK_LEFT || wParam == VK_RIGHT || wParam == VK_UP || wParam == VK_DOWN) { DoMove(wParam); } } } return CallNextHookEx(NULL, nCode, wParam, lParam); }
/* human move */ static PyObject * engine_hmove(PyObject *self, PyObject *args) { char *hmove; short rc; if (!PyArg_ParseTuple(args, "s", &hmove)) return NULL; winner = 0; oppptr = (oppptr + 1) % MINGAMEIN; rc = DoMove(hmove); /* in commondsp.c */ return Py_BuildValue("h", rc); }
void DoGameMove(GAME *Game, int Move, double Value, double Time) { if (! IsLegalMove(Game->Board,Move)) FatalError("Illegal move in DoGameMove()"); TurnTime = (Trust && Time >= 0.0) ? Time : Duration(TurnBegin,CurrentTime()); ElapsedTime[Game->Board->Colour>0] += TurnTime; DoMove(Game->Board,Move); Game->Move[Game->MoveNo].Move = Move; Game->Move[Game->MoveNo].Value = Value; Game->Move[Game->MoveNo].Time = TurnTime; Game->MoveNo++; Game->Move[Game->MoveNo].Move = NO_MOVE; TurnBegin = CurrentTime(); }
void ribi::Chess::GameWidget::Click(const boost::shared_ptr<const Square> square) { m_selector->Click(square,this); //BUG ? //Moves will only occur when there is both a cursor and a selected square if (!m_selector->GetSelected()) return; const boost::shared_ptr<const ribi::Chess::Square> from { m_selector->GetSelected() }; const boost::shared_ptr<const ribi::Chess::Square> to { m_selector->GetCursor() }; if (this->CanDoMove(from,to)) { DoMove(from,to); } }
void GameTree::PrintGame(FILE* f){ int i; char pre[100]; for(i=0;i<currDepth;i++) pre[i]=' '; sprintf(pre+i, "%3ld %2d", currIdx, currDepth); if(currIdx==0){ fprintf(f,"Size=%zu\n",size); fprintf(f,"%s %d %d %0.1f\n",pre,MoveValue(),val,IsWin()); }else{ fprintf(f,"%s %d %d %0.1f\n",pre,MoveValue(),val,IsWin()); } if(currDepth<depth) for(int i=0;i<breath;i++){ DoMove(i); PrintGame(f); UndoMove(); } }
// Left button is pressed - if cursor is over the m_pack then deal a card // otherwise if it is over a card pick it up ready to be dragged - see MouseMove() bool Game::LButtonDown(wxDC& dc, int x, int y) { m_srcPile = WhichPile(x, y); if (m_srcPile == m_pack) { Card* card = m_pack->RemoveTopCard(); if (card) { m_pack->Redraw(dc); card->TurnCard(faceup); m_discard->AddCard(dc, card); DoMove(dc, m_pack, m_discard); } m_srcPile = 0; } else if (m_srcPile) { m_srcPile->GetTopCardPos(m_xPos, m_yPos); m_xOffset = m_xPos - x; m_yOffset = m_yPos - y; // Copy the area under the card // Initialise the card bitmap to the background colour { wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmap); m_liftedCard = m_srcPile->RemoveTopCard(memoryDC, m_xPos, m_yPos); } // Draw the card in card bitmap ready for blitting onto // the screen { wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmapCard); m_liftedCard->Draw(memoryDC, 0, 0); } } return m_srcPile != 0; }
void ribi::reversi::Widget::DoMove(const boost::shared_ptr<const ribi::reversi::Move> move) noexcept { #ifndef NDEBUG assert(move); if(!CanDoMove(move)) { TRACE("ERROR"); TRACE(*this); TRACE(move->ToStr()); TRACE("ERROR"); } #endif assert(CanDoMove(move)); //Undo { const boost::shared_ptr<Widget> prev_widget { new Widget(*this) }; m_undo.push_back(std::make_pair(prev_widget,move)); assert(prev_widget->GetCurrentPlayer() == this->GetCurrentPlayer()); } //Actually do the move assert(move); if (boost::dynamic_pointer_cast<const ribi::reversi::MovePass>(move)) { DoMovePass(); } else { const boost::shared_ptr<const ribi::reversi::MovePlacePiece> place { boost::dynamic_pointer_cast<const ribi::reversi::MovePlacePiece>(move) }; assert(place); assert(CanDoMove(place->GetX(),place->GetY())); DoMove(place->GetX(),place->GetY()); } }
/* * DoLastEvent - process the last keystroke event */ vi_rc DoLastEvent( void ) { event *event; vi_rc rc; bool keep_sel; if( LastEvent >= MAX_EVENTS ) { rc = InvalidKey(); } else if( !EditFlags.Modeless && EditFlags.InsertModeActive ) { // UnselectRegion(); if( EditFlags.EscapedInsertChar ) { rc = IMChar(); } else if( InputKeyMaps[LastEvent].data != NULL && !InputKeyMaps[LastEvent].inuse ) { rc = StartInputKeyMap( LastEvent ); } else { rc = (EventList[LastEvent].ins)(); } } else if( !EditFlags.Modeless && KeyMaps[LastEvent].data != NULL && !KeyMaps[LastEvent].inuse ) { rc = DoKeyMap( LastEvent ); } else { event = &EventList[LastEvent]; keep_sel = event->b.keep_selection; if( event->b.keep_selection_maybe ) { if( SelRgn.selected ) { keep_sel = true; } } if( !keep_sel && !EditFlags.ScrollCommand ) { UnselectRegion(); } if( !EditFlags.ScrollCommand ) { ensureCursorDisplayed(); } rc = ERR_NO_ERR; switch( event->b.type ) { case EVENT_INS: if( EditFlags.Modeless ) { /* don't allow following cursor movements to affect seln */ keep_sel = SelRgn.selected; DeleteSelectedRegion(); SelRgn.selected = keep_sel; InsertLikeLast(); rc = event->rtn.ins(); DoneCurrentInsert( false ); SelRgn.selected = false; } else { if( !EditFlags.InsertModeActive ) { InsertLikeLast(); } rc = event->rtn.ins(); } break; case EVENT_OP: DoneCurrentInsert( true ); rc = doOperator( event ); break; case EVENT_REL_MOVE: case EVENT_ABS_MOVE: DoneCurrentInsert( true ); rc = DoMove( event ); break; case EVENT_MISC: DoneCurrentInsert( true ); rc = event->rtn.old(); break; } } return( rc ); } /* DoLastEvent */
// Called when the left button is released after dragging a card // Scan the piles to see if this card overlaps a pile and can be added // to the pile. If the card overlaps more than one pile on which it can be placed // then put it on the nearest pile. void Game::LButtonUp(wxDC& dc, int x, int y) { if (m_srcPile) { // work out the position of the dragged card x += m_xOffset; y += m_yOffset; Pile* nearestPile = 0; int distance = (CardHeight + CardWidth) * (CardHeight + CardWidth); // find the nearest pile which will accept the card int i; for (i = 0; i < 8; i++) { if (DropCard(x, y, m_foundations[i], m_liftedCard)) { if (m_foundations[i]->CalcDistance(x, y) < distance) { nearestPile = m_foundations[i]; distance = nearestPile->CalcDistance(x, y); } } } for (i = 0; i < 10; i++) { if (DropCard(x, y, m_bases[i], m_liftedCard)) { if (m_bases[i]->CalcDistance(x, y) < distance) { nearestPile = m_bases[i]; distance = nearestPile->CalcDistance(x, y); } } } // Restore the area under the card wxMemoryDC memoryDC; memoryDC.SelectObject(*m_bmap); dc.Blit(m_xPos, m_yPos, CardWidth, CardHeight, &memoryDC, 0, 0, wxCOPY); // Draw the card in its new position if (nearestPile) { // Add to new pile nearestPile->AddCard(dc, m_liftedCard); if (nearestPile != m_srcPile) { DoMove(dc, m_srcPile, nearestPile); } } else { // Return card to src pile m_srcPile->AddCard(dc, m_liftedCard); } m_srcPile = 0; m_liftedCard = 0; } }
// Called when the left button is double clicked // If a card is under the pointer and it can move elsewhere then move it. // Move onto a foundation as first choice, a populated base as second and // an empty base as third choice. // NB Cards in the m_pack cannot be moved in this way - they aren't in play // yet void Game::LButtonDblClk(wxDC& dc, int x, int y) { Pile* pile = WhichPile(x, y); if (!pile) return; // Double click on m_pack is the same as left button down if (pile == m_pack) { LButtonDown(dc, x, y); } else { Card* card = pile->GetTopCard(); if (card) { int i; // if the card is an ace then try to place it next // to an ace of the same suit if (card->GetPipValue() == 1) { for(i = 0; i < 4; i++) { Card* m_topCard = m_foundations[i]->GetTopCard(); if ( m_topCard ) { if (m_topCard->GetSuit() == card->GetSuit() && m_foundations[i + 4] != pile && m_foundations[i + 4]->GetTopCard() == 0) { pile->RemoveTopCard(dc); m_foundations[i + 4]->AddCard(dc, card); DoMove(dc, pile, m_foundations[i + 4]); return; } } } } // try to place the card on a foundation for(i = 0; i < 8; i++) { if (m_foundations[i]->AcceptCard(card) && m_foundations[i] != pile) { pile->RemoveTopCard(dc); m_foundations[i]->AddCard(dc, card); DoMove(dc, pile, m_foundations[i]); return; } } // try to place the card on a populated base for(i = 0; i < 10; i++) { if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile && m_bases[i]->GetTopCard()) { pile->RemoveTopCard(dc); m_bases[i]->AddCard(dc, card); DoMove(dc, pile, m_bases[i]); return; } } // try to place the card on any base for(i = 0; i < 10; i++) { if (m_bases[i]->AcceptCard(card) && m_bases[i] != pile) { pile->RemoveTopCard(dc); m_bases[i]->AddCard(dc, card); DoMove(dc, pile, m_bases[i]); return; } } } } }
VALUE DetermineZeroValue(POSITION position) { POSITION i,lowSeen,highSeen; POSITION numUndecided, oldNumUndecided, numNew; MOVELIST *moveptr, *headMove; POSITION child; VALUE childValue; POSITION numTot, numWin, numTie; int tieRemoteness, winRemoteness; //if (gTwoBits) // InitializeVisitedArray(); StoreValueOfPosition(position,Primitive(position)); MarkAsVisited(position); oldNumUndecided = 0; numUndecided = 1; numNew = 1; lowSeen = position; highSeen = lowSeen+1; while((numUndecided != oldNumUndecided) || (numNew != 0)) { oldNumUndecided = numUndecided; numUndecided = 0; numNew = 0; for(i = lowSeen; i <= highSeen; i++) { if(Visited(i)) { if(GetValueOfPosition(i) == undecided) { moveptr = headMove = GenerateMoves(i); numTot = numWin = numTie = 0; tieRemoteness = winRemoteness = REMOTENESS_MAX; while(moveptr != NULL) { child = DoMove(i,moveptr->move); numTot++; if(Visited(child)) childValue = GetValueOfPosition(child); else{ childValue = Primitive(child); numNew++; MarkAsVisited(child); StoreValueOfPosition(child,childValue); if(childValue != undecided) { SetRemoteness(child,0); } if(child < lowSeen) lowSeen = child; if(child > highSeen) highSeen = child + 1; } if(childValue == lose) { StoreValueOfPosition(i,win); if(Remoteness(i) > Remoteness(child)+1) SetRemoteness(i,Remoteness(child)+1); } if(childValue == win) { numWin++; if(Remoteness(child) < winRemoteness) { winRemoteness = Remoteness(child); } } if(childValue == tie) { numTie++; if(Remoteness(child) < tieRemoteness) { tieRemoteness = Remoteness(child); } } moveptr = moveptr->next; } FreeMoveList(headMove); if((numTot != 0) && (numTot == numWin + numTie)) { if(numTie == 0) { SetRemoteness(i, winRemoteness+1); StoreValueOfPosition(i,lose); }else{ SetRemoteness(i, tieRemoteness+1); StoreValueOfPosition(i,tie); } } if(GetValueOfPosition(i) == undecided) numUndecided++; } } } printf("\nnumUndecided: " POSITION_FORMAT ", diff: " POSITION_FORMAT ", numNew: " POSITION_FORMAT ", lowSeen: " POSITION_FORMAT ", highSeen: " POSITION_FORMAT, numUndecided,numUndecided - oldNumUndecided,numNew,lowSeen,highSeen); } for(i = 0; i < gNumberOfPositions; i++) { if(Visited(i) && (GetValueOfPosition(i) == undecided)) { SetRemoteness(i,REMOTENESS_MAX); StoreValueOfPosition(i, tie); } UnMarkAsVisited(i); } return GetValueOfPosition(position); }
/* * IMCursorKey - handle cursor keys in insert mode */ vi_rc IMCursorKey( void ) { int wlen; event *ev; int type; wlen = WorkLine->len + 1; if( wlen == 0 ) { wlen = CurrentLine->len + 1; } /* * handle movement on the same line */ switch( LastEvent ) { case VI_KEY( HOME ): GoToColumn( 1, wlen ); abbrevCnt = 0; return( ERR_NO_ERR ); case VI_KEY( END ): GoToColumnOK( wlen ); abbrevCnt = 0; return( ERR_NO_ERR ); case VI_KEY( LEFT ): GoToColumn( CurrentPos.column - 1, wlen ); abbrevCnt = 0; return( ERR_NO_ERR ); case VI_KEY( RIGHT ): GoToColumn( CurrentPos.column + 1, wlen ); abbrevCnt = 0; return( ERR_NO_ERR ); } /* * handle movement that leaves the current line */ ev = &EventList[LastEvent]; if( EditFlags.Modeless ) { type = ev->alt_b.type; } else { type = ev->b.type; } if( needNewUndoForLine ) { if( type == EVENT_REL_MOVE || type == EVENT_ABS_MOVE ) { DoMove( ev ); } else { if( EditFlags.Modeless ) { ev->alt_rtn.old(); } else { ev->rtn.old(); } } return( ERR_NO_ERR ); } if( CurrentPos.column > WorkLine->len ) { GoToColumnOK( WorkLine->len + 1 ); } doneWithCurrentLine(); if( type == EVENT_REL_MOVE || type == EVENT_ABS_MOVE ) { DoMove( ev ); } else { if( EditFlags.Modeless ) { ev->alt_rtn.old(); } else { ev->rtn.old(); } } needNewUndoForLine = TRUE; abbrevCnt = 0; return( ERR_NO_ERR ); } /* IMCursorKey */
static int quies(struct SearchData *sd, int alpha, int beta, int depth) { struct Position *p = sd->position; int best; int move; int talpha; int tmp; QNodes++; EnterNode(sd); /* max search depth reached */ if (sd->ply >= MaxDepth || Repeated(p, FALSE)) { best = 0; goto EXIT; } /* * Probe recognizers. If the probe is successful, use the * recognizer score as evaluation score. * * Otherwise, use ScorePosition() */ switch (ProbeRecognizer(p, &tmp)) { case ExactScore: best = tmp; goto EXIT; case LowerBound: best = tmp; if (best >= beta) { goto EXIT; } break; case UpperBound: best = tmp; if (best <= alpha) { goto EXIT; } break; default: best = ScorePosition(p, alpha, beta); break; } if (best >= beta) { goto EXIT; } talpha = MAX(alpha, best); while ((move = NextMoveQ(sd, alpha) ) != M_NONE) { DoMove(p, move); if (InCheck(p, OPP(p->turn))) UndoMove(p, move); else { tmp = -quies(sd, -beta, -talpha, depth-1); UndoMove(p, move); if (tmp >= beta) { best = tmp; goto EXIT; } if (tmp > best) { best = tmp; if (best > talpha) { talpha = best; } } } } EXIT: LeaveNode(sd); return best; }
LRESULT CALLBACK MenuDrawProc(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { static MENUITEM *start; static BOOL dragging; static HCURSOR oldcurs; static struct resRes *resData; static struct propertyFuncs *resFuncs; POINT mouse; RECT r; PAINTSTRUCT paint; HDC dc; LPCREATESTRUCT createStruct; struct resRes *menuData; int i; struct menuUndo *undo; switch (iMessage) { case WM_MDIACTIVATE: if ((HWND)lParam == hwnd) { doMaximize(); } break; case WM_SETFOCUS: menuData = (struct resRes *)GetWindowLong(hwnd, 0); SetResourceProperties(resData, resFuncs); break; case EM_CANUNDO: menuData = (struct resRes *)GetWindowLong(hwnd, 0); return menuData->gd.undoData != NULL; case WM_KEYDOWN: menuData = (struct resRes *)GetWindowLong(hwnd, 0); switch (wParam) { case 'S': if (GetKeyState(VK_CONTROL) &0x80000000) { PostMessage(hwnd, WM_COMMAND, IDM_SAVE, 0); } break; case 'Z': if (GetKeyState(VK_CONTROL) &0x80000000) { PostMessage(hwnd, WM_COMMAND, IDM_UNDO, 0); } break; } break; case WM_CREATE: createStruct = (LPCREATESTRUCT)lParam; menuData = (struct resRes *)((LPMDICREATESTRUCT)(createStruct->lpCreateParams))->lParam; SetWindowLong(hwnd, 0, (long)menuData); menuData->activeHwnd = hwnd; resData = menuData; resFuncs = &menuFuncs; MarkUnexpanded(menuData->resource->u.menu->items); break; case WM_CLOSE: SendMessage(hwndSrcTab, TABM_REMOVE, 0, (LPARAM)hwnd); break; case WM_DESTROY: menuData = (struct resRes *)GetWindowLong(hwnd, 0); menuData->activeHwnd = NULL; undo = menuData->gd.undoData; menuData->gd.undoData = NULL; if (undo) menuData->gd.cantClearUndo = TRUE; while (undo) { struct menuUndo *next = undo->next; free(undo); undo = next; } break; // case WM_LBUTTONUP: case WM_MBUTTONUP: case WM_MBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_MBUTTONDBLCLK: case WM_RBUTTONUP: SetFocus(hwnd); return 1; case WM_PAINT: menuData = (struct resRes *)GetWindowLong(hwnd, 0); GetClientRect(hwnd, &r); dc = BeginPaint(hwnd, &paint); DoPaint(hwnd, dc, &paint, &r, menuData); EndPaint(hwnd, &paint); break; case WM_RBUTTONDOWN: menuData = (struct resRes *)GetWindowLong(hwnd, 0); SendMessage(hwnd, WM_COMMAND, ID_EDIT + (EN_KILLFOCUS << 16), 0); mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); i = menuHitTest(hwnd, menuData, mouse); if (i) { HMENU menu, popup; SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_EDIT, CBN_KILLFOCUS), 0); menu = LoadMenuGeneric(hInstance, "RESMENUMENU"); if (i & 2) EnableMenuItem(menu, IDM_DELETE, MF_BYCOMMAND | MF_GRAYED); if (i & 4) EnableMenuItem(menu, IDM_INSERT_SEPARATOR, MF_BYCOMMAND | MF_GRAYED); menuData->gd.selectedRow = mouse.y + menuData->gd.scrollPos.y; menuData->gd.selectedColumn = mouse.x + menuData->gd.scrollPos.x; popup = GetSubMenu(menu, 0); ClientToScreen(hwnd, &mouse); InsertBitmapsInMenu(popup); TrackPopupMenuEx(popup, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_LEFTBUTTON, mouse.x, mouse.y, hwnd, NULL); DestroyMenu(menu); } return 1; case WM_LBUTTONDBLCLK: SendMessage(hwnd, WM_COMMAND, ID_EDIT + (EN_KILLFOCUS << 16), 0); SetFocus(hwnd); menuData = (struct resRes *)GetWindowLong(hwnd, 0); mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); SelectSubmenu(hwnd, menuData, mouse, TRUE); break; case WM_MOUSEMOVE: if (dragging) { menuData = (struct resRes *)GetWindowLong(hwnd, 0); mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); menuData->gd.selectedMenu = start; i = menuHitTest(hwnd, menuData, mouse); if (!oldcurs) oldcurs = GetCursor(); SetCursor(i & 8 ? dragCur : noCur); } break; case WM_LBUTTONDOWN: SetFocus(hwnd); menuData = (struct resRes *)GetWindowLong(hwnd, 0); SendMessage(hwnd, WM_COMMAND, ID_EDIT + (EN_KILLFOCUS << 16), 0); mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); i = menuHitTest(hwnd, menuData, mouse); if (i & 1) { resData = menuData; resFuncs = &menuItemFuncs; start = menuData->gd.selectedMenu; dragging = TRUE; SetCapture(hwnd); } else { resData = menuData; resFuncs = &menuFuncs; } SetResourceProperties(resData, resFuncs); break; case WM_LBUTTONUP: if (dragging) { dragging = FALSE; ReleaseCapture(); } menuData = (struct resRes *)GetWindowLong(hwnd, 0); if (oldcurs) { if (GetCursor() == dragCur) { mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); i = menuHitTest(hwnd, menuData, mouse); DoMove(menuData, start, menuData->gd.selectedMenu); } SetCursor(oldcurs); oldcurs = NULL; } else { SendMessage(hwnd, WM_COMMAND, ID_EDIT + (EN_KILLFOCUS << 16), 0); SetFocus(hwnd); mouse.x = LOWORD(lParam); mouse.y = HIWORD(lParam); SelectSubmenu(hwnd, menuData, mouse, FALSE); } break; case WM_COMMAND: menuData = (struct resRes *)GetWindowLong(hwnd, 0); switch (LOWORD(wParam)) { case ID_EDIT: if (HIWORD(wParam) == EN_KILLFOCUS) { static BOOL inKillFocus; if (menuData->gd.editWindow && !inKillFocus) { char buf[256]; char buf2[256]; UndoChange(menuData, menuData->gd.selectedMenu); buf[GetWindowText(menuData->gd.editWindow, buf, sizeof(buf))] = 0; StringWToA(buf2, menuData->gd.selectedMenu->text, wcslen(menuData->gd.selectedMenu->text)); if (strcmp(buf, buf2)) { ResGetHeap(workArea, menuData); if (menuData->gd.selectedMenu->id) ResGetMenuItemName(menuData->gd.selectedMenu->id, buf); StringAsciiToWChar(&menuData->gd.selectedMenu->text, buf, strlen(buf)); ResSetDirty(menuData); } InvalidateRect(hwnd, 0, FALSE); inKillFocus = TRUE; DestroyWindow(menuData->gd.editWindow); inKillFocus = FALSE; menuData->gd.editWindow = NULL; } } break; case IDM_DELETE: case IDM_INSERT: case IDM_INSERT_SEPARATOR: InsertDelete(hwnd, menuData, LOWORD(wParam)); break; case IDM_SAVE: if (menuData->resource->changed) { ResSaveCurrent(workArea, menuData); } break; case IDM_UNDO: DoUndo(menuData); break; } break; case WM_VSCROLL: menuData = (struct resRes *)GetWindowLong(hwnd, 0); switch (LOWORD(wParam)) { case SB_BOTTOM: menuData->gd.scrollPos.y = menuData->gd.scrollMax.y; break; case SB_TOP: menuData->gd.scrollPos.y = 0; break; case SB_LINEDOWN: menuData->gd.scrollPos.y += 8; break; case SB_LINEUP: menuData->gd.scrollPos.y -= 8; break; case SB_PAGEDOWN: menuData->gd.scrollPos.y += 64; break; case SB_PAGEUP: menuData->gd.scrollPos.y -= 64; break; case SB_ENDSCROLL: return 0; case SB_THUMBPOSITION: case SB_THUMBTRACK: { SCROLLINFO si; memset(&si, 0, sizeof(si)); si.cbSize = sizeof(si); si.fMask = SIF_TRACKPOS; GetScrollInfo(hwnd, SB_VERT, &si); menuData->gd.scrollPos.y = si.nTrackPos; } break; default: return 0; } if (menuData->gd.scrollPos.y < 0) menuData->gd.scrollPos.y = 0; if (menuData->gd.scrollPos.y >= menuData->gd.scrollMax.y) menuData->gd.scrollPos.y = menuData->gd.scrollMax.y; SetScrollPos(hwnd, SB_VERT, menuData->gd.scrollPos.y, TRUE); InvalidateRect(hwnd,0,FALSE); return 0; case WM_HSCROLL: menuData = (struct resRes *)GetWindowLong(hwnd, 0); switch (LOWORD(wParam)) { case SB_LEFT: menuData->gd.scrollPos.x = 0; break; case SB_RIGHT: menuData->gd.scrollPos.x = menuData->gd.scrollMax.x; break; case SB_LINELEFT: menuData->gd.scrollPos.x -= 8; break; case SB_LINERIGHT: menuData->gd.scrollPos.x += 8; break; case SB_PAGERIGHT: menuData->gd.scrollPos.x += 64; break; case SB_PAGELEFT: menuData->gd.scrollPos.x -= 64; break; case SB_ENDSCROLL: return 0; case SB_THUMBPOSITION: case SB_THUMBTRACK: { SCROLLINFO si; memset(&si, 0, sizeof(si)); si.cbSize = sizeof(si); si.fMask = SIF_TRACKPOS; GetScrollInfo(hwnd, SB_HORZ, &si); menuData->gd.scrollPos.x = si.nTrackPos; } break; } if (menuData->gd.scrollPos.x < 0) menuData->gd.scrollPos.x = 0; if (menuData->gd.scrollPos.x >= menuData->gd.scrollMax.x) menuData->gd.scrollPos.x = menuData->gd.scrollMax.x; SetScrollPos(hwnd, SB_HORZ, menuData->gd.scrollPos.x, TRUE); SetWindowPos(menuData->gd.childWindow, NULL, menuData->gd.origin.x - menuData->gd.scrollPos.x, menuData->gd.origin.y - menuData->gd.scrollPos.y, 0,0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); InvalidateRect(hwnd,0,FALSE); return 0; case WM_SIZE: InvalidateRect(hwnd, 0, FALSE); break; default: break; } return DefMDIChildProc(hwnd, iMessage, wParam, lParam); }
static int negascout(struct SearchData *sd, int alpha, int beta, const int depth, int node_type #if MP ,int exclusiveP #endif /* MP */ ) { struct Position *p = sd->position; struct SearchStatus *st; int best = -INF; int bestm = M_NONE; int tmp; int talpha; int incheck; int lmove; int move; int extend = 0; int threat = FALSE; int reduce_extensions; int next_type; int was_futile = FALSE; #if FUTILITY int is_futile; int optimistic = 0; #endif #if MP int deferred_cnt = 0; int deferred_list[MAX_DEFERRED]; int deferred_depth[MAX_DEFERRED]; #endif EnterNode(sd); Nodes++; /* check for search termination */ if (sd->master && TerminateSearch(sd)) { AbortSearch = TRUE; goto EXIT; } /* max search depth reached */ if (sd->ply >= MaxDepth) goto EXIT; /* * Check for insufficent material or theoretical draw. */ if ( /* InsufMat(p) || CheckDraw(p) || */ Repeated(p, FALSE)) { best = 0; goto EXIT; } /* * check extension */ incheck = InCheck(p, p->turn); if (incheck && p->material[p->turn] > 0) { extend += CheckExtend(p); ChkExt++; } /* * Check the hashtable */ st = sd->current; HTry++; #if MP switch (ProbeHT(p->hkey, &tmp, depth, &(st->st_hashmove), &threat, sd->ply, exclusiveP, sd->localHashTable)) #else switch (ProbeHT(p->hkey, &tmp, depth, &(st->st_hashmove), &threat, sd->ply)) #endif /* MP */ { case ExactScore: HHit++; best = tmp; goto EXIT; case UpperBound: if (tmp <= alpha) { HHit++; best = tmp; goto EXIT; } break; case LowerBound: if (tmp >= beta) { HHit++; best = tmp; goto EXIT; } break; case Useless: threat = !incheck && MateThreat(p, OPP(p->turn)); break; #if MP case OnEvaluation: best = -ON_EVALUATION; goto EXIT; #endif } /* * Probe EGTB */ if (depth > EGTBDepth && ProbeEGTB(p, &tmp, sd->ply)) { best = tmp; goto EXIT; } /* * Probe recognizers */ switch (ProbeRecognizer(p, &tmp)) { case ExactScore: best = tmp; goto EXIT; case LowerBound: if (tmp >= beta) { best = tmp; goto EXIT; } break; case UpperBound: if (tmp <= alpha) { best = tmp; goto EXIT; } break; } #if NULLMOVE /* * Null move search. * See Christian Donninger, "Null Move and Deep Search" * ICCA Journal Volume 16, No. 3, pp. 137-143 */ if (!incheck && node_type == CutNode && !threat) { int next_depth; int nms; next_depth = depth - ReduceNullMove; if (next_depth > 0) { next_depth = depth - ReduceNullMoveDeep; } DoNull(p); if (next_depth < 0) { nms = -quies(sd, -beta, -beta+1, 0); } else { #if MP nms = -negascout(sd, -beta, -beta+1, next_depth, AllNode, 0); #else nms = -negascout(sd, -beta, -beta+1, next_depth, AllNode); #endif } UndoNull(p); if (AbortSearch) goto EXIT; if (nms >= beta) { if (p->nonPawn[p->turn] >= Value[Queen]) { best = nms; goto EXIT; } else { if (next_depth < 0) { nms = quies(sd, beta-1, beta, 0); } else { #if MP nms = negascout(sd, beta-1, beta, next_depth, CutNodeNoNull, 0); #else nms = negascout(sd, beta-1, beta, next_depth, CutNodeNoNull); #endif } if (nms >= beta) { best = nms; goto EXIT; } else { extend += ExtendZugzwang; ZZExt++; } } } else if (nms <= -CMLIMIT) { threat = TRUE; } } #endif /* NULLMOVE */ lmove = (p->actLog-1)->gl_Move; reduce_extensions = (sd->ply > 2*sd->depth); talpha = alpha; switch (node_type) { case AllNode: next_type = CutNode; break; case CutNode: case CutNodeNoNull: next_type = AllNode; break; default: next_type = PVNode; break; } #if FUTILITY is_futile = !incheck && !threat && alpha < CMLIMIT && alpha > -CMLIMIT; if (is_futile) { if (p->turn == White) { optimistic = MaterialBalance(p) + MaxPos; } else { optimistic = -MaterialBalance(p) + MaxPos; } } #endif /* FUTILITY */ /* * Internal iterative deepening. If we do not have a move, we try * a shallow search to find a good candidate. */ if (depth > 2*OnePly && ((alpha + 1) != beta) && !LegalMove(p, st->st_hashmove)) { int useless; #if MP useless = negascout(sd, alpha, beta, depth-2*OnePly, PVNode, 0); #else useless = negascout(sd, alpha, beta, depth-2*OnePly, PVNode); #endif st->st_hashmove = sd->pv_save[sd->ply+1]; } /* * Search all legal moves */ while ((move = incheck ? NextEvasion(sd) : NextMove(sd)) != M_NONE) { int next_depth = extend; if (move & M_CANY && !MayCastle(p, move)) continue; /* * recapture extension */ if ((move & M_CAPTURE) && (lmove & M_CAPTURE) && M_TO(move) == M_TO(lmove) && IsRecapture(p->piece[M_TO(move)], (p->actLog-1)->gl_Piece)) { RCExt += 1; next_depth += ExtendRecapture[TYPE(p->piece[M_TO(move)])]; } /* * passed pawn push extension */ if (TYPE(p->piece[M_FROM(move)]) == Pawn && p->nonPawn[OPP(p->turn)] <= Value[Queen]) { int to = M_TO(move); if (((p->turn == White && to >= a7) || (p->turn == Black && to <= h2)) && IsPassed(p, to, p->turn) && SwapOff(p, move) >= 0) { next_depth += ExtendPassedPawn; PPExt += 1; } } /* * limit extensions to sensible range. */ if (reduce_extensions) next_depth /= 2; next_depth += depth - OnePly; #if FUTILITY /* * Futility cutoffs */ if (is_futile) { if (next_depth < 0 && !IsCheckingMove(p, move)) { tmp = optimistic + ScoreMove(p, move); if (tmp <= alpha) { if (tmp > best) { best = tmp; bestm = move; was_futile = TRUE; } continue; } } #if EXTENDED_FUTILITY /* * Extended futility cutoffs and limited razoring. * See Ernst A. Heinz, "Extended Futility Pruning" * ICCA Journal Volume 21, No. 2, pp 75-83 */ else if (next_depth >= 0 && next_depth < OnePly && !IsCheckingMove(p, move)) { tmp = optimistic + ScoreMove(p, move) + (3*Value[Pawn]); if (tmp <= alpha) { if (tmp > best) { best = tmp; bestm = move; was_futile = TRUE; } continue; } } #if RAZORING else if (next_depth >= OnePly && next_depth < 2*OnePly && !IsCheckingMove(p, move)) { tmp = optimistic + ScoreMove(p, move) + (6*Value[Pawn]); if (tmp <= alpha) { next_depth -= OnePly; } } #endif /* RAZORING */ #endif /* EXTENDED_FUTILITY */ } #endif /* FUTILITY */ DoMove(p, move); if (InCheck(p, OPP(p->turn))) { UndoMove(p, move); } else { /* * Check extension */ if (p->material[p->turn] > 0 && InCheck(p, p->turn)) { next_depth += (reduce_extensions) ? ExtendInCheck>>1 : ExtendInCheck; } /* * Recursively search this position. If depth is exhausted, use * quies, otherwise use negascout. */ if (next_depth < 0) { tmp = -quies(sd, -beta, -talpha, 0); } else if (bestm != M_NONE && !was_futile) { #if MP tmp = -negascout(sd, -talpha-1, -talpha, next_depth, next_type, bestm != M_NONE); if (tmp != ON_EVALUATION && tmp > talpha && tmp < beta) { tmp = -negascout(sd, -beta, -tmp, next_depth, node_type == PVNode ? PVNode : AllNode, bestm != M_NONE); } #else tmp = -negascout(sd, -talpha-1, -talpha, next_depth, next_type); if (tmp > talpha && tmp < beta) { tmp = -negascout(sd, -beta, -tmp, next_depth, node_type == PVNode ? PVNode : AllNode); } #endif /* MP */ } else { #if MP tmp = -negascout(sd, -beta, -talpha, next_depth, next_type, bestm != M_NONE); #else tmp = -negascout(sd, -beta, -talpha, next_depth, next_type); #endif /* MP */ } UndoMove(p, move); if (AbortSearch) goto EXIT; #if MP if (tmp == ON_EVALUATION) { /* * This child is ON_EVALUATION. Remember move and * depth. */ deferred_list[deferred_cnt] = move; deferred_depth[deferred_cnt] = next_depth; deferred_cnt++; } else { #endif /* MP */ /* * beta cutoff, enter move in Killer/Countermove table */ if (tmp >= beta) { if (!(move & M_TACTICAL)) { PutKiller(sd, move); sd->counterTab[p->turn][lmove & 4095] = move; } StoreResult(sd, tmp, alpha, beta, move, depth, threat); best = tmp; goto EXIT; } /* * Improvement on best move to date */ if (tmp > best) { best = tmp; bestm = move; was_futile = FALSE; if (best > talpha) { talpha = best; } } next_type = CutNode; #if MP } #endif /* MP */ } }