V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
200
V2EX  ›  Python

写了一个命令行版的 2048

  •  
  •   200 · 2014-03-15 00:00:32 +08:00 · 4519 次点击
    这是一个创建于 3667 天前的主题,其中的信息可能已经有所发展或是发生改变。
    原版: http://gabrielecirulli.github.io/2048/

    可以考虑跑些搜索 看看有没有好的策略啥的 (¬_¬)

    7 条回复    2014-05-01 09:02:07 +08:00
    ericls
        1
    ericls  
       2014-03-15 15:25:41 +08:00
    这游戏一不小心玩儿了3个小时 我LGQ
    yangff
        2
    yangff  
       2014-03-15 21:32:16 +08:00 via Android
    早就有ai了。。
    jprovim
        3
    jprovim  
       2014-03-16 09:37:31 +08:00
    挑個毛病,使用AWSD操作,而且還需要輸入Enter。
    總體來說還是很好的。
    patricksong1993
        4
    patricksong1993  
       2014-03-16 23:44:49 +08:00
    2048升级版4096
    自带超快机器人
    http://patricksong1993.github.io/4096/
    rex
        5
    rex  
       2014-03-18 14:14:31 +08:00
    @jprovim @200
    可以使用

    ```
    def getkey():
    "get key press without Enter"

    import termios, sys, os

    fd = sys.stdin.fileno()
    old = termios.tcgetattr(fd)
    new = termios.tcgetattr(fd)
    new[3] = new[3] & ~TERMIOS.ICANON & ~TERMIOS.ECHO
    new[6][TERMIOS.VMIN] = 1
    new[6][TERMIOS.VTIME] = 0
    termios.tcsetattr(fd, TERMIOS.TCSANOW, new)
    c = None
    try:
    c = os.read(fd, 1)
    finally:
    termios.tcsetattr(fd, TERMIOS.TCSAFLUSH, old)
    return c
    ```

    代替sys.stdin.readline().strip().lower(),这样就不必 enter 了。
    rex
        6
    rex  
       2014-03-18 14:16:09 +08:00
    排版乱了。
    贴个链接试试

    https://gist.github.com/zhasm/9614482
    jprovim
        7
    jprovim  
       2014-05-01 09:02:07 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1509 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:54 · PVG 07:54 · LAX 16:54 · JFK 19:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.