实时人工智能德州扑克,使用Python和Flask – 在浏览器中玩
Real-Time AI-Powered Texas Hold'em in Python and Flask – Play in the Browser

原始链接: https://github.com/EMMA019/AI_pokergame

## 午夜奢华扑克:实时德州扑克游戏 午夜奢华扑克是一款使用Flask-SocketIO和现代前端构建的精致实时德州扑克游戏,提供奢华的赌场体验。玩家可以与三种难度级别(简单、普通、困难)的人工智能对手对战,或与朋友一起游戏。 **主要特点:** * **游戏玩法:** 完整的德州扑克规则,包括边池和完整的手牌评估。响应式设计支持桌面和移动设备。 * **用户体验:** 具有流畅动画和直观投注界面的视觉吸引人的奢华赌场主题。通过Socket.IO进行实时更新,让玩家随时了解情况。 * **技术基础:** 模块化架构、线程安全的游戏引擎、用于玩家持久化的数据库集成以及全面的错误处理。 **开始使用:** 该游戏易于安装,只需克隆项目并使用`pip install -r requirements.txt`安装依赖项即可。配置通过`.env`和`config.py`文件管理。提供用于用户管理和游戏状态访问的API端点。 **部署:** 生产部署使用Dockerfile进行容器化,并推荐PostgreSQL作为数据库。建议使用Gunicorn来提供应用程序服务。详细文档、故障排除和贡献指南均在README中提供。

一位开发者在Hacker News分享了一个基于Python和Flask的实时德州扑克游戏,托管在GitHub上 (github.com/emma019)。该项目使用了AI,可能得到了编码代理的协助。 虽然该项目因其雄心壮志——创建一个带有Web界面的本地扑克服务器——而受到赞扬,但初步用户反馈表明它尚未准备好广泛使用,并指出了UI问题和错误,包括安装问题。开发者正在积极寻求有关遇到的错误的详细信息(操作系统、Python版本、具体错误)以便快速解决。 一位评论者建议利用长上下文AI助手来迭代改进该项目。原作者鼓励用户报告问题以便快速解决。
相关文章

原文
image image

Poker Table Python GitHub stars GitHub forks GitHub issues License

# 🎴 Midnight Luxury Poker

A sophisticated, real-time Texas Hold'em poker game built with Flask-SocketIO backend and modern frontend. Features AI opponents with multiple difficulty levels and a luxurious casino-themed interface.

## ✨ Features

### 🎮 Gameplay
- **Real-time Texas Hold'em** with full poker rules
- **Multiplayer support** - Play with friends or AI opponents
- **Smart AI opponents** with three difficulty levels (Easy, Normal, Hard)
- **Complete hand evaluation** and pot management
- **Side pot handling** for all-in scenarios
- **Responsive design** that works on desktop and mobile

### 🎨 User Experience
- **Luxury casino theme** with midnight black and gold accents
- **Smooth animations** for card dealing, chip movements, and pot distribution
- **Intuitive betting interface** with slider and preset bet buttons
- **Real-time game state updates** with Socket.IO
- **Winner announcements** with hand information

### 🛠 Technical
- **Modular architecture** with separated game logic and UI
- **Thread-safe game engine** with proper locking
- **Database integration** for player persistence
- **Comprehensive error handling** and logging
- **Easy deployment** with production-ready configuration

## 🚀 Quick Start

### Prerequisites
- Python 3.8 or higher
- pip (Python package manager)
- Modern web browser with JavaScript enabled

### Installation

