Posts: 4,229
Threads: 97
Joined: Sep 2016
I've been working on a suite of command-line interface (text) games called t_games. It's got 32 games at the moment, but it's designed to be modular so that more game can easily be added. I was hoping to get some other people to download it (github repository here) and try it out, see what they think, see if they find any bugs I missed.
If you're interested, have at it. You can provide feed back here, or I set up an email just for this project: t_admin at xenomind dot com.
Here's the current list of games:
- Backgammon
- Battleships
- Bisley
- Blackjack
- Canfield
- Connect Four
- Craps
- Crazy Eights
- Cribbage
- Forty Thieves
- FreeCell
- Gargantua
- Hamurabi
- Hangman
- Hunt the Wumpus
- Klondike
- Liar's Dice
- Mate
- Monte Carlo
- Ninety-Nine
- Oregon Trail
- Pig
- Pyramid
- Quadrille
- Rock-Paper-Scissors
- Roulette
- Solitaire Dice
- Spider
- Strategy
- Thoughtful Solitaire
- Yacht
- Yukon
It's a bit biased toward solitaire games, but that's how it started out, and they have enough similarities that I made a class just for them that makes them easier to program.
Posts: 11,875
Threads: 474
Joined: Sep 2016
Jan-01-2019, 01:59 AM
(This post was last modified: Jan-01-2019, 01:59 AM by Larz60+.)
I'll see if I can get my grandson to download.
I know he'll run them all, just not so sure about feedback, (he's 13, an awkward age)
I'll play with it a bit myself tomorrow, especially backgammon as I'm a big fan.
Posts: 5,150
Threads: 396
Joined: Sep 2016
i cant figure out how to run them.
metulburr@ubuntu:~/repos/t_games/t_games$ python play.py
Traceback (most recent call last):
File "play.py", line 19, in <module>
import t_games.interface as interface
ImportError: No module named t_games.interface metulburr@ubuntu:~/repos/t_games/t_games$ python3 play.py
Traceback (most recent call last):
File "play.py", line 19, in <module>
import t_games.interface as interface
ModuleNotFoundError: No module named 't_games' metulburr@ubuntu:~/repos/t_games$ python3
Python 3.6.1 (default, Jun 8 2017, 06:36:16)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_games
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/metulburr/repos/t_games/t_games/__init__.py", line 28, in <module>
from t_games.test import test
File "/home/metulburr/repos/t_games/t_games/test.py", line 56, in <module>
test = Test()
File "/home/metulburr/repos/t_games/t_games/test.py", line 38, in __init__
self.human = player.Tester()
File "/home/metulburr/repos/t_games/t_games/player.py", line 494, in __init__
self.load_shortcuts()
File "/home/metulburr/repos/t_games/t_games/player.py", line 431, in load_shortcuts
with open(os.path.join(self.folder_name, 'shortcuts.txt')) as player_data:
FileNotFoundError: [Errno 2] No such file or directory: '/home/metulburr/repos/t_games/t_games/buckaroo-testing-black/shortcuts.txt' metulburr@ubuntu:~/repos/t_games/t_games/gambling_games$ python3 craps_game.py
Traceback (most recent call last):
File "craps_game.py", line 44, in <module>
import t_games.dice as dice
ModuleNotFoundError: No module named 't_games'
Recommended Tutorials:
Posts: 4,229
Threads: 97
Joined: Sep 2016
Jan-01-2019, 03:44 AM
(This post was last modified: Jan-01-2019, 04:03 AM by ichabod801.)
(Jan-01-2019, 02:28 AM)metulburr Wrote: i cant figure out how to run them.
Is the folder in your python path?
I ran into problems with absolute imports and used relative ones. Maybe I need to go back to absolute.
Edit: Now I have no idea. I made a copy outside my python path and it runs fine.
Edit: Well, duh, it's accessing the ones in my pythonpath.
Posts: 11,875
Threads: 474
Joined: Sep 2016
using pathlib for relative paths makes it easy, here's a sample:
from pathlib import Path
import os
class ConnectedPaths:
def __init__(self):
os.chdir(os.path.abspath(os.path.dirname(__file__)))
self.homepath = Path('.')
self.rootpath = self.homepath / '..'
self.datapath = self.rootpath / 'data'
self.datapath.mkdir(exist_ok=True)
self.tmppath = self.datapath / 'tmp'
self.tmppath.mkdir(exist_ok=True)
self.docpath = self.datapath / 'doc'
self.docpath.mkdir(exist_ok=True)
if __name__ == '__main__':
ConnectedPaths() usage:
import ConnectedPaths
class Data(object):
def __init__(self):
self.cpath = ConnectedPaths.ConnectedPaths()
tmpfile = self.cpath.tmppath / 'tempdata.dat'
with tmpfile.open() as fp:
maindata = fp.read() so to access the ../data/tmp directory, use:
Posts: 5,150
Threads: 396
Joined: Sep 2016
Jan-01-2019, 06:19 PM
(This post was last modified: Jan-01-2019, 06:19 PM by metulburr.)
(Jan-01-2019, 03:44 AM)ichabod801 Wrote: Is the folder in your python path? I dont see why one would have to put games in the path to be able to run them. I think they should be able to run independently. Having said that, i get the same error after adding it to the path
metulburr@ubuntu:~/repos/t_games$ python3
Python 3.6.1 (default, Jun 8 2017, 06:36:16)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append('/home/metulburr/repos/t_games')
>>> import t_games
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/metulburr/repos/t_games/t_games/__init__.py", line 28, in <module>
from t_games.test import test
File "/home/metulburr/repos/t_games/t_games/test.py", line 56, in <module>
test = Test()
File "/home/metulburr/repos/t_games/t_games/test.py", line 38, in __init__
self.human = player.Tester()
File "/home/metulburr/repos/t_games/t_games/player.py", line 494, in __init__
self.load_shortcuts()
File "/home/metulburr/repos/t_games/t_games/player.py", line 431, in load_shortcuts
with open(os.path.join(self.folder_name, 'shortcuts.txt')) as player_data:
FileNotFoundError: [Errno 2] No such file or directory: '/home/metulburr/repos/t_games/t_games/buckaroo-testing-black/shortcuts.txt' Although the error is accurate. There doesnt seem to be a shortcuts text file there
metulburr@ubuntu:~/repos/t_games/t_games/buckaroo-testing-black$ ls
results.txt
metulburr@ubuntu:
Recommended Tutorials:
Posts: 4,229
Threads: 97
Joined: Sep 2016
(Jan-01-2019, 06:19 PM)metulburr Wrote: I think they should be able to run independently.
I agree. But there were problems getting the imports to work in both 2.7 and 3.6. I'll see if I can straighten them out another way.
Posts: 4,229
Threads: 97
Joined: Sep 2016
I just uploaded a fix to the tester shortcuts problem, or you can use play.py, which creates a user folder you need to log into at the start.
Posts: 5,150
Threads: 396
Joined: Sep 2016
Jan-01-2019, 09:53 PM
(This post was last modified: Jan-01-2019, 09:53 PM by metulburr.)
i tried it and i still get errors with play.py or importing.
metulburr@ubuntu:~/repos/t_games/t_games$ python play.py
Traceback (most recent call last):
File "play.py", line 19, in <module>
import t_games.interface as interface
ImportError: No module named t_games.interface
metulburr@ubuntu:~/repos/t_games/t_games$ python3 play.py
Traceback (most recent call last):
File "play.py", line 19, in <module>
import t_games.interface as interface
ModuleNotFoundError: No module named 't_games'
metulburr@ubuntu:~/repos/t_games/t_games$ cd ..
metulburr@ubuntu:~/repos/t_games$ python3
Python 3.6.1 (default, Jun 8 2017, 06:36:16)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_games
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/metulburr/repos/t_games/t_games/__init__.py", line 28, in <module>
from t_games.test import test
File "/home/metulburr/repos/t_games/t_games/test.py", line 56, in <module>
test = Test()
File "/home/metulburr/repos/t_games/t_games/test.py", line 38, in __init__
self.human = player.Tester()
File "/home/metulburr/repos/t_games/t_games/player.py", line 496, in __init__
self.load_shortcuts()
File "/home/metulburr/repos/t_games/t_games/player.py", line 436, in load_shortcuts
if not line.endswith('\n'):
UnboundLocalError: local variable 'line' referenced before assignment
>>> exit()
metulburr@ubuntu:~/repos/t_games$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_games
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "t_games/__init__.py", line 28, in <module>
from t_games.test import test
File "t_games/test.py", line 56, in <module>
test = Test()
File "t_games/test.py", line 38, in __init__
self.human = player.Tester()
File "t_games/player.py", line 496, in __init__
self.load_shortcuts()
File "t_games/player.py", line 436, in load_shortcuts
if not line.endswith('\n'):
UnboundLocalError: local variable 'line' referenced before assignment
>>> import sys
>>> sys.path.append('/home/metulburr/repos/t_games')
>>> import t_games
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "t_games/__init__.py", line 23, in <module>
import t_games.dice as dice
AttributeError: 'module' object has no attribute 'dice'
>>>
Recommended Tutorials:
Posts: 4,229
Threads: 97
Joined: Sep 2016
Alright, never mind. I'll go back to the drawing board on the imports.
|