MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QGridLayout *MainLayout= new QGridLayout; QWidget *widget= new QWidget; HerosUP = new NS_IHM::IHM_Heros::IHM_Heros(); HerosDOWN = new NS_IHM::IHM_Heros::IHM_Heros(); HandUP = new NS_IHM::IHM_Hand::IHM_Hand(); HandDOWN = new NS_IHM::IHM_Hand::IHM_Hand(); BoardUP = new NS_IHM::IHM_Board::IHM_Board(); BoardDOWN = new NS_IHM::IHM_Board::IHM_Board(); BoutonNext= new QPushButton("Passer"); QWidget::connect(BoutonNext, SIGNAL(clicked()), this, SLOT(ChangePlayer())); int i; for(i=0;i<10;i++) { QObject::connect(HandDOWN->getHand().value(i), SIGNAL(clicked()), this, SLOT(JouerCarte())); } for(i=0;i<5;i++) { QObject::connect(BoardDOWN->getBoardCard().value(i), SIGNAL(clicked()), this, SLOT(Attaquer())); } setCentralWidget(widget); QPushButton *BoutonPlay = new QPushButton("Jouer !"); QWidget::connect(BoutonPlay, SIGNAL(clicked()), this, SLOT(Game())); MainLayout->addWidget(BoutonPlay); // Ajout du bouton widget->setLayout(MainLayout); Joueur1 = new Heros("Jaina", QApplication::applicationDirPath()+"/Ressources/Jaina.png"); Joueur2 = new Heros("Garrosh", QApplication::applicationDirPath()+"/Ressources/Garrosh.png"); }
bool GameLogicManager::Holed(Player* p, bool correct, GeneralBall* ball) { if (correct) { p->Holed(ball->getId()); ChangePlayer(); srand((unsigned int)time(0)); GeneralBall* specialBall; int xPos = rand() % BOARD_WIDTH + BOARD_LEFT_MOST; int yPos = rand() % BOARD_HEIGHT + BOARD_TOP_MOST; if (rand() & 1) { specialBall = new ExplosionBall(xPos, yPos, mBoard->mFriction, mGeneralBallList); specialBall->Initialize(); } else { specialBall = new FrictionBall(xPos, yPos, mBoard->mFriction); specialBall->Initialize(); } mSpecialBallList.push_back(specialBall); mBoard->setFriction(1.0f); return true; } ball->setDroppedDead(false); ball->setCoordX(gsRelativeStartPosX[ball->getId()] + (int)(0.65f * (float)WINDOW_WIDTH)); ball->setCoordY(gsRelativeStartPosY[ball->getId()] + WINDOW_HALF_HEIGHT); ball->Stop(); return false; }
void MAPS::ChangeLayer(u8 newLayer) { if ( curr && curr->currLayer() != newLayer ) { curr->selections().removeTiles(); curr->currLayer() = newLayer; HWND hLayerBox = hLayer; if ( SendMessage(hLayerBox, CB_GETCURSEL, 0, 0) != newLayer ) SendMessage(hLayerBox, CB_SETCURSEL, newLayer, 0); if ( newLayer == LAYER_FOG || newLayer == LAYER_UNITS || newLayer == LAYER_SPRITES || newLayer == LAYER_VIEW_FOG ) // Layers where player#'s are relevant { ChangePlayer(curr->currPlayer()); ShowWindow(hPlayer, SW_SHOW); } else // Layers where player#'s are irrelevant { SendMessage(hStatus, SB_SETTEXT, 2, NULL); ShowWindow(hPlayer, SW_HIDE); } if ( newLayer == LAYER_TERRAIN ) ShowWindow(hTerrainCombo, SW_SHOW); else ShowWindow(hTerrainCombo, SW_HIDE); if ( hTerrainProp ) EndDialog(hTerrainProp, NULL); //RedrawWindow(curr->getHandle(), NULL, NULL, RDW_INVALIDATE); curr->Redraw(false); char layerString[32]; SendMessage(hLayerBox, CB_GETLBTEXT, newLayer, (INT_PTR)layerString); SendMessage(hStatus, SB_SETTEXT, 1, (INT_PTR)layerString); } }
void Maps::ChangeLayer(Layer newLayer) { if ( currentlyActiveMap != nullptr && currentlyActiveMap->getLayer() != newLayer ) { currentlyActiveMap->clearSelectedTiles(); if ( chkd.mainToolbar.layerBox.GetSel() != (int)newLayer ) chkd.mainToolbar.layerBox.SetSel((int)newLayer); if ( newLayer == Layer::FogEdit || newLayer == Layer::Units || newLayer == Layer::Sprites || newLayer == Layer::FogView ) // Layers where player#'s are relevant { ChangePlayer(currentlyActiveMap->getCurrPlayer()); ShowWindow(chkd.mainToolbar.playerBox.getHandle(), SW_SHOW); } else // Layers where player#'s are irrelevant { chkd.statusBar.SetText(2, ""); ShowWindow(chkd.mainToolbar.playerBox.getHandle(), SW_HIDE); } if ( newLayer == Layer::Terrain ) ShowWindow(chkd.mainToolbar.terrainBox.getHandle(), SW_SHOW); else ShowWindow(chkd.mainToolbar.terrainBox.getHandle(), SW_HIDE); currentlyActiveMap->setLayer(newLayer); chkd.tilePropWindow.DestroyThis(); currentlyActiveMap->Redraw(false); std::string layerString; if ( chkd.mainToolbar.layerBox.GetItemText((int)newLayer, layerString) ) chkd.statusBar.SetText(1, layerString.c_str()); } }
move IterativeMinMax(SearchBoard *board, Player player, int time_max) { char name[6]; int TIME_INCREASE = 1; SearchList Greedy = NewEmptyListMax(); SearchList NextLevel; if(player==whites) PossibleMovesListMax(board, player, &NextLevel); else PossibleMovesListMin(board, player, &NextLevel); SearchMove M; SearchBoard NewBoard; enum piece backup; int HMaxLimit = getHeuristic(board, player); int Alpha = REAL_MIN; int Beta = REAL_MAX; int ContadorDoNumerodeJogadasPossiveis=0; Tzero = clock(); clock_t SpentTime = 1;// para nao ter 0 no denominador TimeMax = time_max*CLOCKS_PER_SEC; TimeInterruptionLastSearch = false; clock_t AcumulatedTime; int auxiliar; for(int i=2; clock()-Tzero<time_max && !TimeInterruptionLastSearch /*&& i<=NIVEL_MIN*/; i++) { //NIVEL_MAX = i; Alpha = REAL_MIN; Beta = REAL_MAX; OrdenateList(&NextLevel); AtributeList(&Greedy,&NextLevel); EmptyList(&NextLevel); //M = DequeueList(&Greedy); ContadorDoNumerodeJogadasPossiveis = 0; while(!TimeInterruptionLastSearch&&clock()-Tzero<time_max&&!IsEmpty(&Greedy)) { M = DequeueList(&Greedy); movToStr(M.Move,name); //printf("\n%s:",name); NewBoard = *board; if(mkCmpMove(&NewBoard,player,M.Move)!=invalid) { ContadorDoNumerodeJogadasPossiveis++; movToStr(M.Move,name); printf("\n%d : ",i); printf("%s: %d",name,M.h_max); AcumulatedTime = clock(); if(player==whites) auxiliar = HeuristicLimitedSearchMin(&NewBoard,(Player)ChangePlayer(player),HMaxLimit,i,Alpha,Beta,1,AcumulatedTime); else auxiliar = HeuristicLimitedSearchMax(&NewBoard,(Player)ChangePlayer(player),HMaxLimit,i,Alpha,Beta,1,AcumulatedTime); if(!TimeInterruptionLastSearch) { M.h_max = auxiliar; } printf(" : %d\n",M.h_max); //printf("%d",M.h_max); EnqueueList(&NextLevel,M); } else { //printf("\nfail"); } //M = DequeueList(&Greedy); } if(ContadorDoNumerodeJogadasPossiveis==1) return DequeueList(&NextLevel).Move; //TIME_INCREASE = (time(NULL)-Tzero)/SpentTime; //SpentTime = time(NULL)-Tzero; } ConcatenateList(&Greedy,&NextLevel); OrdenateList(&Greedy); SearchMove resp, aux; resp = DequeueList(&Greedy); NewBoard = *board; mkCmpMove(&NewBoard,player,aux.Move); int contador; srand(time(NULL)); SearchBoard AnotherNewBoard; while(!IsEmpty(&Greedy)) { aux = DequeueList(&Greedy); AnotherNewBoard = *board; mkCmpMove(&AnotherNewBoard,player,aux.Move); if((player==whites&&aux.h_max>resp.h_max)||(player==blacks&&aux.h_max<resp.h_max)) { resp = aux; NewBoard = *board; mkCmpMove(&NewBoard,player,aux.Move); } if(aux.h_max==resp.h_max) { AnotherNewBoard = *board; mkCmpMove(&AnotherNewBoard,player,aux.Move); if((player==whites&&get_heuristics(&AnotherNewBoard,player)>get_heuristics(&NewBoard,player)) ||(player==blacks&&get_heuristics(&AnotherNewBoard,player)<get_heuristics(&NewBoard,player)) ||rand()%50==0) { resp = aux; NewBoard = AnotherNewBoard; } } } return resp.Move; }
int HeuristicLimitedSearchMin(SearchBoard *board,Player player,int HMaxZero,const int Level, int Alpha, int Beta, int n, clock_t AcumulatedTime) { bool FoundOnHash; int HashLevel; int HashHeuristic; clock_t Defasagem = AcumulatedTime - clock(); //printf("\nfuncionou ate aqui min\n"); if(n>nivelmax) nivelmax = n; int HMaxLimit = HMaxZero - Level; int HMinLimit = -HMaxZero - Level; numchamadas++; SearchList Greedy; PossibleMovesListMin(board, player,&Greedy); SearchList NextLevel = NewEmptyListMin(); SearchMove M;// = DequeueList(&Greedy); SearchBoard NewBoard; enum piece backup; int LastHeuristic = getHeuristic(board,player); //if(IsEmpty(&Greedy)) //{printf("\n<<<<<<<<<<<<<<<<<<<<<<BUGOU MUITO BIZARRO>>>>>>>>>>>>>>>>>>>>>\n");printBoard(board->board);} while((!IsEmpty(&Greedy))/*&&(-M.hmax-n>HMinLimit)*/) { if(clock()-Tzero>TimeMax) { printf("\nacabou o tempo: %d\n",clock()-Tzero); TimeInterruptionLastSearch = true; return -1000; } numjogadas++; M = DequeueList(&Greedy); NewBoard = *board; if(mkCmpMove(&NewBoard,player,M.Move)!=invalid) { FoundOnHash = false; /*if(getHashValue(&NewBoard, (Player)ChangePlayer(player), &HashHeuristic, &HashLevel)) { if(HashLevel>1+Level-n) { M.h_max = HashHeuristic; FoundOnHash = true; printf("\n%d", HashLevel); } }*/ //if((n<=NIVEL_MAX)&&(-M.h_max-n>HMaxLimit||-M.h_max!=LastHeuristic)) if(!FoundOnHash&&/*n<=NIVEL_MAX&&*/(n<Level||(M.h_max!=LastHeuristic)&&(n<Level+2))) { M.h_max = HeuristicLimitedSearchMax(&NewBoard, (Player)ChangePlayer(player), HMaxZero, Level, Alpha, Beta, n+1, Defasagem+clock()); if(TimeInterruptionLastSearch) return -1000; //addToHash(&NewBoard, (Player)ChangePlayer(player), M.h_max, 1+Level-n); //if(n==Ntest) printf("\nmin%d:%d",n,M.h_max); } //else printf("\n%d\n",n); //undoMov(board->board,M.Move,backup); EnqueueList(&NextLevel,M); // AlphaBeta condition // Alpha is the value of the best alternative for MAX along the path to board // Beta is the value of the best alternative for MIN along the path to board if(M.h_max<Alpha) { EmptyList(&Greedy); EmptyList(&NextLevel); return M.h_max; } if(M.h_max<Beta) Beta = M.h_max; } //M = DequeueList(&Greedy); } move Mov1,Mov2; int resp1 = REAL_MAX, resp2 = REAL_MAX; OrdenateList(&Greedy); OrdenateList(&NextLevel); if(IsEmpty(&Greedy )&&IsEmpty(&NextLevel)) { //printf("BIZU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",n); return REAL_MAX-n; } if(!IsEmpty(&Greedy )) resp1 = DequeueList(&Greedy).h_max; if(!IsEmpty(&NextLevel)) resp2 = DequeueList(&NextLevel).h_max; //while(!IsEmpty(&Greedy)) printf("\n%d:%d",n,DequeueList(&Greedy).h_max); //while(!IsEmpty(&NextLevel)) printf("\n%d:%d",n,DequeueList(&NextLevel).h_max); //printf("\n%d:final: %d",n,(resp1<resp2?resp1:resp2)); //if(resp1==resp2&&resp1==REAL_MAX&&IsEmpty(&Greedy )&&IsEmpty(&NextLevel)) return REAL_MAX-10;//printf("MIN%dBUGOU BIZARRO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",n); EmptyList(&Greedy); EmptyList(&NextLevel); //if(n==Ntest) printf("\nMIN%d:%d",n,(resp1<resp2?resp1:resp2)); return (resp1<resp2?resp1:resp2); }