Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) GameSearchAndDestroyChess

 

SearchAndDestroyChess is a variant on chess, also called Kriegspiel or Dark Chess. In SearchAndDestroyChess you can only view that part of the board that is 'seen' by your pieces.

 

There is also a console/MS-DOS version of SearchAndDestroyChess called SearchAndDestroyChessConsole.

 

The following special rules apply to SearchAndDestroyChess:

 

SearchAndDestroyChess is programmed in C++ using the IDE C++ Builder 6.0. It uses the STL, VCL and Boost libraries.

 

One month after putting SearchAndDestroyChess online, I found out I wasn't the first to have invented this variant :-(.

 

 

 

 

 

Downloads

 

 

 

 

 

 

External links

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./GameSearchAndDestroyChess/GameSearchAndDestroyChessConsole.pro

 

QT       += core
QT       -= gui
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

#Turn threads off for quick execution
#Turn threads on for linear debugging
#DEFINES += SADC_USE_THREADS

LIBS += -lboost_system -lboost_filesystem -lboost_program_options -lboost_regex

INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppChess \
    ../../Classes/CppTrace

SOURCES += main.cpp \
    ../../Classes/CppChess/chesspiece.cpp \
    ../../Classes/CppChess/chessmove.cpp \
    ../../Classes/CppChess/chesscolor.cpp \
    ../../Classes/CppChess/chesssquare.cpp \
    ../../Classes/CppChess/chessboard.cpp \
    ../../Classes/CppChess/chessscore.cpp \
    ../../Classes/CppChess/chessrank.cpp \
    ../../Classes/CppChess/chessplayer.cpp \
    ../../Classes/CppChess/chesspiecetest.cpp \
    ../../Classes/CppChess/chessmovetest.cpp \
    ../../Classes/CppChess/chessmoves.cpp \
    ../../Classes/CppChess/chessgame.cpp \
    ../../Classes/CppChess/chessfile.cpp \
    ../../Classes/CppChess/chesscastling.cpp \
    ../../Classes/CppChess/chessboardtest.cpp \
    ../../Classes/CppChess/chessbitboard.cpp \
    searchanddestroychessmenudialog.cpp \
    searchanddestroychessgamedialog.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppChess/chessboardfactory.cpp \
    ../../Classes/CppChess/chesshelper.cpp \
    ../../Classes/CppChess/chesspiecefactory.cpp \
    ../../Classes/CppChess/chesssquarefactory.cpp \
    ../../Classes/CppChess/chessmovefactory.cpp

HEADERS += \
    ../../Classes/CppChess/chesspiece.h \
    ../../Classes/CppChess/chessmove.h \
    ../../Classes/CppChess/chesscolor.h \
    ../../Classes/CppChess/chesssquare.h \
    ../../Classes/CppChess/chessboard.h \
    ../../Classes/CppChess/chessscore.h \
    ../../Classes/CppChess/chessrank.h \
    ../../Classes/CppChess/chessplayer.h \
    ../../Classes/CppChess/chessmoves.h \
    ../../Classes/CppChess/chessgame.h \
    ../../Classes/CppChess/chessfwd.h \
    ../../Classes/CppChess/chessfile.h \
    ../../Classes/CppChess/chesscastling.h \
    ../../Classes/CppChess/chessbitboard.h \
    searchanddestroychessmenudialog.h \
    searchanddestroychessgamedialog.h \
    ../../Classes/CppTrace/trace.h \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppChess/chessboardfactory.h \
    ../../Classes/CppChess/chesshelper.h \
    ../../Classes/CppChess/chesspiecefactory.h \
    ../../Classes/CppChess/chesssquarefactory.h \
    ../../Classes/CppChess/chessmovefactory.h

OTHER_FILES += \
    ../../Classes/CppChess/Licence.txt \
    ../../Classes/CppTrace/Licence.txt \
    ../../Classes/CppWidget/Licence.txt \
    ../../Classes/CppAbout/Licence.txt

 

 

 

 

 

Qt project file: ./GameSearchAndDestroyChess/GameSearchAndDestroyChessDesktop.pro

 

