From 8c1e01ec122778a431d614c7c2fc15a191287005 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Wed, 6 Jan 2016 18:52:00 +0100 Subject: Generate shared ibraries for libquackle and libquackleio --- quackle.pro | 2 +- quackleio/quackleio.pro | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quackle.pro b/quackle.pro index 4bd40f4..37ce296 100644 --- a/quackle.pro +++ b/quackle.pro @@ -21,7 +21,7 @@ QMAKE_CXXFLAGS += -std=c++11 # enable/disable debug symbols #CONFIG += debug staticlib -CONFIG += release staticlib +CONFIG += release staticlib dll CONFIG -= x11 # Input diff --git a/quackleio/quackleio.pro b/quackleio/quackleio.pro index b48f58b..3c8b8ff 100644 --- a/quackleio/quackleio.pro +++ b/quackleio/quackleio.pro @@ -17,7 +17,7 @@ MOC_DIR = moc # enable/disable debug symbols #CONFIG += debug staticlib -CONFIG += release staticlib +CONFIG += release staticlib dll CONFIG -= x11 QMAKE_CXXFLAGS += -std=c++11 -- cgit v1.2.3 From df31cc20c63c9447ba057d599d48cc67c4555ca7 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Wed, 6 Jan 2016 18:52:51 +0100 Subject: GCGIO: Add a simple method to read GCG files using only the file names. --- quackleio/gcgio.cpp | 18 ++++++++++++++++++ quackleio/gcgio.h | 1 + 2 files changed, 19 insertions(+) diff --git a/quackleio/gcgio.cpp b/quackleio/gcgio.cpp index cafbf49..30fac0f 100644 --- a/quackleio/gcgio.cpp +++ b/quackleio/gcgio.cpp @@ -30,6 +30,24 @@ GCGIO::GCGIO() { } +Quackle::Game *GCGIO::read(const QString &filename, int flags) +{ + QFile file(filename); + Quackle::Game *ret = new Quackle::Game; + + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + UVcerr << "Could not open gcg " << QuackleIO::Util::qstringToString(filename) << endl; + return ret; + } + + QTextStream in(&file); + ret = read(in, flags); + file.close(); + + return ret; +} + Quackle::Game *GCGIO::read(QTextStream &stream, int flags) { Quackle::Game *ret = new Quackle::Game; diff --git a/quackleio/gcgio.h b/quackleio/gcgio.h index 477f84f..a219c9f 100644 --- a/quackleio/gcgio.h +++ b/quackleio/gcgio.h @@ -30,6 +30,7 @@ public: GCGIO(); ~GCGIO() {}; + virtual Quackle::Game *read(const QString &filename, int flags); virtual Quackle::Game *read(QTextStream &stream, int flags); virtual bool canRead(QTextStream &stream) const; virtual void write(const Quackle::Game &game, QTextStream &stream); -- cgit v1.2.3 From dcb66bd8ebe8a4f8ee6605b00af09e8a48ace0ff Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Wed, 6 Jan 2016 19:50:21 +0100 Subject: Add a SWIG interface file, a Bash script to generate Go, Python and Lua bindings and add Python test file. --- bindings/python/test.py | 63 ++++++++++++++++++++++++++++++ bindings/quackle.i | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ bindings/swig.sh | 22 +++++++++++ 3 files changed, 186 insertions(+) create mode 100644 bindings/python/test.py create mode 100644 bindings/quackle.i create mode 100644 bindings/swig.sh diff --git a/bindings/python/test.py b/bindings/python/test.py new file mode 100644 index 0000000..a5e2373 --- /dev/null +++ b/bindings/python/test.py @@ -0,0 +1,63 @@ +# coding: utf-8 + +import quackle + +# Set up the data manager +dm = quackle.DataManager() +dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) +dm.setBackupLexicon('twl06') +dm.setAppDataDirectory('../../data') + +# Set up the alphabet +abc = quackle.AlphabetParameters.findAlphabetFile('english') +fa = quackle.FlexibleAlphabetParameters() +assert fa.load(quackle.Util.stdStringToQString(abc)) +dm.setAlphabetParameters(fa) + +# Set up the board +board = quackle.BoardParameters() +dm.setBoardParameters(board) + +# Find the lexicon +dawg = quackle.LexiconParameters.findDictionaryFile('twl06.dawg') +gaddag = quackle.LexiconParameters.findDictionaryFile('twl06.gaddag') +dm.lexiconParameters().loadDawg(dawg) +dm.lexiconParameters().loadGaddag(gaddag) + +dm.strategyParameters().initialize('twl06') + +# Create a computer player +player1, found = dm.computerPlayers().playerForName('Speedy Player') +assert found +player1 = player1.computerPlayer() +print player1.name() + +# Create the Game file (.gcg) reader +gamereader = quackle.GCGIO() +game = gamereader.read(quackle.Util.stdStringToQString('../../test/positions/short_game_with_bad_moves.gcg'), + quackle.Logania.MaintainBoardPreparation) + +# Get the current position +position = game.currentPosition() + +player1.setPosition(position) + +racks = quackle.ProbableRackList() +unseenbag = position.unseenBag() +if unseenbag.size() <= dm.parameters().rackSize() + 3: + enum = quackle.Enumerator(unseenbag) + enum.enumerate(racks) + for rack in racks: + print rack + +movesToShow = 10 + +print "Board state: \n%s" % position.board().toString() +print "Move made: %s" % position.moveMade().toString() +print "Current player: %s" % position.currentPlayer().storeInformationToString() +print "Turn number: %i" % position.turnNumber() + +movelist = player1.moves(10) + +# Show 10 moves suggested by computer player +for move in movelist: print move.toString() diff --git a/bindings/quackle.i b/bindings/quackle.i new file mode 100644 index 0000000..8ded915 --- /dev/null +++ b/bindings/quackle.i @@ -0,0 +1,101 @@ +%module quackle +%{ +#include "fixedstring.h" +#include "uv.h" +#include "alphabetparameters.h" +#include "move.h" +#include "rack.h" +#include "bag.h" +#include "board.h" +#include "boardparameters.h" +#include "evaluator.h" +#include "catchall.h" +#include "player.h" +#include "game.h" +#include "gameparameters.h" +#include "sim.h" +#include "computerplayer.h" +#include "computerplayercollection.h" +#include "datamanager.h" +#include "endgame.h" +#include "endgameplayer.h" +#include "enumerator.h" +#include "bogowinplayer.h" +#include "clock.h" +#include "generator.h" +#include "gaddag.h" +#include "lexiconparameters.h" +#include "preendgame.h" +#include "reporter.h" +#include "resolvent.h" +#include "strategyparameters.h" + +#include +#include "quackleio/flexiblealphabet.h" +#include "quackleio/util.h" +#include "quackleio/logania.h" +#include "quackleio/gcgio.h" +%} + +%include "std_string.i" +%include "std_vector.i" + +/*Needed to generate proper iterable types */ +%template(MoveVector) std::vector; +%template(PlayerVector) std::vector; +%template(ProbableRackList) std::vector; +%template(PositionList) std::vector; + +%include "fixedstring.h" +%include "uv.h" +%include "alphabetparameters.h" +%include "move.h" +%include "rack.h" +%include "bag.h" +%include "board.h" +%include "boardparameters.h" +%include "evaluator.h" +%include "catchall.h" +%include "player.h" + +/* handle output arguments of PlayerList methods using cool SWIG typemaps */ +/* what we do here is just to tell SWIG that last bool& argument is an output argument */ +%include "typemaps.i" + +using namespace std; +namespace Quackle +{ + class PlayerList : public vector + { + public: + PlayerList(); + + const Player &playerForId(int id, bool &OUTPUT) const; + const Player &playerForName(const UVString &name, bool &OUTPUT) const; + }; +} + +%include "game.h" +%include "gameparameters.h" +%include "sim.h" +%include "computerplayer.h" +%include "computerplayercollection.h" +%include "datamanager.h" +%include "endgame.h" +%include "endgameplayer.h" +%include "enumerator.h" +%include "bogowinplayer.h" +%include "clock.h" +%include "generator.h" +%include "gaddag.h" +%include "lexiconparameters.h" +%include "preendgame.h" +%include "reporter.h" +%include "resolvent.h" +%include "strategyparameters.h" + +%include +%include "quackleio/flexiblealphabet.h" +%include "quackleio/util.h" +%include "quackleio/logania.h" +%include "quackleio/gcgio.h" diff --git a/bindings/swig.sh b/bindings/swig.sh new file mode 100644 index 0000000..62ec220 --- /dev/null +++ b/bindings/swig.sh @@ -0,0 +1,22 @@ +set -eu + +#################### Generate Python bindings +ln -sf ../../lib/release/libquackle.so.0 python/libquackle.so.0 +ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so +swig -c++ -o python/pyquackle.cxx -I../ `pkg-config QtCore --cflags` -python quackle.i +g++ -c -std=c++11 -fPIC python/pyquackle.cxx `pkg-config QtCore --cflags` `pkg-config python2 --cflags` -I../ -o python/pyquackle.o +g++ -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so python/pyquackle.o -o python/_quackle.so + +#################### Generate Go bindings +mkdir go +ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 +ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so +swig -c++ -o go/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -go -cgo -intgosize 64 quackle.i + +#################### Generate Lua bindings +mkdir lua +ln -sf ../../lib/release/libquackle.so.0 lua/libquackle.so.0 +ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so +swig -c++ -o lua/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -lua quackle.i +g++ -std=c++11 -fPIC `pkg-config lua52 --cflags` `pkg-config QtCore --cflags` -I../ -c lua/quackle_wrap.cxx -o lua/quackle_wrap.o +g++ -std=c++11 -shared `pkg-config lua52 --libs` ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so lua/quackle_wrap.o -o lua/quackle.so -- cgit v1.2.3 From d4424449fa86a8383761c6ae068a01d10e160c94 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Wed, 6 Jan 2016 20:00:10 +0100 Subject: bindings: Fix swig shared library extensions. --- bindings/swig.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/swig.sh b/bindings/swig.sh index 62ec220..8e069b0 100644 --- a/bindings/swig.sh +++ b/bindings/swig.sh @@ -2,7 +2,7 @@ set -eu #################### Generate Python bindings ln -sf ../../lib/release/libquackle.so.0 python/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so +ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so.0 swig -c++ -o python/pyquackle.cxx -I../ `pkg-config QtCore --cflags` -python quackle.i g++ -c -std=c++11 -fPIC python/pyquackle.cxx `pkg-config QtCore --cflags` `pkg-config python2 --cflags` -I../ -o python/pyquackle.o g++ -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so python/pyquackle.o -o python/_quackle.so @@ -10,13 +10,13 @@ g++ -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/lib #################### Generate Go bindings mkdir go ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so +ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so.0 swig -c++ -o go/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -go -cgo -intgosize 64 quackle.i #################### Generate Lua bindings mkdir lua ln -sf ../../lib/release/libquackle.so.0 lua/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so +ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so.0 swig -c++ -o lua/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -lua quackle.i g++ -std=c++11 -fPIC `pkg-config lua52 --cflags` `pkg-config QtCore --cflags` -I../ -c lua/quackle_wrap.cxx -o lua/quackle_wrap.o g++ -std=c++11 -shared `pkg-config lua52 --libs` ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so lua/quackle_wrap.o -o lua/quackle.so -- cgit v1.2.3 From 6c0e2acad583f74883510e00876331329bb4b8a0 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Thu, 7 Jan 2016 14:48:00 +0100 Subject: Replace swig bash script with a Makefile. --- bindings/Makefile | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bindings/swig.sh | 22 ---------------------- 2 files changed, 54 insertions(+), 22 deletions(-) create mode 100644 bindings/Makefile delete mode 100644 bindings/swig.sh diff --git a/bindings/Makefile b/bindings/Makefile new file mode 100644 index 0000000..5680f89 --- /dev/null +++ b/bindings/Makefile @@ -0,0 +1,54 @@ +CC=g++ + +QTFLAGS := $(shell pkg-config QtCore --cflags) +PYTHONFLAGS := $(shell pkg-config python2 --cflags) +LUAFLAGS := $(shell pkg-config lua52 --cflags) + +INCLUDES=-I.. + +python/quackle_wrap.cxx: + @test -d python || mkdir python + swig -c++ -o $@ $(INCLUDES) $(QTFLAGS) -python quackle.i + +python/quackle_wrap.o: python/quackle_wrap.cxx + $(CC) -c -std=c++11 -fPIC $< $(QTFLAGS) $(PYTHONFLAGS) $(INCLUDES) -o $@ + +python: python/quackle_wrap.o + ln -sf ../../lib/release/libquackle.so.0 python/libquackle.so.0 + ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so.0 + $(CC) -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o python/_quackle.so + +go: + @test -d go || mkdir go + ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 + ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so.0 + swig -c++ -o go/quackle_wrap.cxx -I../ $(QTFLAGS) -go -cgo -intgosize 64 quackle.i + +lua/quackle_wrap.cxx: + @test -d lua || mkdir lua + swig -c++ -o $@ $(INCLUDES) $(QTFLAGS) -lua quackle.i + +lua/quackle_wrap.o: lua/quackle_wrap.cxx + $(CC) -std=c++11 -fPIC $(LUAFLAGS) $(QTFLAGS) $(INCLUDES) -c $< -o $@ + +lua: lua/quackle_wrap.o + ln -sf ../../lib/release/libquackle.so.0 lua/libquackle.so.0 + ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so.0 + $(CC) -std=c++11 -shared $(LUAFLAGS) ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o lua/quackle.so + +.PHONY: clean + +clean: + -rm -rf python/libquackle.* + -rm -rf python/libquackleio.* + -rm -rf python/quackle.py + -rm -rf lua/libquackle.* + -rm -rf lua/libquackleio.* + -rm -rf go/libquackle.* + -rm -rf go/libquackleio.* + -rm -rf */*_wrap.cxx + -rm -rf */*.o + -rm -rf */*.pyc + -rm -rf */*.so + -rm -rf lua + -rm -rf go diff --git a/bindings/swig.sh b/bindings/swig.sh deleted file mode 100644 index 8e069b0..0000000 --- a/bindings/swig.sh +++ /dev/null @@ -1,22 +0,0 @@ -set -eu - -#################### Generate Python bindings -ln -sf ../../lib/release/libquackle.so.0 python/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so.0 -swig -c++ -o python/pyquackle.cxx -I../ `pkg-config QtCore --cflags` -python quackle.i -g++ -c -std=c++11 -fPIC python/pyquackle.cxx `pkg-config QtCore --cflags` `pkg-config python2 --cflags` -I../ -o python/pyquackle.o -g++ -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so python/pyquackle.o -o python/_quackle.so - -#################### Generate Go bindings -mkdir go -ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so.0 -swig -c++ -o go/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -go -cgo -intgosize 64 quackle.i - -#################### Generate Lua bindings -mkdir lua -ln -sf ../../lib/release/libquackle.so.0 lua/libquackle.so.0 -ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so.0 -swig -c++ -o lua/quackle_wrap.cxx -I../ `pkg-config QtCore --cflags` -lua quackle.i -g++ -std=c++11 -fPIC `pkg-config lua52 --cflags` `pkg-config QtCore --cflags` -I../ -c lua/quackle_wrap.cxx -o lua/quackle_wrap.o -g++ -std=c++11 -shared `pkg-config lua52 --libs` ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so lua/quackle_wrap.o -o lua/quackle.so -- cgit v1.2.3 From c7276ad4f627d3c3569996519de001431c04b1c0 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Thu, 7 Jan 2016 17:35:04 +0100 Subject: Tidy up Python test file and add extra vector typemaps to swig file. --- bindings/python/test.py | 73 ++++++++++++++++++++++++++++++------------------- bindings/quackle.i | 3 ++ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/bindings/python/test.py b/bindings/python/test.py index a5e2373..3a95808 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -2,40 +2,57 @@ import quackle -# Set up the data manager -dm = quackle.DataManager() -dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) -dm.setBackupLexicon('twl06') -dm.setAppDataDirectory('../../data') - -# Set up the alphabet -abc = quackle.AlphabetParameters.findAlphabetFile('english') -fa = quackle.FlexibleAlphabetParameters() -assert fa.load(quackle.Util.stdStringToQString(abc)) -dm.setAlphabetParameters(fa) - -# Set up the board -board = quackle.BoardParameters() -dm.setBoardParameters(board) - -# Find the lexicon -dawg = quackle.LexiconParameters.findDictionaryFile('twl06.dawg') -gaddag = quackle.LexiconParameters.findDictionaryFile('twl06.gaddag') -dm.lexiconParameters().loadDawg(dawg) -dm.lexiconParameters().loadGaddag(gaddag) - -dm.strategyParameters().initialize('twl06') +def startUp(lexicon='twl06', + alphabet='english', + datadir='../../data'): + + # Set up the data manager + dm = quackle.DataManager() + dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) + dm.setBackupLexicon(lexicon) + dm.setAppDataDirectory(datadir) + + # Set up the alphabet + abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) + abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring + fa = quackle.FlexibleAlphabetParameters() + fa.thisown = False + + assert fa.load(abc2) + dm.setAlphabetParameters(fa) + + # Set up the board + board = quackle.BoardParameters() + board.thisown = False + dm.setBoardParameters(board) + + # Find the lexicon + dawg = quackle.LexiconParameters.findDictionaryFile(lexicon + '.dawg') + gaddag = quackle.LexiconParameters.findDictionaryFile(lexicon + '.gaddag') + dm.lexiconParameters().loadDawg(dawg) + dm.lexiconParameters().loadGaddag(gaddag) + + dm.strategyParameters().initialize(lexicon) + return dm + + +def getComputerPlayer(dm, name='Speedy Player'): + player, found = dm.computerPlayers().playerForName(name) + assert found + player = player.computerPlayer() + return player + + +dm = startUp() # Create a computer player -player1, found = dm.computerPlayers().playerForName('Speedy Player') -assert found -player1 = player1.computerPlayer() +player1 = getComputerPlayer(dm) print player1.name() # Create the Game file (.gcg) reader gamereader = quackle.GCGIO() -game = gamereader.read(quackle.Util.stdStringToQString('../../test/positions/short_game_with_bad_moves.gcg'), - quackle.Logania.MaintainBoardPreparation) +gamePath = quackle.Util.stdStringToQString('../../test/positions/short_game_with_bad_moves.gcg') +game = gamereader.read(gamePath, quackle.Logania.MaintainBoardPreparation) # Get the current position position = game.currentPosition() diff --git a/bindings/quackle.i b/bindings/quackle.i index 8ded915..cc8e390 100644 --- a/bindings/quackle.i +++ b/bindings/quackle.i @@ -49,6 +49,9 @@ %include "fixedstring.h" %include "uv.h" %include "alphabetparameters.h" + +%template(LetterParameterVector) std::vector; +%template(LetterStringVector) std::vector; %include "move.h" %include "rack.h" %include "bag.h" -- cgit v1.2.3 From 027385d0ff9f1223cb98410a29937e38d82de397 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Thu, 7 Jan 2016 18:32:14 +0100 Subject: bindings: Add another python test file to demonstrate selfplay. --- bindings/python/test.py | 80 ---------------------------------- bindings/python/test1_position.py | 80 ++++++++++++++++++++++++++++++++++ bindings/python/test2_selfplay.py | 91 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+), 80 deletions(-) delete mode 100644 bindings/python/test.py create mode 100644 bindings/python/test1_position.py create mode 100644 bindings/python/test2_selfplay.py diff --git a/bindings/python/test.py b/bindings/python/test.py deleted file mode 100644 index 3a95808..0000000 --- a/bindings/python/test.py +++ /dev/null @@ -1,80 +0,0 @@ -# coding: utf-8 - -import quackle - -def startUp(lexicon='twl06', - alphabet='english', - datadir='../../data'): - - # Set up the data manager - dm = quackle.DataManager() - dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) - dm.setBackupLexicon(lexicon) - dm.setAppDataDirectory(datadir) - - # Set up the alphabet - abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) - abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring - fa = quackle.FlexibleAlphabetParameters() - fa.thisown = False - - assert fa.load(abc2) - dm.setAlphabetParameters(fa) - - # Set up the board - board = quackle.BoardParameters() - board.thisown = False - dm.setBoardParameters(board) - - # Find the lexicon - dawg = quackle.LexiconParameters.findDictionaryFile(lexicon + '.dawg') - gaddag = quackle.LexiconParameters.findDictionaryFile(lexicon + '.gaddag') - dm.lexiconParameters().loadDawg(dawg) - dm.lexiconParameters().loadGaddag(gaddag) - - dm.strategyParameters().initialize(lexicon) - return dm - - -def getComputerPlayer(dm, name='Speedy Player'): - player, found = dm.computerPlayers().playerForName(name) - assert found - player = player.computerPlayer() - return player - - -dm = startUp() - -# Create a computer player -player1 = getComputerPlayer(dm) -print player1.name() - -# Create the Game file (.gcg) reader -gamereader = quackle.GCGIO() -gamePath = quackle.Util.stdStringToQString('../../test/positions/short_game_with_bad_moves.gcg') -game = gamereader.read(gamePath, quackle.Logania.MaintainBoardPreparation) - -# Get the current position -position = game.currentPosition() - -player1.setPosition(position) - -racks = quackle.ProbableRackList() -unseenbag = position.unseenBag() -if unseenbag.size() <= dm.parameters().rackSize() + 3: - enum = quackle.Enumerator(unseenbag) - enum.enumerate(racks) - for rack in racks: - print rack - -movesToShow = 10 - -print "Board state: \n%s" % position.board().toString() -print "Move made: %s" % position.moveMade().toString() -print "Current player: %s" % position.currentPlayer().storeInformationToString() -print "Turn number: %i" % position.turnNumber() - -movelist = player1.moves(10) - -# Show 10 moves suggested by computer player -for move in movelist: print move.toString() diff --git a/bindings/python/test1_position.py b/bindings/python/test1_position.py new file mode 100644 index 0000000..3a95808 --- /dev/null +++ b/bindings/python/test1_position.py @@ -0,0 +1,80 @@ +# coding: utf-8 + +import quackle + +def startUp(lexicon='twl06', + alphabet='english', + datadir='../../data'): + + # Set up the data manager + dm = quackle.DataManager() + dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) + dm.setBackupLexicon(lexicon) + dm.setAppDataDirectory(datadir) + + # Set up the alphabet + abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) + abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring + fa = quackle.FlexibleAlphabetParameters() + fa.thisown = False + + assert fa.load(abc2) + dm.setAlphabetParameters(fa) + + # Set up the board + board = quackle.BoardParameters() + board.thisown = False + dm.setBoardParameters(board) + + # Find the lexicon + dawg = quackle.LexiconParameters.findDictionaryFile(lexicon + '.dawg') + gaddag = quackle.LexiconParameters.findDictionaryFile(lexicon + '.gaddag') + dm.lexiconParameters().loadDawg(dawg) + dm.lexiconParameters().loadGaddag(gaddag) + + dm.strategyParameters().initialize(lexicon) + return dm + + +def getComputerPlayer(dm, name='Speedy Player'): + player, found = dm.computerPlayers().playerForName(name) + assert found + player = player.computerPlayer() + return player + + +dm = startUp() + +# Create a computer player +player1 = getComputerPlayer(dm) +print player1.name() + +# Create the Game file (.gcg) reader +gamereader = quackle.GCGIO() +gamePath = quackle.Util.stdStringToQString('../../test/positions/short_game_with_bad_moves.gcg') +game = gamereader.read(gamePath, quackle.Logania.MaintainBoardPreparation) + +# Get the current position +position = game.currentPosition() + +player1.setPosition(position) + +racks = quackle.ProbableRackList() +unseenbag = position.unseenBag() +if unseenbag.size() <= dm.parameters().rackSize() + 3: + enum = quackle.Enumerator(unseenbag) + enum.enumerate(racks) + for rack in racks: + print rack + +movesToShow = 10 + +print "Board state: \n%s" % position.board().toString() +print "Move made: %s" % position.moveMade().toString() +print "Current player: %s" % position.currentPlayer().storeInformationToString() +print "Turn number: %i" % position.turnNumber() + +movelist = player1.moves(10) + +# Show 10 moves suggested by computer player +for move in movelist: print move.toString() diff --git a/bindings/python/test2_selfplay.py b/bindings/python/test2_selfplay.py new file mode 100644 index 0000000..4463c28 --- /dev/null +++ b/bindings/python/test2_selfplay.py @@ -0,0 +1,91 @@ +# coding: utf-8 + +import time + +import quackle + +def startUp(lexicon='twl06', + alphabet='english', + datadir='../../data'): + + # Set up the data manager + dm = quackle.DataManager() + dm.setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) + dm.setBackupLexicon(lexicon) + dm.setAppDataDirectory(datadir) + + # Set up the alphabet + abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) + abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring + fa = quackle.FlexibleAlphabetParameters() + fa.thisown = False + + assert fa.load(abc2) + dm.setAlphabetParameters(fa) + + # Set up the board + board = quackle.BoardParameters() + board.thisown = False + dm.setBoardParameters(board) + + # Find the lexicon + dawg = quackle.LexiconParameters.findDictionaryFile(lexicon + '.dawg') + gaddag = quackle.LexiconParameters.findDictionaryFile(lexicon + '.gaddag') + dm.lexiconParameters().loadDawg(dawg) + dm.lexiconParameters().loadGaddag(gaddag) + + dm.strategyParameters().initialize(lexicon) + return dm + + + return player + + +def getComputerPlayer(dm, name='Speedy Player'): + player, found = dm.computerPlayers().playerForName(name) + assert found + player = player.computerPlayer() + player.thisown = False + return player + + +dm = startUp() + +p1 = getComputerPlayer(dm) +p2 = getComputerPlayer(dm) + +# Create computer players +player1 = quackle.Player('Compy1', quackle.Player.ComputerPlayerType, 0) +player1.setComputerPlayer(p1) +print player1.name() + +player2 = quackle.Player('Compy2', quackle.Player.ComputerPlayerType, 1) +player2.setComputerPlayer(p2) +print player2.name() + +dm.seedRandomNumbers(42) + +game = quackle.Game() +players = quackle.PlayerList() + +players.append(player1) +players.append(player2) + +game.setPlayers(players) +game.associateKnownComputerPlayers() +game.addPosition() + +for i in range(50): + if game.currentPosition().gameOver(): + print "GAME OVER" + break + + player = game.currentPosition().currentPlayer() + player.thisown =False + move = game.haveComputerPlay() + #print "Player: " + player.name() + print "Rack : " + player.rack().toString() + print 'Move: ' + move.toString() + print 'Board: \n' + game.currentPosition().board().toString() + + time.sleep(1) -- cgit v1.2.3 From 8c0321f80411286ca60cbfdd11320df36b28cf2e Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Thu, 7 Jan 2016 18:47:22 +0100 Subject: Bindings: Remove unnecessary lines from Python selfplay test file --- bindings/python/test2_selfplay.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bindings/python/test2_selfplay.py b/bindings/python/test2_selfplay.py index 4463c28..1c41874 100644 --- a/bindings/python/test2_selfplay.py +++ b/bindings/python/test2_selfplay.py @@ -38,14 +38,10 @@ def startUp(lexicon='twl06', return dm - return player - - def getComputerPlayer(dm, name='Speedy Player'): player, found = dm.computerPlayers().playerForName(name) assert found player = player.computerPlayer() - player.thisown = False return player @@ -81,7 +77,6 @@ for i in range(50): break player = game.currentPosition().currentPlayer() - player.thisown =False move = game.haveComputerPlay() #print "Player: " + player.name() print "Rack : " + player.rack().toString() -- cgit v1.2.3 From 3235e28a041c08ecebef4bc63c38a91d772793c1 Mon Sep 17 00:00:00 2001 From: "H. İbrahim Güngör" Date: Thu, 7 Jan 2016 20:59:10 +0200 Subject: bindings/go: Use `go` tool to generate go bindings `go` tool can help build packages by recognizing `.swig` and `.swigcxx` extensions. It invokes the `swig` command internally while building the package. --- bindings/Makefile | 10 ++++++---- bindings/go/quackle.go | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 bindings/go/quackle.go diff --git a/bindings/Makefile b/bindings/Makefile index 5680f89..9a6665f 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -19,10 +19,10 @@ python: python/quackle_wrap.o $(CC) -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o python/_quackle.so go: - @test -d go || mkdir go + ln -sf ../quackle.i go/quackle.swigcxx ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so.0 - swig -c++ -o go/quackle_wrap.cxx -I../ $(QTFLAGS) -go -cgo -intgosize 64 quackle.i + go build ./go/... lua/quackle_wrap.cxx: @test -d lua || mkdir lua @@ -36,7 +36,7 @@ lua: lua/quackle_wrap.o ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so.0 $(CC) -std=c++11 -shared $(LUAFLAGS) ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o lua/quackle.so -.PHONY: clean +.PHONY: clean go clean: -rm -rf python/libquackle.* @@ -51,4 +51,6 @@ clean: -rm -rf */*.pyc -rm -rf */*.so -rm -rf lua - -rm -rf go + -rm -rf go/quackle.swigcxx + -rm -rf go/libquackle.* + -rm -rf go/libquackleio.* diff --git a/bindings/go/quackle.go b/bindings/go/quackle.go new file mode 100644 index 0000000..bbc53b8 --- /dev/null +++ b/bindings/go/quackle.go @@ -0,0 +1,6 @@ +package quackle + +// #cgo CXXFLAGS: -I../.. +// #cgo pkg-config: QtCore +// #cgo LDFLAGS: -L. -lquackle -lquackleio -lQtCore +import "C" -- cgit v1.2.3 From 77495bb0a6dc1df4c927852a0496f4991c5165b2 Mon Sep 17 00:00:00 2001 From: "H. İbrahim Güngör" Date: Thu, 7 Jan 2016 21:26:54 +0200 Subject: bindings/go: Set library path to current dir Use ${SRCDIR} directive to set library path as the current directory --- bindings/Makefile | 4 ++-- bindings/go/quackle.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bindings/Makefile b/bindings/Makefile index 9a6665f..1da34e4 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -20,8 +20,8 @@ python: python/quackle_wrap.o go: ln -sf ../quackle.i go/quackle.swigcxx - ln -sf ../../lib/release/libquackle.so.0 go/libquackle.so.0 - ln -sf ../../quackleio/lib/release/libquackleio.so.0 go/libquackleio.so.0 + ln -sf ../../lib/release/libquackle.so go/libquackle.so + ln -sf ../../quackleio/lib/release/libquackleio.so go/libquackleio.so go build ./go/... lua/quackle_wrap.cxx: diff --git a/bindings/go/quackle.go b/bindings/go/quackle.go index bbc53b8..66323a0 100644 --- a/bindings/go/quackle.go +++ b/bindings/go/quackle.go @@ -2,5 +2,5 @@ package quackle // #cgo CXXFLAGS: -I../.. // #cgo pkg-config: QtCore -// #cgo LDFLAGS: -L. -lquackle -lquackleio -lQtCore +// #cgo LDFLAGS: -L${SRCDIR} -lquackle -lquackleio -lQtCore import "C" -- cgit v1.2.3 From 5f6c8472451d321d3d55977444c84bf676657992 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Fri, 8 Jan 2016 10:55:13 +0100 Subject: bindings: Generate all bindings from static quackle libraries for convenience. --- bindings/Makefile | 23 +++++------------------ quackle.pro | 2 +- quackleio/quackleio.pro | 2 +- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/bindings/Makefile b/bindings/Makefile index 1da34e4..577e978 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -1,27 +1,25 @@ CC=g++ QTFLAGS := $(shell pkg-config QtCore --cflags) +QTLIBS := $(shell pkg-config QtCore --libs) PYTHONFLAGS := $(shell pkg-config python2 --cflags) LUAFLAGS := $(shell pkg-config lua52 --cflags) INCLUDES=-I.. +QUACKLELIBS=../lib/release/libquackle.a ../quackleio/lib/release/libquackleio.a python/quackle_wrap.cxx: @test -d python || mkdir python swig -c++ -o $@ $(INCLUDES) $(QTFLAGS) -python quackle.i python/quackle_wrap.o: python/quackle_wrap.cxx - $(CC) -c -std=c++11 -fPIC $< $(QTFLAGS) $(PYTHONFLAGS) $(INCLUDES) -o $@ + $(CC) -std=c++11 -fPIC $(QTFLAGS) $(PYTHONFLAGS) $(INCLUDES) -c $< -o $@ python: python/quackle_wrap.o - ln -sf ../../lib/release/libquackle.so.0 python/libquackle.so.0 - ln -sf ../../quackleio/lib/release/libquackleio.so.0 python/libquackleio.so.0 - $(CC) -std=c++11 -shared ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o python/_quackle.so + $(CC) -std=c++11 -shared -Wl,--whole-archive $(QUACKLELIBS) -Wl,--no-whole-archive $(QTLIBS) $< -o python/_quackle.so go: ln -sf ../quackle.i go/quackle.swigcxx - ln -sf ../../lib/release/libquackle.so go/libquackle.so - ln -sf ../../quackleio/lib/release/libquackleio.so go/libquackleio.so go build ./go/... lua/quackle_wrap.cxx: @@ -32,25 +30,14 @@ lua/quackle_wrap.o: lua/quackle_wrap.cxx $(CC) -std=c++11 -fPIC $(LUAFLAGS) $(QTFLAGS) $(INCLUDES) -c $< -o $@ lua: lua/quackle_wrap.o - ln -sf ../../lib/release/libquackle.so.0 lua/libquackle.so.0 - ln -sf ../../quackleio/lib/release/libquackleio.so.0 lua/libquackleio.so.0 - $(CC) -std=c++11 -shared $(LUAFLAGS) ../lib/release/libquackle.so ../quackleio/lib/release/libquackleio.so $< -o lua/quackle.so + $(CC) -std=c++11 -shared $(LUAFLAGS) -Wl,--whole-archive $(QUACKLELIBS) -Wl,--no-whole-archive $(QTLIBS) $< -o lua/quackle.so .PHONY: clean go clean: - -rm -rf python/libquackle.* - -rm -rf python/libquackleio.* -rm -rf python/quackle.py - -rm -rf lua/libquackle.* - -rm -rf lua/libquackleio.* - -rm -rf go/libquackle.* - -rm -rf go/libquackleio.* -rm -rf */*_wrap.cxx -rm -rf */*.o -rm -rf */*.pyc - -rm -rf */*.so -rm -rf lua -rm -rf go/quackle.swigcxx - -rm -rf go/libquackle.* - -rm -rf go/libquackleio.* diff --git a/quackle.pro b/quackle.pro index 37ce296..4bd40f4 100644 --- a/quackle.pro +++ b/quackle.pro @@ -21,7 +21,7 @@ QMAKE_CXXFLAGS += -std=c++11 # enable/disable debug symbols #CONFIG += debug staticlib -CONFIG += release staticlib dll +CONFIG += release staticlib CONFIG -= x11 # Input diff --git a/quackleio/quackleio.pro b/quackleio/quackleio.pro index 3c8b8ff..b48f58b 100644 --- a/quackleio/quackleio.pro +++ b/quackleio/quackleio.pro @@ -17,7 +17,7 @@ MOC_DIR = moc # enable/disable debug symbols #CONFIG += debug staticlib -CONFIG += release staticlib dll +CONFIG += release staticlib CONFIG -= x11 QMAKE_CXXFLAGS += -std=c++11 -- cgit v1.2.3 From 4b4fca57042535e176f061823382c26818d3d995 Mon Sep 17 00:00:00 2001 From: "H. İbrahim Güngör" Date: Fri, 8 Jan 2016 12:07:35 +0200 Subject: bindings/go: Use static libraries for Go bindings Search for the static libraries in their relative paths instead of symlinking into the build directory. --- bindings/go/quackle.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/go/quackle.go b/bindings/go/quackle.go index 66323a0..6c40a84 100644 --- a/bindings/go/quackle.go +++ b/bindings/go/quackle.go @@ -2,5 +2,5 @@ package quackle // #cgo CXXFLAGS: -I../.. // #cgo pkg-config: QtCore -// #cgo LDFLAGS: -L${SRCDIR} -lquackle -lquackleio -lQtCore +// #cgo LDFLAGS: -L${SRCDIR}/../../lib/release -L${SRCDIR}/../../quackleio/lib/release -lquackle -lquackleio -lQtCore import "C" -- cgit v1.2.3 From 11c010c445f4dc00c1d92fd13c5ea40df5cbecfe Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Fri, 8 Jan 2016 11:22:24 +0100 Subject: bindings: Clean up .so files as well. --- bindings/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/Makefile b/bindings/Makefile index 577e978..702d678 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -38,6 +38,7 @@ clean: -rm -rf python/quackle.py -rm -rf */*_wrap.cxx -rm -rf */*.o + -rm -rf */*.so -rm -rf */*.pyc -rm -rf lua -rm -rf go/quackle.swigcxx -- cgit v1.2.3 From 80bc5b91205dd48870e5134b0c71a78718253a95 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Sun, 24 Jan 2016 13:15:51 +0100 Subject: bindings: Add a lua test file and compile with lua5.1 for luajit compatibility. --- bindings/Makefile | 3 +- bindings/lua/test_selfplay.lua | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 bindings/lua/test_selfplay.lua diff --git a/bindings/Makefile b/bindings/Makefile index 702d678..55d1164 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -3,7 +3,7 @@ CC=g++ QTFLAGS := $(shell pkg-config QtCore --cflags) QTLIBS := $(shell pkg-config QtCore --libs) PYTHONFLAGS := $(shell pkg-config python2 --cflags) -LUAFLAGS := $(shell pkg-config lua52 --cflags) +LUAFLAGS := $(shell pkg-config lua5.1 --cflags) INCLUDES=-I.. QUACKLELIBS=../lib/release/libquackle.a ../quackleio/lib/release/libquackleio.a @@ -40,5 +40,4 @@ clean: -rm -rf */*.o -rm -rf */*.so -rm -rf */*.pyc - -rm -rf lua -rm -rf go/quackle.swigcxx diff --git a/bindings/lua/test_selfplay.lua b/bindings/lua/test_selfplay.lua new file mode 100644 index 0000000..4be6c28 --- /dev/null +++ b/bindings/lua/test_selfplay.lua @@ -0,0 +1,88 @@ +require 'quackle' + +function startUp(lexicon, alphabet, datadir) + + local lexicon = lexicon and lexicon or 'twl06' + local alphabet = alphabet and alphabet or 'english' + local datadir = datadir and datadir or '../../data' + + -- Set up the data manager + local dm = quackle.DataManager() + dm:setComputerPlayers(quackle.ComputerPlayerCollection.fullCollection()) + dm:setBackupLexicon(lexicon) + dm:setAppDataDirectory(datadir) + + -- Set up the alphabet + local abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) + local abc2 = quackle.Util.stdStringToQString(abc) --convert to qstring + local fa = quackle.FlexibleAlphabetParameters() + + assert(fa:load(abc2)) + dm:setAlphabetParameters(fa) + + -- Set up the board + local board = quackle.BoardParameters() + dm:setBoardParameters(board) + + -- Find the lexicon + local dawg = quackle.LexiconParameters.findDictionaryFile(lexicon .. '.dawg') + local gaddag = quackle.LexiconParameters.findDictionaryFile(lexicon .. '.gaddag') + dm:lexiconParameters():loadDawg(dawg) + dm:lexiconParameters():loadGaddag(gaddag) + + dm:strategyParameters():initialize(lexicon) + return dm + +end + + +function getComputerPlayer(dm, name) + + local name = name and name or 'Speedy Player' + local player, found = dm:computerPlayers():playerForName(name) + assert(found) + player = player:computerPlayer() + return player + +end + +dm = startUp() + +p1 = getComputerPlayer(dm) +p2 = getComputerPlayer(dm) + +-- Create computer players +player1 = quackle.Player('Compy1', quackle.Player.ComputerPlayerType, 0) +player1:setComputerPlayer(p1) +print(player1:name()) + +player2 = quackle.Player('Compy2', quackle.Player.ComputerPlayerType, 1) +player2:setComputerPlayer(p2) +print(player2:name()) + +dm:seedRandomNumbers(42) + +game = quackle.Game() +players = quackle.PlayerList() + +players:push_back(player1) +players:push_back(player2) + +game:setPlayers(players) +game:associateKnownComputerPlayers() +game:addPosition() + +for i=1, 50 do + if game:currentPosition():gameOver() then + print "GAME OVER" + break + end + + player = game:currentPosition():currentPlayer() + move = game:haveComputerPlay() + --print("Player: " .. player:name()) + print("Rack : " .. player:rack():toString()) + print('Move: ' .. move:toString()) + print('Board: \n' .. game:currentPosition():board():toString()) + +end -- cgit v1.2.3 From 49ff349b67c7fed35782bf6407242fe58ef654c7 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Sun, 24 Jan 2016 13:18:24 +0100 Subject: bindings: Fix DataManager ownership problems using DISOWN. --- bindings/python/test1_position.py | 2 -- bindings/python/test2_selfplay.py | 2 -- bindings/quackle.i | 25 ++++++++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bindings/python/test1_position.py b/bindings/python/test1_position.py index 3a95808..e04081a 100644 --- a/bindings/python/test1_position.py +++ b/bindings/python/test1_position.py @@ -16,14 +16,12 @@ def startUp(lexicon='twl06', abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring fa = quackle.FlexibleAlphabetParameters() - fa.thisown = False assert fa.load(abc2) dm.setAlphabetParameters(fa) # Set up the board board = quackle.BoardParameters() - board.thisown = False dm.setBoardParameters(board) # Find the lexicon diff --git a/bindings/python/test2_selfplay.py b/bindings/python/test2_selfplay.py index 1c41874..bb6e889 100644 --- a/bindings/python/test2_selfplay.py +++ b/bindings/python/test2_selfplay.py @@ -18,14 +18,12 @@ def startUp(lexicon='twl06', abc = quackle.AlphabetParameters.findAlphabetFile(alphabet) abc2 = quackle.Util.stdStringToQString(abc) #convert to qstring fa = quackle.FlexibleAlphabetParameters() - fa.thisown = False assert fa.load(abc2) dm.setAlphabetParameters(fa) # Set up the board board = quackle.BoardParameters() - board.thisown = False dm.setBoardParameters(board) # Find the lexicon diff --git a/bindings/quackle.i b/bindings/quackle.i index cc8e390..e45eb88 100644 --- a/bindings/quackle.i +++ b/bindings/quackle.i @@ -37,21 +37,23 @@ #include "quackleio/gcgio.h" %} + %include "std_string.i" %include "std_vector.i" +%include "typemaps.i" + +%include "fixedstring.h" +%include "uv.h" +%include "alphabetparameters.h" /*Needed to generate proper iterable types */ %template(MoveVector) std::vector; %template(PlayerVector) std::vector; %template(ProbableRackList) std::vector; %template(PositionList) std::vector; - -%include "fixedstring.h" -%include "uv.h" -%include "alphabetparameters.h" - %template(LetterParameterVector) std::vector; %template(LetterStringVector) std::vector; + %include "move.h" %include "rack.h" %include "bag.h" @@ -61,10 +63,6 @@ %include "catchall.h" %include "player.h" -/* handle output arguments of PlayerList methods using cool SWIG typemaps */ -/* what we do here is just to tell SWIG that last bool& argument is an output argument */ -%include "typemaps.i" - using namespace std; namespace Quackle { @@ -83,6 +81,15 @@ namespace Quackle %include "sim.h" %include "computerplayer.h" %include "computerplayercollection.h" + +%apply SWIGTYPE *DISOWN {Quackle::AlphabetParameters *alphabetParameters}; +%apply SWIGTYPE *DISOWN {Quackle::BoardParameters *boardParameters}; +%apply SWIGTYPE *DISOWN {Quackle::StrategyParameters *lexiconParameters}; +%apply SWIGTYPE *DISOWN {Quackle::LexiconParameters *lexiconParameters}; +%apply SWIGTYPE *DISOWN {Quackle::Evaluator *evaluator}; +%apply SWIGTYPE *DISOWN {Quackle::GameParameters *parameters}; +%apply SWIGTYPE *DISOWN {const Quackle::PlayerList &playerList}; + %include "datamanager.h" %include "endgame.h" %include "endgameplayer.h" -- cgit v1.2.3 From 7c2d25968459b9268b51a9ac0c15f66c4b73a800 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Sun, 24 Jan 2016 13:53:17 +0100 Subject: bindings: Fix lua default argument trick. --- bindings/lua/test_selfplay.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bindings/lua/test_selfplay.lua b/bindings/lua/test_selfplay.lua index 4be6c28..9209f52 100644 --- a/bindings/lua/test_selfplay.lua +++ b/bindings/lua/test_selfplay.lua @@ -2,9 +2,9 @@ require 'quackle' function startUp(lexicon, alphabet, datadir) - local lexicon = lexicon and lexicon or 'twl06' - local alphabet = alphabet and alphabet or 'english' - local datadir = datadir and datadir or '../../data' + local lexicon = lexicon or 'twl06' + local alphabet = alphabet or 'english' + local datadir = datadir or '../../data' -- Set up the data manager local dm = quackle.DataManager() @@ -38,10 +38,12 @@ end function getComputerPlayer(dm, name) - local name = name and name or 'Speedy Player' + local name = name or 'Speedy Player' + local player, found = dm:computerPlayers():playerForName(name) assert(found) player = player:computerPlayer() + return player end -- cgit v1.2.3 From 147b22ae1225863cac9f07b3906415713afdcf02 Mon Sep 17 00:00:00 2001 From: Gökçen Eraslan Date: Sat, 20 Feb 2016 10:38:26 +0100 Subject: Add PHP bindings, tested with PHP 5.6 --- bindings/Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/bindings/Makefile b/bindings/Makefile index 55d1164..9cdb6a3 100644 --- a/bindings/Makefile +++ b/bindings/Makefile @@ -3,11 +3,23 @@ CC=g++ QTFLAGS := $(shell pkg-config QtCore --cflags) QTLIBS := $(shell pkg-config QtCore --libs) PYTHONFLAGS := $(shell pkg-config python2 --cflags) +PHPFLAGS := $(shell php-config --includes) +PHPLIBS := $(shell php-config --libs) LUAFLAGS := $(shell pkg-config lua5.1 --cflags) INCLUDES=-I.. QUACKLELIBS=../lib/release/libquackle.a ../quackleio/lib/release/libquackleio.a +php/quackle_wrap.cxx: + @test -d php || mkdir php + swig -c++ -o $@ $(INCLUDES) $(QTFLAGS) -php quackle.i + +php/quackle_wrap.o: php/quackle_wrap.cxx + $(CC) -std=c++11 -fPIC $(QTFLAGS) $(PHPFLAGS) $(PHPLIBS) $(INCLUDES) -c $< -o $@ + +php: php/quackle_wrap.o + $(CC) -std=c++11 -shared -Wl,--whole-archive $(QUACKLELIBS) -Wl,--no-whole-archive $(QTLIBS) $< -o php/quackle.so + python/quackle_wrap.cxx: @test -d python || mkdir python swig -c++ -o $@ $(INCLUDES) $(QTFLAGS) -python quackle.i @@ -36,6 +48,7 @@ lua: lua/quackle_wrap.o clean: -rm -rf python/quackle.py + -rm -rf php/*php* -rm -rf */*_wrap.cxx -rm -rf */*.o -rm -rf */*.so -- cgit v1.2.3