# Colour Prediction Game

## Files Included

### Database
- `database_schema.sql` - Complete MySQL/MariaDB schema with all tables

### Game Pages
- `colour_game.php` - Main game page for players (Red/Green betting)
- `prediction_history.php` - Player's bet history & result patterns

### Admin Panel
- `admin_panel.php` - Admin control panel with:
  - Real-time Red/Green betting amounts
  - Manual result control (Red/Green buttons)
  - Result history table
  - Game settings (timer, multiplier, min/max bet)
  - Admin activity logs

### API Files
- `api/game_api.php` - Main game API (place bets, get session, history)
- `api/get_balance.php` - Balance fetch API
- `api/auto_result.php` - Cron script for auto results

### Config
- `config.php` - Database connection & helper functions

## Features

1. **Timer-based rounds** - Configurable countdown timer
2. **Red & Green buttons** - Two colour betting options
3. **No number prediction** - Only colour based
4. **2x winning amount** - Double your bet on win
5. **Logic: Jidhar zyada amount, woh LOSE** - House edge logic
6. **Auto & Manual result modes** - Admin can control or auto-generate
7. **Result history strip** - Shows last 15 results
8. **Admin panel** - Full control with betting stats display

## Setup Instructions

1. Import `database_schema.sql` into your MySQL database
2. Update `config.php` with your database credentials
3. Set up cron job for auto results:
   ```
   * * * * * /usr/bin/php /path/to/api/auto_result.php
   ```
4. Access game via: `colour_game.php?token=YOUR_JWT_TOKEN`
5. Access admin via: `admin_panel.php` (login as admin first)

## Admin Login
- Username: `admin`
- Password: `admin123` (change in production!)

## Game Flow

1. Admin creates a round (or auto-created)
2. Timer starts counting down
3. Players place bets on Red or Green
4. Timer ends -> betting locks
5. Admin sets result (manual) OR auto-result generated
6. Winners get 2x payout, losers lose bet
7. Next round starts automatically
