-rw-r--r-- | noncore/games/backgammon/backgammon.cpp | 16 | ||||
-rw-r--r-- | noncore/games/backgammon/moveengine.cpp | 2 |
2 files changed, 11 insertions, 7 deletions
diff --git a/noncore/games/backgammon/backgammon.cpp b/noncore/games/backgammon/backgammon.cpp index 51020a0..bdb1c78 100644 --- a/noncore/games/backgammon/backgammon.cpp +++ b/noncore/games/backgammon/backgammon.cpp @@ -1,129 +1,133 @@ #include "backgammon.h" - #include "aidialog.h" #include "filedialog.h" #include "playerdialog.h" #include "rulesdialog.h" #include "themedialog.h" +/* OPIE */ +#include <opie2/odebug.h> +#include <qpe/qpeapplication.h> +#include <qpe/config.h> +#include <qpe/resource.h> +using namespace Opie::Core; + +/* QT */ #include <qfile.h> #include <qlayout.h> #include <qmessagebox.h> #include <qtimer.h> -#include <qpe/qpeapplication.h> -#include <qpe/config.h> #include <qmenubar.h> -#include <qpe/resource.h> #include <stdlib.h> BackGammon::BackGammon(QWidget* parent, const char* name, WFlags fl) : QMainWindow(parent, name, fl) { if (!name) setName("BackGammon"); setCaption(tr( "Backgammon") ); setIcon( Resource::loadPixmap( "backgammon" ) ); //general counter varaible int a=0; //the game engine move=new MoveEngine(); //load the default theme Config conf("backgammon"); if(!conf.isValid()) { - qDebug("config file does not exist"); + odebug << "config file does not exist" << oendl; conf.setGroup("general"); conf.writeEntry("theme","default"); conf.setGroup("rules"); conf.writeEntry("move_with_pieces_out",false); conf.writeEntry("nice_dice",false); conf.setGroup("display"); conf.writeEntry("small",false); conf.writeEntry("warning",true); conf.setGroup("ai"); conf.writeEntry("rescue",6); conf.writeEntry("eliminate",4); conf.writeEntry("expose",1); conf.writeEntry("protect",5); conf.writeEntry("safe",3); conf.writeEntry("empty",2); } conf.setGroup("general"); theme_name=conf.readEntry("theme","default"); QString theme_file=QPEApplication::qpeDir()+"/backgammon/"+theme_name+".theme"; //the rules conf.setGroup("rules"); rules.move_with_pieces_out=conf.readBoolEntry("move_with_pieces_out",false); rules.generous_dice=conf.readBoolEntry("nice_dice",false); move->setRules(rules); //get the AI settings AISettings ai; conf.setGroup("ai"); ai.rescue=conf.readNumEntry("rescue",6); ai.eliminate=conf.readNumEntry("eliminate",4); ai.expose=conf.readNumEntry("expose",1); ai.protect=conf.readNumEntry("protect",5); ai.safe=conf.readNumEntry("safe",3); ai.empty=conf.readNumEntry("empty",2); move->setAISettings(ai); //get the theme component names Config theme(theme_file,Config::File); if(!theme.isValid()) { - qDebug("theme file does not exist"); + odebug << "theme file does not exist" << oendl; theme.setGroup("theme"); theme.writeEntry("board","casino_board_1"); theme.writeEntry("pieces1","casino_pieces_blue"); theme.writeEntry("pieces2","casino_pieces_white"); theme.writeEntry("dice1","casino_dice"); theme.writeEntry("dice2","casino_dice"); theme.writeEntry("table","casino_table_green"); theme.writeEntry("odds","casino_odds"); } theme.setGroup("theme"); board_name=theme.readEntry("board","casino_board_1"); piecesA_name=theme.readEntry("pieces1","casino_pieces_blue"); piecesB_name=theme.readEntry("pieces2","casino_pieces_white"); diceA_name=theme.readEntry("dice1","casino_dice"); diceB_name=theme.readEntry("dice2","casino_dice"); table_name=theme.readEntry("table","casino_table_green"); odds_name=theme.readEntry("odds","casino_odds"); //the menu QMenuBar* menuBar = new QMenuBar(this); QPopupMenu* gamemenu= new QPopupMenu(this); gamemenu->insertItem(tr( "New" ),this,SLOT(newgame())); gamemenu->insertSeparator(); gamemenu->insertItem(tr( "Load" ),this,SLOT(loadgame())); gamemenu->insertItem(tr( "Save" ),this,SLOT(savegame())); gamemenu->insertSeparator(); gamemenu->insertItem(tr( "Delete" ),this,SLOT(deletegame())); menuBar->insertItem(tr( "Game" ),gamemenu); QPopupMenu* thememenu= new QPopupMenu(this); thememenu->insertItem(tr( "New" ),this,SLOT(newtheme())); thememenu->insertSeparator(); thememenu->insertItem(tr( "Load"),this,SLOT(loadtheme())); thememenu->insertItem(tr( "Save" ),this,SLOT(savetheme())); thememenu->insertSeparator(); thememenu->insertItem(tr( "Default"),this,SLOT(themedefault())); thememenu->insertItem(tr( "Delete" ),this,SLOT(deletetheme())); menuBar->insertItem(tr( "Theme" ),thememenu); QPopupMenu* optionmenu=new QPopupMenu(this); optionmenu->insertItem(tr( "Player" ),this,SLOT(playerselect())); optionmenu->insertSeparator(); optionmenu->insertItem(tr( "AI" ),this,SLOT(modify_AI())); optionmenu->insertItem(tr( "Rules" ),this,SLOT(setrules())); menuBar->insertItem(tr( "Options"),optionmenu); diff --git a/noncore/games/backgammon/moveengine.cpp b/noncore/games/backgammon/moveengine.cpp index 7de7147..a4145cc 100644 --- a/noncore/games/backgammon/moveengine.cpp +++ b/noncore/games/backgammon/moveengine.cpp @@ -412,97 +412,97 @@ int MoveEngine::getPossibleMoves() } else if(fieldColor(nextfield)==otherplayer) { if(abs(population[nextfield].total)>1) //can not move to this field moves[field].weight[b]=0; else if(abs(population[nextfield].total)==1) //eliminate opponent : very nice moves[field].weight[b]=ai.eliminate; } else if(fieldColor(nextfield)==player) //nextfield already occupied by player { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else if(abs(population[nextfield].total)>1) //own pices already there : safe moves[field].weight[b]=ai.safe; else if(abs(population[nextfield].total)==1) //protect own piece : most importatnt moves[field].weight[b]=ai.protect; } else if(population[nextfield].total==0) //nextfield empty { if(abs(population[field].total)==2) //expose own piece : not diserable moves[field].weight[b]=ai.expose; else moves[field].weight[b]=ai.empty; } else moves[field].weight[b]=0; //default. } else moves[field].weight[b]=0; //dice already used or field not used by player } } int total=0; for(int field=0;field<26;field++) { total+=moves[field].weight[0]+moves[field].weight[1]+moves[field].weight[2]+moves[field].weight[3]; } return total; } void MoveEngine::move(const int& from, int to, const int& dice) { - //qDebug("%d moves from %d to %d (%d) with dice %d",player,from,to,to-from,dice); + //odebug << "" << player << " moves from " << from << " to " << to << " (" << to-from << ") with dice " << dice << "" << oendl; if(player==1 && to==25) to=26; if(player==2 && to==0) to=27; //if space is occupied by enemy move pieces to startzone if(fieldColor(to)==otherplayer) { population[to].total=0; if(otherplayer==1) population[0].total++; else population[25].total--; } if(player==1) { population[from].total--; population[to].total++; } else //player=2 { population[from].total++; population[to].total--; } if(dice==1) emit done_dice1(); else if(dice==2) emit done_dice2(); else if(dice==3) emit done_dice3(); else emit done_dice4(); if(abs(population[26].total)==15) emit player_finished(1); if(abs(population[27].total)==15) emit player_finished(2); } void MoveEngine::checkstate() { //check if pieces are out pieces_out[1]=(population[0].total>0) ? true : false; pieces_out[2]=(population[25].total<0) ? true : false; |