include(../../DesktopApplication.pri)

include(../../Libraries/Boost.pri)

include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

include(../../Classes/CppChess/CppChess.pri)
include(../../Classes/CppChessResources/CppChessResources.pri)
include(../../Classes/CppGeometry/CppGeometry.pri)
include(../../Classes/CppPlane/CppPlane.pri)
include(../../Classes/CppWidget/CppWidget.pri)

include(../../Classes/CppQtChess/CppQtChess.pri)

include(GameSearchAndDestroyChessDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./GameSearchAndDestroyChess/GameSearchAndDestroyChessWebsite.pro

 

QT       += core
QT       -= gui
LIBS += -lwt -lwthttp -lboost_filesystem
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppChess \
    ../../Classes/CppRectangle \
    ../../Classes/CppTrace \
    ../../Classes/CppWidget \
    ../../Classes/CppWtAboutDialog \
    ../../Classes/CppWtAutoConfig \
    ../../Classes/CppWtServerPusher \
    ../../Classes/CppWtChessBoardWidget \
    ../../Classes/CppWtTimedServerPusher

HEADERS += \
    ../../Classes/CppChess/chessboard.h \
    ../../Classes/CppChess/chessmove.h \
    ../../Classes/CppChess/chesspiece.h \
    ../../Classes/CppChess/chesssquare.h \
    ../../Classes/CppChess/chesssquareselector.h \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.h \
    ../../Classes/CppTrace/trace.h \
    ../../Classes/CppWtChessBoardWidget/wtchessboardwidget.h \
    searchanddestroychessqtmenudialog.h \
    searchanddestroychessqtgamedialog.h \
    searchanddestroychessmenudialog.h \
    ../../Classes/CppWtAutoConfig/wtautoconfig.h \
    ../../Classes/CppChess/chessfwd.h \
    ../../Classes/CppChess/chessresources.h \
    ../../Classes/CppWtChessBoardWidget/wtchessresources.h \
    ../../Classes/CppChess/chessboardwidget.h \
    ../../Classes/CppChess/chessboard2d.h \
    ../../Classes/CppWidget/widget.h \
    ../../Classes/CppRectangle/rectangle.h \
    ../../Classes/CppChess/chesssquarefactory.h
SOURCES += wtmain.cpp \
    ../../Classes/CppChess/chessboard.cpp \
    ../../Classes/CppChess/chessmove.cpp \
    ../../Classes/CppChess/chesspiece.cpp \
    ../../Classes/CppChess/chesssquare.cpp \
    ../../Classes/CppChess/chesssquareselector.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.cpp \
    ../../Classes/CppWtChessBoardWidget/wtchessboardwidget.cpp \
    searchanddestroychessmenudialog.cpp \
    ../../Classes/CppWtAutoConfig/wtautoconfig.cpp \
    ../../Classes/CppChess/chessresources.cpp \
    ../../Classes/CppWtChessBoardWidget/wtchessresources.cpp \
    ../../Classes/CppChess/chessboardwidget.cpp \
    ../../Classes/CppChess/chessboard2d.cpp \
    ../../Classes/CppWidget/widget.cpp \
    ../../Classes/CppRectangle/rectangle.cpp \
    ../../Classes/CppChess/chesssquarefactory.cpp

OTHER_FILES += \
    GameSearchAndDestroyChessArchitecture.txt

 

 

 

 

 

./GameSearchAndDestroyChess/GameSearchAndDestroyChessConsole.pri

 

INCLUDEPATH += \
    ../../Games/GameSearchAndDestroyChess

SOURCES += \
    ../../Games/GameSearchAndDestroyChess/searchanddestroychessmenudialog.cpp

HEADERS  += \
    ../../Games/GameSearchAndDestroyChess/searchanddestroychessmenudialog.h

OTHER_FILES += \
    ../../Games/GameSearchAndDestroyChess/Licence.txt

 

 

 

 

 

./GameSearchAndDestroyChess/GameSearchAndDestroyChessDesktop.pri

 

include(../../Games/GameSearchAndDestroyChess/GameSearchAndDestroyChessConsole.pri)

RESOURCES += \
    ../../Games/GameSearchAndDestroyChess/GameSearchAndDestroyChess.qrc

FORMS += \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessmenudialog.ui \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessgamedialog.ui

SOURCES += \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessmenudialog.cpp \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessgamedialog.cpp

HEADERS += \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessmenudialog.h \
    ../../Games/GameSearchAndDestroyChess/qtsearchanddestroychessgamedialog.h

 

 

 

 

 

./GameSearchAndDestroyChess/GameSearchAndDestroyChessWebsite.pri

 

include(../../Games/GameSearchAndDestroyChess/GameSearchAndDestroyChessConsole.pri)

SOURCES +=

HEADERS +=

 

 

 

 

 

./GameSearchAndDestroyChess/main.cpp

 

#include <cassert>
#include <string>
#include <fstream>
#include <iostream>

#ifdef SADC_USE_THREADS
#include <thread>
#endif

#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>

#include "chessgame.h"
#include "chessmoves.h"
#include "searchanddestroychessmenudialog.h"
#include "trace.h"
///FileToVector reads a file and converts it to a std::vector<std::string>
///From http://www.richelbilderbeek.nl/CppFileToVector.htm
const std::vector<std::string> FileToVector(const std::string& filename)
{
  assert(boost::filesystem::exists(filename));
  std::vector<std::string> v;
  std::ifstream in(filename.c_str());
  std::string s;
  for (int i=0; !in.eof(); ++i)
  {
    std::getline(in,s);
    v.push_back(s);
  }
  return v;
}

/*
//From http://www.richelbilderbeek/CppAskUserForString.htm
const std::string AskUserForString()
{
  std::string s;
  std::getline(std::cin,s);
  return s;
}

bool AskUserForYesNo()
{
  while (1)
  {
    const std::string s = AskUserForString();
    if (s.empty()==true) continue;
    if (s[0] == 'y' || s[0] == 'Y' || s == "yes" || s == "Yes" || s == "YES") return true;
    if (s[0] == 'n' || s[0] == 'N' || s == "no" || s == "No" || s == "NO")    return false;
  }
}

void ClearScreen()
{
  //'clear' the screen
  for (int i=0; i!=50; ++i) std::cout << std::endl;
}
*/

///Goal:
///- Input: a game its moves
///- Output: valid yes/no

///NEVER FORGET:
/// - Prefer Factory over copy constructor
int main(int argc, char* argv[])
{
  START_TRACE();

  #ifdef SADC_USE_THREADS
  std::thread t(
    []
  #endif
    {
      FTRACE("Testing in main");
      //SearchAndDestroyChess::MenuDialog::Test();
      ribi::Chess::Game::Test();
    }
  #ifdef SADC_USE_THREADS
  );
  #endif

// Declare the supported options.
  boost::program_options::options_description d("Allowed options for [my_program]");
  std::string filename = "chess.txt";
  d.add_options()
      ("help",
        "produce this help message")
      ("filename",
         boost::program_options::value<std::string>(&filename),
         "load from file 'arg'");

  boost::program_options::variables_map m;
  boost::program_options::store(
    boost::program_options::parse_command_line(
      argc, argv, d), m);
  boost::program_options::notify(m);

  //If one of the options is set to 'help'...
  if (m.count("help"))
  {
    //Display the options_description
    std::cout << d << "\n";
  }

  if (m.count("filename"))
  {
    filename = m["filename"].as<std::string>();
    std::cout
      << "Filename is set to '"
      << m["filename"].as<std::string>()
      << "'\n";
  }
  else
  {
    std::cout << "No filename set, using '" << filename << "'\n";
  }

  if (!boost::filesystem::exists(filename))
  {
    std::cout << "Filename '" + filename + "' does not exist.\n";
    const auto v = ribi::Chess::Moves::GetGameKasparovVersusTheWorld();
    std::ofstream file(filename.c_str());
    std::copy(v.begin(),v.end(),std::ostream_iterator<std::string>(file,"\n"));
    std::cout << "Filename '" + filename + "' created with example game.\n";
  }
  assert(boost::filesystem::exists(filename));
  const std::vector<std::string> v = FileToVector(filename);

  if (ribi::Chess::Game::CanDoGame(v))
  {
    std::cout << "Y" << std::endl;
  }
  else
  {
    std::cout << "N" << std::endl;
    const int n = ribi::Chess::Game::CanDoGameUntil(v);
    std::cout << n << std::endl;
    std::copy(v.begin(),v.begin() + n + 1,std::ostream_iterator<std::string>(std::cout,"\n"));
    std::cout << std::flush;

  }
  #ifdef SADC_USE_THREADS
  while (1) {}
  t.join();
  #endif

  /*
  ShowLicence();

  std::cout
    << std::string(79,'*')
    << std::endl
    << "Welcome to Search And Destroy Chess."
    << std::endl
    << "White player, please"
    << std::endl
    << "press any key to start the game"
    << std::endl;
  AskUserForString();

  ClearScreen();

  std::cout << "Is player #1 (white) a human player (y/n) ?" << std::endl;
  const bool isPlayerOneHuman = AskUserForYesNo();
  std::cout << "Is player #2 (black) a human player (y/n) ?" << std::endl;
  const bool isPlayerTwoHuman = AskUserForYesNo();


  ChessGame game;
  while(1)
  {
    game.CoutGame();

    if ( (game.GetWhoseTurn() == ChessPiece::white && isPlayerOneHuman == true)
      || (game.GetWhoseTurn() == ChessPiece::black && isPlayerTwoHuman == true) )
    {
      //Human move
      const std::string input = AskUserForString();

      if (input == "q" || input == "Q" || input == "exit"    || input == "quit") break;
      if (input == "r" || input == "R" || input == "restart" || input == "new ")
      {
        game = ChessGame();
        continue;
      }

      ChessMove move;

      const bool validInput = game.ParseMove(input,move);
      if (validInput == false) continue;

      const bool validMove = game.CanDoMove(move);
      if (validMove == false) continue;

      game.DoMove(move);
    }
    else
    {
      //Computer move
      const ChessMove move = game.SuggestMove();
      game.DoMove(move);
    }

    if (game.IsGameOver()==true)
    {
      game.CoutGame();

      std::cout
        << "Game won by "
        << (game.GetWinner() == ChessPiece::white ? "white" : "black")
        << " player." << std::endl
        << "Press any key to start a new game" << std::endl;
      const std::string input = AskUserForString();
      if (input == "q" || input == "Q" || input == "exit"    || input == "quit") break;
      game = ChessGame();
    }


    if ( (game.GetWhoseTurn() == ChessPiece::white && isPlayerOneHuman == true)
      || (game.GetWhoseTurn() == ChessPiece::black && isPlayerTwoHuman == true) )
    {
      //Human input
      ClearScreen();


      std::cout
        << (game.GetWhoseTurn() == ChessPiece::white ? "white" : "black")
        << " player, please" << std::endl
        << "press any key to view the board" << std::endl;
      AskUserForString();
      ClearScreen();
    }
  }

  ShowLicence();
  std::cout
    << "press any key to quit"
    << std::endl;
  AskUserForString();
  */
}

 

 

 

 

 

./GameSearchAndDestroyChess/maindialog.h

 

//---------------------------------------------------------------------------
/*
TestQuestion, tool to test the Question and QuestionDialog classes
Copyright (C) 2011 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestQuestion.htm
//---------------------------------------------------------------------------
#ifndef TESTQUESTIONMAINDIALOG_H
#define TESTQUESTIONMAINDIALOG_H
//---------------------------------------------------------------------------
#include <vector>
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
struct MultipleChoiceQuestion;
struct MultipleChoiceQuestionDialog;
struct OpenQuestion;
struct OpenQuestionDialog;
struct QuestionDialog;
//---------------------------------------------------------------------------
///The GUI independent TestQuestion main dialog
struct TestQuestionMainDialog
{
  TestQuestionMainDialog();

  std::vector<boost::shared_ptr<QuestionDialog> >& GetQuestions() { return m_questions; }

  private:
  std::vector<boost::shared_ptr<QuestionDialog> > m_questions;

  void OnQuestionAnswered();

  static std::vector<boost::shared_ptr<QuestionDialog> > CreateQuestions();
};
//---------------------------------------------------------------------------
#endif // TESTDIALMENUDIALOG_H

 

 

 

 

 

./GameSearchAndDestroyChess/maindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestQuestion, tool to test the Question and QuestionDialog classes
Copyright (C) 2011 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestQuestion.htm
//---------------------------------------------------------------------------
#include "multiplechoicequestion.h"
#include "multiplechoicequestiondialog.h"
#include "openquestion.h"
#include "openquestiondialog.h"
#include "testquestionmaindialog.h"
//---------------------------------------------------------------------------
TestQuestionMainDialog::TestQuestionMainDialog()
  : m_questions(CreateQuestions())
{

}
//---------------------------------------------------------------------------
std::vector<boost::shared_ptr<QuestionDialog> > TestQuestionMainDialog::CreateQuestions()
{
  std::vector<boost::shared_ptr<QuestionDialog> > v;

  v.push_back(
    boost::shared_ptr<QuestionDialog>(
      new OpenQuestionDialog(
        boost::shared_ptr<OpenQuestion>(
          new OpenQuestion(
            "*",
            "1+1=",
            { "2", "two" }
          )
        )
      )
    )
  );
  v.push_back(
    boost::shared_ptr<QuestionDialog>(
      new OpenQuestionDialog(
        boost::shared_ptr<OpenQuestion>(
          new OpenQuestion(
            "question.png",
            "The solution of this equation is...",
            { "2", "two" }
          )
        )
      )
    )
  );
  v.push_back(
    boost::shared_ptr<QuestionDialog>(
      new MultipleChoiceQuestionDialog(
        boost::shared_ptr<MultipleChoiceQuestion>(
          new MultipleChoiceQuestion(
            "*",
            "1+1=",
            "2",
            { "1", "3", "4", "5", "6" }
          )
        )
      )
    )
  );
  v.push_back(
    boost::shared_ptr<QuestionDialog>(
      new MultipleChoiceQuestionDialog(
        boost::shared_ptr<MultipleChoiceQuestion>(
          new MultipleChoiceQuestion(
            "question.png",
            "The solution of this equation is...",
            "2",
            { "1", "3", "4", "5", "6" }
          )
        )
      )
    )
  );
  std::random_shuffle(v.begin(),v.end());



  return v;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

 

 

 

 

 

./GameSearchAndDestroyChess/qtmain.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <QApplication>
#include "qtsearchanddestroychessmenudialog.h"
#pragma GCC diagnostic pop

///Graphics used from
///http://www.gnu.org/software/xboard/
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  ribi::sadc::QtSearchAndDestroyChessMenuDialog w;
  w.show();
  return a.exec();
}

 

 

 

 

 

./GameSearchAndDestroyChess/qtsearchanddestroychessgamedialog.h

 

#ifndef QTSEARCHANDDESTROYCHESSGAMEDIALOG_H
#define QTSEARCHANDDESTROYCHESSGAMEDIALOG_H

#include "qthideandshowdialog.h"

namespace Ui {
  class QtSearchAndDestroyChessGameDialog;
}

namespace ribi {

class QtSearchAndDestroyChessGameDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtSearchAndDestroyChessGameDialog(QWidget *parent = 0);
  QtSearchAndDestroyChessGameDialog(const QtSearchAndDestroyChessGameDialog&) = delete;
  QtSearchAndDestroyChessGameDialog& operator=(const QtSearchAndDestroyChessGameDialog&) = delete;
  ~QtSearchAndDestroyChessGameDialog() noexcept;

private:
  Ui::QtSearchAndDestroyChessGameDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace ribi

#endif // QTSEARCHANDDESTROYCHESSGAMEDIALOG_H

 

 

 

 

 

./GameSearchAndDestroyChess/qtsearchanddestroychessgamedialog.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "qtsearchanddestroychessgamedialog.h"

#ifdef MXE_SUPPORTS_THREADS
#include <future>
#endif

#include "ui_qtsearchanddestroychessgamedialog.h"
#pragma GCC diagnostic pop

ribi::QtSearchAndDestroyChessGameDialog::QtSearchAndDestroyChessGameDialog(QWidget *parent) :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtSearchAndDestroyChessGameDialog)
{
  ui->setupUi(this);
  #ifndef NDEBUG
  Test();
  #endif
}

ribi::QtSearchAndDestroyChessGameDialog::~QtSearchAndDestroyChessGameDialog() noexcept
{
  delete ui;
}

#ifndef NDEBUG
void ribi::QtSearchAndDestroyChessGameDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  #ifdef MXE_SUPPORTS_THREADS
  std::thread t(
    []
  #endif
    {
      ribi::Chess::QtChessBoardWidget();
    }
  #ifdef MXE_SUPPORTS_THREADS
  );
  t.join();
  #endif

}
#endif

 

 

 

 

 

./GameSearchAndDestroyChess/qtsearchanddestroychessmenudialog.h

 

#ifndef QTSEARCHANDDESTROYCHESSMENUDIALOG_H
#define QTSEARCHANDDESTROYCHESSMENUDIALOG_H

#include "qthideandshowdialog.h"

namespace Ui {
  class QtSearchAndDestroyChessMenuDialog;
}

namespace ribi {
namespace sadc {

class QtSearchAndDestroyChessMenuDialog : public QtHideAndShowDialog
{
  Q_OBJECT

public:
  explicit QtSearchAndDestroyChessMenuDialog(QWidget *parent = 0);
  QtSearchAndDestroyChessMenuDialog(const QtSearchAndDestroyChessMenuDialog&) = delete;
  QtSearchAndDestroyChessMenuDialog& operator=(const QtSearchAndDestroyChessMenuDialog&) = delete;
  ~QtSearchAndDestroyChessMenuDialog() noexcept;

private:
  Ui::QtSearchAndDestroyChessMenuDialog *ui;

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif

private slots:
    void on_button_about_clicked();
    void on_button_start_clicked();
    void on_button_quit_clicked();

};

} //~namespace sadc
} //~namespace ribi

#endif // QTSEARCHANDDESTROYCHESSMENUDIALOG_H

 

 

 

 

 

./GameSearchAndDestroyChess/qtsearchanddestroychessmenudialog.cpp

 

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include "qtsearchanddestroychessmenudialog.h"

#include <future>

#include "searchanddestroychessmenudialog.h"
#include "qtaboutdialog.h"
#include "qtsearchanddestroychessgamedialog.h"
#include "ui_qtsearchanddestroychessmenudialog.h"
#include "trace.h"
#pragma GCC diagnostic pop

ribi::sadc::QtSearchAndDestroyChessMenuDialog::QtSearchAndDestroyChessMenuDialog(QWidget *parent) :
    QtHideAndShowDialog(parent),
    ui(new Ui::QtSearchAndDestroyChessMenuDialog)
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //TODO: Add transparency to the resources
}

ribi::sadc::QtSearchAndDestroyChessMenuDialog::~QtSearchAndDestroyChessMenuDialog() noexcept
{
  delete ui;
}

void ribi::sadc::QtSearchAndDestroyChessMenuDialog::on_button_start_clicked()
{
  QtSearchAndDestroyChessGameDialog d;
  ShowChild(&d);
}

void ribi::sadc::QtSearchAndDestroyChessMenuDialog::on_button_about_clicked()
{
  const About a = sadc::MenuDialog().GetAbout();
  QtAboutDialog d(a);
  ShowChild(&d);
}

void ribi::sadc::QtSearchAndDestroyChessMenuDialog::on_button_quit_clicked()
{
  close();
}

#ifndef NDEBUG
void ribi::sadc::QtSearchAndDestroyChessMenuDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  #ifdef MXE_SUPPORTS_THREADS
  std::thread t(
    []
  #endif
    {
      QtSearchAndDestroyChessGameDialog();
    }
  #ifdef MXE_SUPPORTS_THREADS
  );
  t.join();
  #endif
}
#endif

 

 

 

 

 

./GameSearchAndDestroyChess/searchanddestroychessgamedialog.h

 

#ifndef SEARCHANDDESTROYCHESSGAMEDIALOG_H
#define SEARCHANDDESTROYCHESSGAMEDIALOG_H

#include <string>
#include <vector>

namespace ribi {
namespace SearchAndDestroyChess {

struct GameDialog
{
  GameDialog();
};

} //~namespace SearchAndDestroyChess
} //~namespace ribi

#endif // SEARCHANDDESTROYCHESSGAMEDIALOG_H

 

 

 

 

 

./GameSearchAndDestroyChess/searchanddestroychessgamedialog.cpp

 

#include "searchanddestroychessgamedialog.h"

#include "chessgame.h"


namespace SearchAndDestroyChess {

GameDialog::GameDialog()
{

}



} //~namespace SearchAndDestroyChess

 

 

 

 

 

./GameSearchAndDestroyChess/searchanddestroychessmenudialog.h

 

#ifndef SEARCHANDDESTROYCHESSMENUDIALOG_H
#define SEARCHANDDESTROYCHESSMENUDIALOG_H

#include "menudialog.h"

namespace ribi {
namespace sadc {

///The logic behind the menu dialog
struct MenuDialog : public ::ribi::MenuDialog
{
  ///Creates the resources needed
  MenuDialog();

  About GetAbout() const noexcept;
  Help GetHelp() const noexcept;
  boost::shared_ptr<const Program> GetProgram() const noexcept;
  std::string GetVersion() const noexcept;
  std::vector<std::string> GetVersionHistory() const noexcept;

  private:
  int ExecuteSpecific(const std::vector<std::string>& argv) noexcept;

  private:

  #ifndef NDEBUG
  static void Test() noexcept;
  #endif
};

} //~namespace sadc
} //~namespace ribi

#endif // SEARCHANDDESTROYCHESSMENUDIALOG_H

 

 

 

 

 

./GameSearchAndDestroyChess/searchanddestroychessmenudialog.cpp

 

#include "searchanddestroychessmenudialog.h"

#include <algorithm>
#include <cassert>
#include <iostream>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"

#ifdef MXE_SUPPORTS_THREADS
#include <thread>
#endif

#include "chessgame.h"

#include "chesswidget.h"
#include "chesssquareselector.h"
#include "chesssquarefactory.h"
#include "chesssquare.h"
#include "chessscore.h"
#include "chessrank.h"
#include "chessplayer.h"
#include "chesspiecefactory.h"
#include "chesspiece.h"
#include "chessmoves.h"
#include "chessmovefactory.h"
#include "chessmove.h"
#include "chesshelper.h"
#include "chessgamewidget.h"
#include "chessgame.h"
#include "chessfwd.h"
#include "chessfile.h"
#include "chesscolor.h"
#include "chesscastling.h"
#include "chessboardwidget.h"
#include "chessboardfactory.h"
#include "chessboard.h"
#include "chessbitboard.h"

#include "richelbilderbeekprogram.h"
#include "trace.h"

#include <QFile>
#pragma GCC diagnostic pop

ribi::sadc::MenuDialog::MenuDialog()
{
  #ifndef NDEBUG
  Test();
  #endif
}

int ribi::sadc::MenuDialog::ExecuteSpecific(const std::vector<std::string>& argv) noexcept
{
  #ifndef NDEBUG
  Test();
  #endif
  const int argc = static_cast<int>(argv.size());
  if (argc == 1)
  {
    std::cout << GetHelp() << '\n';
    return 1;
  }
  assert(!"TODO");
  return 1;
}


ribi::About ribi::sadc::MenuDialog::GetAbout() const noexcept
{
  About a(
    "Richel Bilderbeek",
    "SearchAndDestroyChess",
    "Kriegspiel",
    "the 23rd of Februari 2013",
    "2011-2014",
    "http://www.richelbilderbeek.nl/GameSearchAndDestroyChess.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("Artwork from GNU XBoard");
  a.AddLibrary("Chess::widget version: " + Chess::ChessWidget::GetVersion());
  a.AddLibrary("Chess::SquareSelector version: " + Chess::SquareSelector::GetVersion());
  a.AddLibrary("Chess::Square: " + Chess::Square::GetVersion());
  a.AddLibrary("Chess::Score: " + Chess::Score::GetVersion());
  a.AddLibrary("Chess::Rank: " + Chess::Rank::GetVersion());
  a.AddLibrary("Chess::Moves: " + Chess::Moves::GetVersion());
  a.AddLibrary("Chess::Move: " + Chess::Move::GetVersion());
  a.AddLibrary("Chess::Game: " + Chess::Game::GetVersion());
  a.AddLibrary("Chess::GameWidget: " + Chess::GameWidget::GetVersion());
  a.AddLibrary("Chess::File: " + Chess::File::GetVersion());
  a.AddLibrary("Chess::Board: " + Chess::Board::GetVersion());
  a.AddLibrary("Chess::BoardWidget: " + Chess::BoardWidget::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());
  return a;
}

ribi::Help ribi::sadc::MenuDialog::GetHelp() const noexcept
{
  return Help(
    this->GetAbout().GetFileTitle(),
    this->GetAbout().GetFileDescription(),
    {

    },
    {

    }
  );
}

boost::shared_ptr<const ribi::Program> ribi::sadc::MenuDialog::GetProgram() const noexcept
{
  const boost::shared_ptr<const ribi::Program> p {
    new ProgramSearchAndDestroyChess
  };
  assert(p);
  return p;
}


std::string ribi::sadc::MenuDialog::GetVersion() const noexcept
{
  return "1.1";
}

std::vector<std::string> ribi::sadc::MenuDialog::GetVersionHistory() const noexcept
{
  return {
    "2011-06-28: Version 1.0: initial version",
    "2013-02-24: Version 1.1: testing done in seperate thread"
  };
}

#ifndef NDEBUG
void ribi::sadc::MenuDialog::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  #ifdef MXE_SUPPORTS_THREADS
  std::thread t(
    []
  #endif
    {
      FTRACE("Testing MenuDialog");
      MenuDialog();
      Chess::Game();
    }
  #ifdef MXE_SUPPORTS_THREADS
  );
  t.detach();
  #endif
}
#endif

 

 

 

 

 

./GameSearchAndDestroyChess/wtmain.cpp

 

//---------------------------------------------------------------------------
#include <Wt/WApplication>
#include <Wt/WContainerWidget>
#include <Wt/WEnvironment>
//---------------------------------------------------------------------------
#include "chessboard.h"
#include "chesssquare.h"
#include "wtautoconfig.h"
//#include "wtchessboardwidget.h"
#include "trace.h"
//---------------------------------------------------------------------------
struct WtChessBoardDialog : public Wt::WContainerWidget
{
  WtChessBoardDialog()
  {
    //this->addWidget(new ribi::Chess::WtBoardWidget);
    this->addWidget(new Wt::WBreak);
    //this->addWidget(new ribi::Chess::WtKriegspielWidget);
  }
};
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
  {
    this->setTitle("SearchAndDestroyChess");
    root()->addWidget(new WtChessBoardDialog);
  }
};

Wt::WApplication *createApplication(
  const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}

int main(int argc, char **argv)
{
  START_TRACE();
  ribi::WtAutoConfig a(argc,argv,createApplication);
  ribi::WtAutoConfig::SaveDefaultStylesheet();
  return a.Run();
}

/*
  a.AddLibrary("WtServerPusher version: " + WtServerPusher::GetVersion());
  a.AddLibrary("WtServerPusherClient version: " + WtServerPusherClient::GetVersion());
  a.AddLibrary("WtTimedServerPusher version: " + WtTimedServerPusher::GetVersion());
  a.AddLibrary("WtTimedServerPusherClient version: " + WtTimedServerPusherClient::GetVersion());
*/

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml