Skip to content
HsGalaxyPublic

About

I reversed the interface of ibizsim.cn and wrote serveral strategy that can win the game.Here I'm presenting code and exps

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

iBizSim AI Player

AI-driven decision engine for iBizSim (企业竞争模拟), a business simulation platform developed by Peking University. This project reverse-engineers the platform's web API and builds automated game-playing bots that compete against the built-in AI.

Results

Difficulty Score Rank Strategy
1 1.000 #1 Undercut prices 2-3%, steady capacity expansion
5 0.906 #1 Survival-first: skip R&D early, focus 2 markets, then expand
9 0.885 #1 Zero R&D to save 300K/period while AI wastes cash

All difficulties beaten against the built-in AI opponent ("test"), achieving #1 ranking across difficulty levels 1, 5, and 9.

Project Structure

ibizsim/
├── ibizsim_api.py          # Reverse-engineered API client (core)
├── test_api.py              # API validation tests
├── API_REFERENCE.md         # Complete API documentation
├── requirements.txt         # Python dependencies
├── examples/
│   ├── play_match.py        # Difficulty 1 bot (score: 1.000)
│   ├── play_diff5.py        # Difficulty 5 bot (score: 0.906)
│   └── play_diff9.py        # Difficulty 9 bot (score: 0.885)
└── logs/
    ├── game_log.txt          # Difficulty 1 game log
    ├── game_log_diff5.txt    # Difficulty 5 game log
    └── game_log_diff9.txt    # Difficulty 9 game log

Quick Start

pip install requests beautifulsoup4

# Run difficulty 1 match
python examples/play_match.py

# Run difficulty 5 match
python examples/play_diff5.py

# Run difficulty 9 match
python examples/play_diff9.py

Reverse-Engineered API

The ibizsim_api.py module provides a complete Python client for the iBizSim platform:

from ibizsim_api import IBizSimAPI, Decision

api = IBizSimAPI()
api.login("phone_number", "password")

# List & create games
games = api.list_machine_games()
game = api.create_machine_game(template_id=3)  # Difficulty 1, Scenario A

# Read game state
welcome = api.get_game_welcome(game.game_id, game.team_id)
decision = api.get_current_decision(game.game_id, game.team_id)

# Get market intelligence
tip = api.get_price_tip(game_id, period_id, team_id, market=1, product=1)
prod = api.get_production_tip(game_id, period_id, team_id, product=1, job=1)

# Submit decisions
decision.price11 = 2050
api.submit_decision(game.game_id, game.team_id, period_id, decision)

# Read reports (lazy-loaded AJAX tabs)
public = api.get_public_report(game.game_id, game.team_id)
private = api.get_private_report(game.game_id, game.team_id)

Full API reference: API_REFERENCE.md

Game Rules Summary

iBizSim simulates quarterly business operations. Players manage a company producing 2-4 products across 2-4 markets, competing against other companies (human or AI).

Key Mechanics

Rule Detail
Products 2 (Diff 1) / 2 (Diff 5) / 4 (Diff 9)
Markets 2 / 3 / 4
Machine cost 40,000/unit, usable 2 periods after purchase
Raw materials Product A: 300/unit, Product B: 1,500/unit
Shipping limit Only 75% of current production can be shipped
Raw material delivery Only 50% of ordered materials available this period
Worker retirement 3% automatic per period
Minimum cash 2,000,000 (below triggers 40% emergency loan = bankruptcy)
Shifts Shift 1 (normal + OT) + Shift 2 (normal + OT)
R&D Required at Difficulty 5+ to upgrade product grade

Scoring (7 indicators)

Indicator Weight
Current profit 0.20
Net worth 0.20
Market share 0.15
Return on capital 0.15
Profit per employee 0.10
Cumulative dividends 0.10
Cumulative tax paid 0.10

The composite score is the LAST period's score, not cumulative. Must be winning at game end.

Strategy Insights

Difficulty 1 (Score: 1.000)

  • Pricing: 2-3% below AI (A=2050 vs 2100, B=4500 vs 4600) captures ~60% market share
  • Expansion: +12 machines/period for P1-3, +8 for P4-7, +4 for P8-11 (machines cost only 40K each)
  • Workers: Maintain 220+, always compensate 3% retirement
  • Raw materials: Buy 2.5x consumption (B needs 1500/unit and only 50% arrives immediately)
  • Dividends: 40K/period from P8+ (cumulative dividends is a scoring factor)
  • Cash safety: Never below 2.5M to avoid emergency loans

Difficulty 5 (Score: 0.906)

  • Phase 1 (P1-6): Zero R&D, skip market 3, focus on markets 1-2 only. Build cash.
  • Phase 2 (P7-12): Enter market 3, start R&D (80K+150K), accelerate growth
  • Phase 3 (P13-20): Full optimization, steady dividends
  • Key insight: R&D costs 300K/period, which bankrupts you if started too early with only 2.5M starting cash

Difficulty 9 (Score: 0.885)

  • Zero R&D throughout: The AI wastes 300K/period on R&D while both companies lose money. By skipping R&D, we save 300K/period and become profitable while AI bleeds cash.
  • Match AI prices exactly: No undercut needed. Both at 50% market share, but we have higher profit.
  • Zero expansion initially: Only start buying machines at P7 when cash exceeds 4M
  • Consistent dividends: 50K/period when cash allows, building cumulative dividend advantage
  • Key insight: When both players lose money, the one who loses less wins. Skip unnecessary costs.

Universal Lessons

  1. Cash is king: Going below 2M triggers 40% emergency loans, creating an unrecoverable death spiral
  2. Don't over-expand: Each machine adds 2K/quarter depreciation forever. Over-buying destroys profitability.
  3. System modifies infeasible decisions randomly: If you can't afford your plan, the system cuts your shipments to zero. Always ensure feasibility.
  4. Read the rules: Machine cost is 40K (not 100K), B raw materials = 1500 (not 600). Wrong assumptions = bankruptcy.
  5. Score = last period: Doesn't matter if you lead for 15 periods - only the final period counts.

Technical Details

Platform

  • Tech stack: Ruby on Rails
  • Auth: Cookie-based session (_session_id) with CSRF token (authenticity_token)
  • Data format: HTML (not JSON API), requires BeautifulSoup parsing
  • Report tabs: Lazy-loaded via AJAX with render=TAB_NAME parameter
  • Decision submission: POST returns 500 but decision is accepted (server rendering bug)

47 Game Scenarios

The platform offers 47 different scenarios across 9 difficulty levels (1-9) with multiple scenario variants (A-P). Each has different market conditions, transport costs, and initial parameters.

License

MIT

Acknowledgments

  • iBizSim platform by Peking University Guanghua School of Management
  • AI decision engine built with assistance from Claude (Anthropic)

About

I reversed the interface of ibizsim.cn and wrote serveral strategy that can win the game.Here I'm presenting code and exps

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages