diff options
author | Martin DeMello <mdemello@google.com> | 2019-02-06 20:11:58 -0800 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2019-02-07 16:20:28 -0600 |
commit | d387d2e719f736d28db797d47ffc4fca29a202fa (patch) | |
tree | 100d4b6c794f855acfbcb878b8163cd59b3a8d75 /bindings/python | |
parent | 3ce63c2e3f4056f6fe8f4191de41290a87f42730 (diff) |
Add separate python2 and python3 targets, and a flag for Qt version.
Diffstat (limited to 'bindings/python')
-rw-r--r-- | bindings/python/test1_position.py | 78 | ||||
-rw-r--r-- | bindings/python/test2_selfplay.py | 84 |
2 files changed, 0 insertions, 162 deletions
diff --git a/bindings/python/test1_position.py b/bindings/python/test1_position.py deleted file mode 100644 index e04081a..0000000 --- a/bindings/python/test1_position.py +++ /dev/null @@ -1,78 +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() - - assert fa.load(abc2) - dm.setAlphabetParameters(fa) - - # Set up the board - board = quackle.BoardParameters() - 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 deleted file mode 100644 index bb6e889..0000000 --- a/bindings/python/test2_selfplay.py +++ /dev/null @@ -1,84 +0,0 @@ -# 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() - - assert fa.load(abc2) - dm.setAlphabetParameters(fa) - - # Set up the board - board = quackle.BoardParameters() - 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() - -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() - 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) |