Skip to content

dakariuishmg/Ai_Web_Gamer_Companion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Ai_Web_Gamer_Companion

A fully local AI-powered gaming hub featuring Noughts & Crosses and Connect Four with opponents running entirely in-browser via Local AI.

uish-games-hub

A fully local AI-powered gaming hub featuring Noughts & Crosses (Tic-Tac-Toe) and Connect Four with LLM opponents running entirely in-browser via Transformers.js. Experience intelligent gameplay without any server communication - all AI inference happens directly in your browser using WebGPU acceleration.

Features

  • 100% Local AI: All model inference runs in your browser using Transformers.js and ONNX Runtime
  • Two Classic Games: Play Noughts & Crosses and Connect Four against AI opponents
  • WebGPU Acceleration: Hardware-accelerated inference for fast response times
  • Privacy-First: No data leaves your device - completely offline capable
  • Intelligent Opponents: LLM-powered AI makes strategic decisions
  • Modern UI: Clean, responsive interface built with vanilla JavaScript and CSS3
  • Progressive Enhancement: Graceful fallback for browsers without WebGPU support

Installation

Option 1: Direct Download

  1. Clone this repository:
git clone https://github.com/yourusername/uish-games-hub.git
cd uish-games-hub
  1. Open index.html in a modern web browser that supports WebGPU (Chrome 113+, Edge 113+, or compatible browsers)

Option 2: Local Server

For best results, serve the files via a local HTTP server:

# Using Python 3
python -m http.server 8000

# Using Node.js (with npx)
npx serve .

# Using PHP
php -S localhost:8000

Then navigate to http://localhost:8000 in your browser.

Usage

First Launch

On first load, the application will:

  1. Check for WebGPU support in your browser
  2. Download the AI model from Hugging Face (approximately 50-100MB, cached for future use)
  3. Initialize the ONNX Runtime with WebGPU acceleration

This may take 30-60 seconds on first launch. Subsequent loads will be much faster.

Playing Games

Noughts & Crosses (Tic-Tac-Toe)

  1. Select "Noughts & Crosses" from the main menu
  2. Choose whether to play as X or O
  3. Click on any empty cell to make your move
  4. The AI will respond with its move
  5. First to get three in a row wins!

Connect Four

  1. Select "Connect Four" from the main menu
  2. Choose your color (red or yellow)
  3. Click on any column to drop your piece
  4. The AI will respond with its move
  5. First to get four in a row (horizontal, vertical, or diagonal) wins!

Settings

  • Difficulty Level: Adjust AI thinking depth (Easy, Medium, Hard)
  • First Move: Choose who goes first (Player or AI)
  • Theme: Toggle between light and dark modes

Requirements

Browser Compatibility

Minimum Requirements:

  • Chrome/Edge 113+ (recommended for WebGPU support)
  • Firefox 117+ (with WebGPU enabled in about:config)
  • Safari 17.4+ (limited WebGPU support)

Hardware Requirements:

  • 4GB RAM minimum (8GB recommended)
  • Modern GPU with WebGPU support
  • 200MB free disk space for model caching

Note: If WebGPU is not available, the application will fall back to WASM inference, which will be slower but functional.

Enabling WebGPU

Chrome/Edge: WebGPU is enabled by default in version 113+

Firefox:

  1. Navigate to about:config
  2. Search for dom.webgpu.enabled
  3. Set to true

Safari: WebGPU support is experimental. Enable in Developer settings.

Technical Details

Architecture

  • Frontend: Vanilla JavaScript (ES6+), CSS3 with CSS Grid and Flexbox
  • AI Inference: Transformers.js v3 with ONNX Runtime Web
  • Model: Quantized LLM optimized for game strategy (loaded from Hugging Face)
  • Acceleration: WebGPU for GPU-accelerated inference, WASM fallback
  • State Management: Local browser storage for game history and settings

Performance

  • Initial model load: 30-60 seconds (one-time, cached)
  • AI move generation: 0.5-3 seconds (depending on difficulty)
  • Memory usage: ~200-400MB during gameplay

Privacy & Security

  • Zero Server Communication: All AI processing happens locally
  • No Telemetry: No analytics or tracking
  • Offline Capable: Works without internet after initial model download
  • Local Storage Only: Game data stored in browser localStorage

Project Structure

uish-games-hub/
│
├── index.html              # Main entry point
├── css/
│   ├── styles.css         # Global styles
│   ├── games.css          # Game-specific styles
│   └── themes.css         # Light/dark themes
│
├── js/
│   ├── main.js            # Application initialization
│   ├── ai-engine.js       # Transformers.js integration
│   ├── games/
│   │   ├── noughts-crosses.js
│   │   └── connect-four.js
│   └── utils/
│       ├── storage.js     # LocalStorage management
│       └── webgpu-check.js
│
├── assets/
│   ├── icons/
│   └── images/
│
└── README.md

Browser Compatibility Matrix

Browser Version WebGPU WASM Status
Chrome 113+ Full support
Edge 113+ Full support
Firefox 117+ ⚠️ Requires manual enable
Safari 17.4+ ⚠️ Experimental
Opera 99+ Full support

Troubleshooting

Model fails to load

  • Check internet connection (required for first download)
  • Ensure sufficient disk space (200MB minimum)
  • Clear browser cache and reload

Slow performance

  • Verify WebGPU is enabled in your browser
  • Close other resource-intensive tabs
  • Try reducing AI difficulty level
  • Consider upgrading to a browser with better WebGPU support

Game doesn't respond

  • Check browser console for errors (F12)
  • Ensure JavaScript is enabled
  • Try refreshing the page

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

MIT License

Copyright (c) 2024 uish-games-hub

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Acknowledgments

Links


Note: This project requires a modern browser with WebGPU support for optimal performance. The AI models are downloaded from Hugging Face on first use and cached locally.

About

A fully local AI-powered gaming hub featuring Noughts & Crosses and Connect Four with opponents running entirely in-browser via Local AI all tucked within a single file html and web browser..

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages