Inspiration

Fantasy Premier League (FPL) managers spend hours pouring over spreadsheets and stats, trying to calculate whether taking a -4 points hit is worth it or when the optimal time to play a Wildcard is. We realized that human intuition is fundamentally flawed when dealing with millions of combinatorial transfer paths across multiple gameweeks. We were inspired to bring enterprise-level operations research (Linear Programming and Beam Search) and Generative AI into the hands of everyday football fans, democratizing elite-level FPL strategy.

What it does

FPL Optimizer is an elite web application that takes your live Fantasy Premier League team and calculates the absolute mathematical optimum for your squad across future gameweeks.

  • Multi-Horizon Simulation: It projects Expected Points (xP) multiple gameweeks into the future, weighing the Expected Value (EV) of free transfers, point hits, and chip usage (e.g., Wildcard, Bench Boost).
  • Beta Pilot AI Agent: Powered by Google Gemini 2.0, it provides users with personalized, natural language tactical advice based on live injuries, press conferences, and their specific squad constraints.
  • Automated Data Ingestion: An autonomous "Sniper Bot" scrapes the freshest xP data just hours before the FPL deadline to ensure the engine's math is flawless.

How we built it

We built a highly responsive frontend using React, Vite, and Tailwind CSS, featuring a premium, glassmorphic dark-mode aesthetic with smooth framer-motion animations.

The core engine is built in TypeScript. We utilized a Multi-Horizon Beam Search algorithm to explore the massive combinatorial tree of future gameweeks. Whenever the simulator tests a "Wildcard" or "Free Hit" state, it delegates the heavy lifting to a custom Linear Programming (LP) Solver (javascript-lp-solver) to instantly calculate the mathematically perfect 15-man squad within the £100m budget constraint.

For the AI Agent, we integrated the Google Gemini 2.0 Flash API, passing it the live state of the user's team, the xP data, and contextual prompts. Authentication and monetization are handled seamlessly via Firebase and Stripe, allowing us to gate advanced computational tiers (Strategist & Beta Pilot) behind a subscription model. Finally, we set up GitHub Actions to run an automated Playwright headless scraper that acts as an autonomous oracle, continuously keeping our expected points data up to date.

Challenges we ran into

  • Combinatorial Explosion: Calculating every possible transfer across 5+ gameweeks leads to billions of permutations. We had to implement a highly optimized Beam Search to aggressively prune suboptimal branches, ensuring our Vercel serverless functions wouldn't time out.
  • Handling Strict FPL Constraints: Translating FPL's rigid rules (maximum 3 players from one club, exact positional limits of 2 GKP, 5 DEF, 5 MID, 3 FWD, and budget constraints) into strict mathematical equations for the LP Solver was highly complex.
  • Dynamic AI Context: Passing an entire 15-man squad and complex xP tables to an LLM can cause hallucinations. We had to carefully engineer the Gemini system prompt to force the AI to act strictly as a tactical "Beta Pilot," relying only on the injected JSON state rather than its own outdated training data.

Accomplishments that we're proud of

  • The Premium UI/UX: We built a stunning interface with interactive confetti, dynamic pitch visualizations, and lock-state bypasses that make staring at complex math feel like playing a high-end video game.
  • The Seamless Integration of AI and Math: We successfully married rigid mathematical optimization (Linear Programming) with fluid, natural language analysis (Gemini AI), creating a tool that provides both the "what" (the numbers) and the "why" (the context).
  • Fully Autonomous Data Pipeline: Building the GitHub Action "Sniper Bot" means the app maintains its own data integrity without any manual human intervention.

What we learned

We learned a tremendous amount about operations research, specifically how to formulate real-world constraints into linear programming models in JavaScript. We also mastered handling complex state transitions in React, orchestrating secure Stripe checkout sessions via Firebase webhooks, and seamlessly integrating Generative AI to enhance data-heavy applications.

What's next for FPL Optimizer: The Ultimate AI Edge

We plan to introduce Elite Ownership (EO) Risk Penalties, allowing the engine to mathematically weigh the rank risk of not owning highly-owned players. We also want to expand the Gemini AI Agent to automatically fetch and summarize live press conferences directly into the chat, and eventually release a native iOS/Android mobile app for on-the-go gameweek tinkering!

Built With

Share this project:

Updates