1. **Clone or unpack the project**
   ```bash
   # If using the unpacker
   python unpacker.py poker_project.md
  1. Run the automated setup

    This will:

    • Check your Python environment
    • Install required dependencies
    • Create configuration files
    • Start the development server
  2. Manual setup (alternative)

    # Install dependencies
    pip install -r requirements.txt
    
    # Start the server
    python run.py
  3. Access the game Open your browser and navigate to:

  1. Enter your player name in the lobby
  2. Add AI opponents using the difficulty buttons
  3. Click "Start Game" to begin
  4. The game automatically handles dealing and betting rounds
  1. Blinds: Small and big blinds are posted automatically
  2. Pre-flop: Receive your hole cards and begin betting
  3. Flop: Three community cards are revealed
  4. Turn: Fourth community card revealed
  5. River: Final community card revealed
  6. Showdown: Remaining players reveal hands, best hand wins
  • Fold: Discard your hand and sit out the current round
  • Check: Stay in the game without betting (when no bet to call)
  • Call: Match the current bet amount
  • Raise: Increase the current bet (must meet minimum raise requirements)
  • All-in: Bet all your remaining chips
midnight-luxury-poker/
├── 📁 app/                    # Backend application
│   ├── __init__.py           # Flask app factory
│   ├── extensions.py         # Database and SocketIO initialization
│   └── 📁 poker/             # Poker game logic
│       ├── __init__.py       # Blueprint registration
│       ├── models.py         # Database models (User)
│       ├── game.py          # Core game logic (Game, Player, Deck classes)
│       ├── ai.py            # AI strategies (Easy, Normal, Hard)
│       ├── events.py        # SocketIO event handlers
│       ├── routes.py        # HTTP API endpoints
│       └── exceptions.py    # Custom game exceptions
├── 📁 frontend/              # Frontend assets
│   ├── index.html           # Main HTML file
│   ├── style.css            Luxury casino styling
│   └── script.js            # Client-side game logic
├── 📄 run.py                # Main server entry point
├── 📄 start_server.py       # Automated setup script
├── 📄 config.py             # Application configuration
├── 📄 requirements.txt      # Python dependencies
└── 📄 .env.example          # Environment variables template

Create a .env file from .env.example:

# Application Security
SECRET_KEY=your-super-secret-key-here-change-in-production

# Debug & Development
FLASK_DEBUG=True
FLASK_RUN_HOST=127.0.0.1
FLASK_RUN_PORT=5000

# Database
DATABASE_URL=sqlite:///poker.db

# CORS Settings (production)
# CORS_ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com

Modify config.py to adjust:

  • DEFAULT_CHIPS: Starting chip count (default: 10000)
  • SMALL_BLIND / BIG_BLIND: Blind amounts
  • MAX_PLAYERS_PER_GAME: Maximum players per table

🎮 AI Difficulty Levels

  • Makes random decisions with basic strategy
  • Good for beginners learning the game
  • Occasionally makes questionable plays
  • Uses hand strength evaluation
  • Considers position and pot odds
  • Balanced aggression and caution
  • Advanced hand reading and range analysis
  • Position-aware betting strategies
  • Pot odds and implied odds calculations
  • Capable of bluffing and semi-bluffing
  • join_game: Join a game room
    { "username": "string", "room_id": "string" }
  • start_game: Start a new hand
  • player_action: Submit player action
    { "action": "fold|check|call|bet|raise", "amount": number }
  • game_state_update: Real-time game state
  • game_over: Round completion with winners
  • error: Error notifications
  • POST /api/user: Create new user
  • GET /api/user/<username>: Get user information
  • POST /api/reset_user: Reset user chips
  • GET /api/games: List active games
  • GET /api/game/<room_id>: Get specific game state
  1. Set FLASK_DEBUG=False in .env
  2. Generate a strong SECRET_KEY
  3. Configure production database (PostgreSQL recommended)
  4. Set proper CORS origins
  5. Use gunicorn for production server:
    gunicorn -k eventlet -w 1 run:app
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "run.py"]

Server won't start:

  • Check Python version (requires 3.8+)
  • Verify all dependencies are installed
  • Check port 5000 is available

Connection errors:

  • Ensure server is running
  • Check browser console for WebSocket errors
  • Verify CORS settings if accessing from different domain

Game logic issues:

  • Check server logs for error messages
  • Verify database file permissions
  • Reset game state if needed
  • Server logs: poker_server.log
  • Real-time logs: Browser developer console
  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request
  • Follow PEP 8 for Python code
  • Use meaningful commit messages
  • Add tests for new features
  • Update documentation accordingly

This project is licensed under the MIT License - see the LICENSE file for details.

  • Poker hand evaluation logic inspired by open-source poker libraries
  • UI design inspired by luxury casino aesthetics
  • Socket.IO for real-time communication capabilities
  • Flask community for excellent web framework documentation

Enjoy your game of Midnight Luxury Poker! 🎰♠️♥️♣️♦️

For questions or support, please check the issues section or contribute to the documentation.


This README provides:

1. **Comprehensive overview** of the project and its features
2. **Easy setup instructions** using your automated scripts
3. **Detailed technical documentation** of the architecture
4. **Game rules and AI descriptions** for users
5. **API documentation** for developers
6. **Deployment guides** for production
7. **Troubleshooting section** for common issues

The structure follows best practices for open-source projects and should help both users and developers understand and work with your codebase effectively.
联系我们 contact @ memedata.com