diff --git a/dealer_random_test.pro b/dealer_random_test.pro new file mode 100644 index 00000000..0e3c228d --- /dev/null +++ b/dealer_random_test.pro @@ -0,0 +1,93 @@ +# QMake pro-file for the PokerTH dedicated server + +isEmpty( PREFIX ){ + PREFIX =/usr +} + +TEMPLATE = app +CODECFORSRC = UTF-8 + +CONFIG += thread console embed_manifest_exe exceptions rtti stl warn_on + +UI_DIR = uics +TARGET = bin/connectivity +MOC_DIR = mocs +OBJECTS_DIR = obj +DEFINES += PREFIX=\"$${PREFIX}\" +QT -= core gui +#PRECOMPILED_HEADER = src/pch_lib.h + +INCLUDEPATH += . \ + src +DEPENDPATH += . \ + src + +# Input +HEADERS += \ + src/game_defs.h \ + src/net/netpacket.h \ + src/third_party/protobuf/pokerth.pb.h + +SOURCES += \ + src/dealer_random_test.cpp \ + src/net/common/netpacket.cpp \ + src/third_party/protobuf/pokerth.pb.cc + +unix : !mac { + + ##### My release static build options + #QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections + #QMAKE_LFLAGS += -Wl,--gc-sections + + QMAKE_LIBDIR += lib $${PREFIX}/lib /opt/gsasl/lib + INCLUDEPATH += $${PREFIX}/include + LIB_DIRS = $${PREFIX}/lib $${PREFIX}/lib64 $$system($$QMAKE_QMAKE -query QT_INSTALL_LIBS) + BOOST_PROGRAM_OPTIONS = boost_program_options boost_program_options-mt + BOOST_SYS = boost_system boost_system-mt + + + # + # searching in $PREFIX/lib, $PREFIX/lib64 and $$system($$QMAKE_QMAKE -query QT_INSTALL_LIBS) + # to override the default '/usr' pass PREFIX + # variable to qmake. + # + for(dir, LIB_DIRS){ + exists($$dir){ + for(lib, BOOST_PROGRAM_OPTIONS):exists($${dir}/lib$${lib}.so*) { + message("Found $$lib") + BOOST_PROGRAM_OPTIONS = -l$$lib + } + for(lib, BOOST_PROGRAM_OPTIONS):exists($${dir}/lib$${lib}.a) { + message("Found $$lib") + BOOST_PROGRAM_OPTIONS = -l$$lib + } + for(lib, BOOST_SYS):exists($${dir}/lib$${lib}.so*) { + message("Found $$lib") + BOOST_SYS = -l$$lib + } + for(lib, BOOST_SYS):exists($${dir}/lib$${lib}.a) { + message("Found $$lib") + BOOST_SYS = -l$$lib + } + } + } + BOOST_LIBS = $$BOOST_PROGRAM_OPTIONS $$BOOST_SYS + !count(BOOST_LIBS, 2){ + error("Unable to find boost libraries in PREFIX=$${PREFIX}") + } + + UNAME = $$system(uname -s) + BSD = $$find(UNAME, "BSD") + kFreeBSD = $$find(UNAME, "kFreeBSD") + + LIBS += $$BOOST_LIBS + LIBS += -lprotobuf -lgsasl -lgcrypt -lidn + + #### INSTALL #### + + binary.path += $${PREFIX}/bin/ + binary.files += connectivity + + INSTALLS += binary +} + diff --git a/src/dealer_random_test.cpp b/src/dealer_random_test.cpp new file mode 100644 index 00000000..8ba9ac13 --- /dev/null +++ b/src/dealer_random_test.cpp @@ -0,0 +1,111 @@ +/***************************************************************************** + * PokerTH - The open source texas holdem engine * + * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU Affero 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 Affero General Public License for more details. * + * * + * You should have received a copy of the GNU Affero General Public License * + * along with this program. If not, see . * + * * + * * + * Additional permission under GNU AGPL version 3 section 7 * + * * + * If you modify this program, or any covered work, by linking or * + * combining it with the OpenSSL project's OpenSSL library (or a * + * modified version of that library), containing parts covered by the * + * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH * + * (Felix Hammer, Florian Thauer, Lothar May) grant you additional * + * permission to convey the resulting work. * + * Corresponding Source for a non-source form of such a combination * + * shall include the source code for the parts of OpenSSL used as well * + * as that of the covered work. * + *****************************************************************************/ + +// Connectivity test program for PokerTH + +#include +#include +#include +#include +#include + + +using namespace std; +namespace po = boost::program_options; +boost::thread_specific_ptr g_rand_state; + +struct nondet_rng : std::unary_function { + boost::random_device &_state; + unsigned operator()(unsigned i) + { + boost::uniform_int<> rng(0, i - 1); + return rng(_state); + } + nondet_rng(boost::random_device &state) : _state(state) {} +}; + + +int +main(int argc, char *argv[]) +{ + try { + // Check command line options. + po::options_description desc("Allowed options"); + desc.add_options() + ("help,h", "produce help message") + ("num,n", po::value(), "set num of deals") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + if (vm.count("help")) { + cout << desc << endl; + return 1; + } + if (!vm.count("mode")) { + cout << "Missing option!" << endl << desc << endl; + return 1; + } + + int num = vm["num"].as(); + const int NumCards = 52; + + for(int i=0; i<=num;i++){ + // shuffle cards + int cardsArray[NumCards] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51 + }; + if (!g_rand_state.get()) { + g_rand_state.reset(new boost::random_device); + } + nondet_rng rand(*g_rand_state); + random_shuffle(&cardsArray[0], &cardsArray[NumCards], rand); + + ostringstream oss(""); + for (int temp = 0; temp < size_of_array; temp++) + oss << int_array[temp]; + cout << oss << endl; + + } catch (...) { + cout << "Exception caught" << endl; + return 1; + } + + return 0; +} +