Action AIAgent::iterativeDeepeningSearch() { int depth = 1; depthLimitedSearch(depth); int score = alphaBetaSearch(gameTree->getRoot(), -1000000000, 100000000, ai_player); Action _action = findMove(score); for (; depth < 6; depth++) { depthLimitedSearch(depth); score = alphaBetaSearch(gameTree->getRoot(), -1000000000, 100000000, ai_player); _action = findMove(score); if (score == 10000000) { return _action; } } return _action; }
void printHints(Game* game) { char cmd[5]; assert(game); findMove(game, cmd); printf("[HINT] Try moving: %c%c%c%c\n\n",cmd[0],cmd[1],cmd[2],cmd[3]); }
bool Sudoku::solve() { if(fin()){ return true; } while(1){ Move m = findMove(); if(m.val == 0){ //no more moves return false; } Sudoku scopy = *this; bool result = scopy.applyMove(m); if(!result){ cand[m.ii][m.jj][m.val] = false; continue; } result = scopy.solve(); if(result){ *this = scopy; return true; }else{ cand[m.ii][m.jj][m.val] = false; } } return false; }
void AbstractGame::executeMove(PositionSet markedPositions) { Move m = findMove(markedPositions); if(m == NULL) { showError(_T("Illegal move:%s"), sprintbin(markedPositions).cstr()); return; } doMove(m); m_playerInTurn = GETOPPONENT(m_playerInTurn); }
void getDecisionFromAI(Game* game, char* cmd) { printf("Computer: I am thinking. . .\n"); findMove(game, cmd); printf("Computer: Done thinking! My move will be: %c%c%c%c\n\n", cmd[0], cmd[1], cmd[2], cmd[3]); }
int SELECTION_TOOL::Main( const TOOL_EVENT& aEvent ) { // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { // Should selected items be added to the current selection or // become the new selection (discarding previously selected items) m_additive = evt->Modifier( MD_SHIFT ); // single click? Select single object if( evt->IsClick( BUT_LEFT ) ) { if( evt->Modifier( MD_CTRL ) && !m_editModules ) { highlightNet( evt->Position() ); } else { if( !m_additive ) clearSelection(); selectCursor( evt->Position() ); } } // right click? if there is any object - show the context menu else if( evt->IsClick( BUT_RIGHT ) ) { bool emptySelection = m_selection.Empty(); if( emptySelection ) selectCursor( evt->Position() ); CONTEXT_MENU& contextMenu = m_menu.Generate( m_selection ); if( contextMenu.GetMenuItemCount() > 0 ) SetContextMenu( &contextMenu, CMENU_NOW ); m_preliminary = emptySelection; } // double click? Display the properties window else if( evt->IsDblClick( BUT_LEFT ) ) { if( m_selection.Empty() ) selectCursor( evt->Position() ); m_toolMgr->RunAction( COMMON_ACTIONS::properties ); } // drag with LMB? Select multiple objects (or at least draw a selection box) or drag them else if( evt->IsDrag( BUT_LEFT ) ) { if( m_additive ) { m_preliminary = false; selectMultiple(); } else if( m_selection.Empty() ) { m_preliminary = false; // There is nothing selected, so try to select something if( !selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ), false ) ) { // If nothings has been selected or user wants to select more // draw the selection box selectMultiple(); } else { m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); } } else { // Check if dragging has started within any of selected items bounding box if( selectionContains( evt->Position() ) ) { // Yes -> run the move tool and wait till it finishes m_toolMgr->InvokeTool( "pcbnew.InteractiveEdit" ); } else { // No -> clear the selection list clearSelection(); } } } else if( evt->IsAction( &COMMON_ACTIONS::selectionCursor ) ) { // GetMousePosition() is used, as it is independent of snapping settings selectCursor( getView()->ToWorld( getViewControls()->GetMousePosition() ) ); } else if( evt->IsAction( &COMMON_ACTIONS::find ) ) { find( *evt ); } else if( evt->IsAction( &COMMON_ACTIONS::findMove ) ) { findMove( *evt ); } else if( evt->IsAction( &COMMON_ACTIONS::selectItem ) ) { SelectItem( *evt ); } else if( evt->IsAction( &COMMON_ACTIONS::unselectItem ) ) { UnselectItem( *evt ); } else if( evt->IsCancel() || evt->Action() == TA_UNDO_REDO || evt->IsAction( &COMMON_ACTIONS::selectionClear ) ) { clearSelection(); } else if( evt->IsAction( &COMMON_ACTIONS::selectConnection ) ) { selectConnection( *evt ); } else if( evt->IsAction( &COMMON_ACTIONS::selectCopper ) ) { selectCopper( *evt ); } else if( evt->IsAction( &COMMON_ACTIONS::selectNet ) ) { selectNet( *evt ); } else if( evt->Action() == TA_CONTEXT_MENU_CLOSED ) { if( m_preliminary ) clearSelection(); } } // This tool is supposed to be active forever assert( false ); return 0; }
void CApp::OnLButtonDown(int mX, int mY) { if(state_helpScreen) { state_helpScreen = false; state_welcomeScreen = true; } if(state_welcomeScreen) { welcomeScreenLogic(mX, mY); } else if(state_storyScreen) { state_storyScreen = false; state_welcomeScreen = true; } else if(state_selectElement1) { int chosenElement = findElement(mX, mY); if(chosenElement != -1) { state_selectElement1 = false; state_selectElement2 = true; addPokemon(chosenElement, "Pokemon 1"); } } else if(state_selectElement2) { int chosenElement = findElement(mX, mY); if(chosenElement != -1) { state_selectElement2 = false; state_selectElement3 = true; addPokemon(chosenElement, "Pokemon 2"); } } else if(state_selectElement3) { int chosenElement = findElement(mX, mY); if(chosenElement != -1) { state_selectElement3 = false; state_selectMoves1 = true; addPokemon(chosenElement, "Pokemon 3"); } } else if(state_selectMoves1) { if(state_elementSelected) { chosenMove = findMove(mX, mY, chosenMoveElement); if(chosenMove != -1) {// && chosenMove >= 0 && chosenMove <= 35 if(addMove(chosenMove, 0)) { //If the poke now has 4 moves state_selectMoves1 = false; state_selectMoves2 = true; state_elementSelected = false; state_selectTheMove = -1; player2->team.at(0)->pokeMoveSet.push_back(new Move()); player2->team.at(0)->pokeMoveSet.push_back(new Move()); player2->team.at(0)->pokeMoveSet.push_back(new Move()); player2->team.at(0)->pokeMoveSet.push_back(new Move()); } else { state_elementSelected = false; state_selectTheMove = -1; } } else { state_elementSelected = false; state_selectTheMove = -1; } } else { chosenMoveElement = findMoveElement(mX, mY); if(chosenMoveElement != -1) state_elementSelected = true; } } else if(state_selectMoves2) { if(state_elementSelected) { chosenMove = findMove(mX, mY, chosenMoveElement); if(chosenMove != -1) {// && chosenMove >= 0 && chosenMove <= 35 if(addMove(chosenMove, 1)) { //If the poke now has 4 moves state_selectMoves2 = false; state_selectMoves3 = true; state_elementSelected = false; state_selectTheMove = -1; player2->team.at(1)->pokeMoveSet.push_back(new Move()); player2->team.at(1)->pokeMoveSet.push_back(new Move()); player2->team.at(1)->pokeMoveSet.push_back(new Move()); player2->team.at(1)->pokeMoveSet.push_back(new Move()); } else { state_elementSelected = false; state_selectTheMove = -1; } } else { state_elementSelected = false; state_selectTheMove = -1; } } else { chosenMoveElement = findMoveElement(mX, mY); if(chosenMoveElement != -1) state_elementSelected = true; } } else if(state_selectMoves3) { if(state_elementSelected) { chosenMove = findMove(mX, mY, chosenMoveElement); if(chosenMove != -1) {// && chosenMove >= 0 && chosenMove <= 35 if(addMove(chosenMove, 2)) { //If the poke now has 4 moves state_selectMoves3 = false; state_elementSelected = false; state_selectTheMove = -1; player2->team.at(2)->pokeMoveSet.push_back(new Move()); player2->team.at(2)->pokeMoveSet.push_back(new Move()); player2->team.at(2)->pokeMoveSet.push_back(new Move()); player2->team.at(2)->pokeMoveSet.push_back(new Move()); } else { state_elementSelected = false; state_selectTheMove = -1; } } else { state_elementSelected = false; state_selectTheMove = -1; } } else { chosenMoveElement = findMoveElement(mX, mY); if(chosenMoveElement != -1) state_elementSelected = true; } } else if(state_player1Win) { state_welcomeScreen = true; state_selectElement1 = false; state_selectElement2 = false; state_selectElement3 = false; state_moveOverlay = false; state_switchPokemon = false; state_player1Win = false; state_player2Win = false; } else if(state_player2Win) { state_welcomeScreen = true; state_selectElement1 = false; state_selectElement2 = false; state_selectElement3 = false; state_moveOverlay = false; state_switchPokemon = false; state_player1Win = false; state_player2Win = false; } else {//Battle State /* if(currentBattle->poke1->taunted) { //Not needed yet as CPU is already random currentBattle->poke1Move = currentBattle->poke1->getMove(rand() % 4); currentBattle->player1Attack = true; player1Ready = true; setBattleOff = false; return; }//Does being taunted or beatdown take priority?*/ if(currentBattle->beatdown1On) { currentBattle->player1Attack = true; player1Ready = true; setBattleOff = false; return; } if(currentBattle->powerFlare1) { currentBattle->player1Attack = false; player1Ready = true; setBattleOff = false; currentBattle->powerFlare1 = false; return; } if(state_switchPokemon == true) { setBattleOff = false; if(waitingForKnockoutSwitch) { //Have to check if pokemon were knocked out before the rest of the checks, as the future checks will modify the values setBattleOff = true; } switchPokemonLogic(mX, mY); } else if(state_moveOverlay == true) { moveOverlayLogic(mX, mY); } if( atInitiateLocation(mX, mY) && hitByTimerPoke1 == 0 && hitByTimerPoke2 == 0) { state_moveOverlay = true; } else { state_moveOverlay = false; } } }
bool AvailableMoves::contains(Square *square) const { return findMove(square) != nullptr; }