A large scale simulation which pits millions of space ships against each other in a virtual universe all running directly in SingleStore.

Overview

Wasm Space Program

In this demo we simulate a fake universe full of thousands of solar systems. In each solar system there are many space ships and energy nodes. Each space ship is controlled by an AI written in Rust and deployed into SingleStore as a user defined function (UDF) using our new Code Engine (Powered by Wasm). The AI is able to observe a 16x16 region of cells around it in order to decide what to do. We execute one turn every second which involves running a series of update queries against SingleStore. These update queries implement asking every AI for their next action and then resolving all actions.

The key technologies used are:

  • every solar system is sharded to a specific partition which allows this demo to horizontally scale
  • wasm is used to embed complex agent behavior into the engine and run it in parallel over all of the entities
  • the game client is written in javascript and runs in the browser - so we use the data api to run queries directly against singlestore to gather and display game state
  • the demo is designed to work perfectly with multiple workspaces in order to support many game clients all observing the simulation concurrently

Turn Resolution

turn resolution

  1. All ships can see entities up to 8 cells away.
  2. Each ship decides what to do from the following options:
    • Hold (energy: 1): The ship stays where it is.
    • Move (energy: 2): The ship moves up to its speed in a cardinal direction.
    • Upgrade (energy: 50): The ship upgrades its Blasters, Harvesters, or Thrusters.
  3. All actions are resolved at the same time in a single database transaction and the game rules are applied.

Detailed rules

  • Ships at the same location will fight. Damage is calculated based on the number of blasters each ship has.
  • Ships alone in a call with energy nodes will consume some amount of energy based on the number of harvesters the ship has.
  • A ship may only move up to N cells per turn where N is the number of thrusters the ship has.
  • Each ship has a shield which recharges 1% per turn if the ship is not in combat.
  • Any ship which looses all of its shield explodes, leaving behind all of its energy at the ships location.
  • Any ship which runs out of energy explodes leaving nothing behind.

Architecture

This game runs entirely within SingleStore and the browser. SingleStore, a scale out relational database optimized for transactions and analytics, stores the game state and handles turn resolution. The game client runs in the browser and communicates directly with SingleStore over our Data API.

architecture

Running the demo locally

  1. spin up SingleStore on the managed service
  2. copy backend/config.example.toml to backend/config.toml and update
    • database.host/database.port should point at a mysql protocol endpoint
    • web.endpoints should be an array of urls to the data api port of your SingleStore cluster - the web frontend will load balance over these endpoints (i.e. you can provide readonly workspace endpoints here)
  3. compile the agent:
    cd agent
    cargo wasi build --release
  4. run schema.sql on your singlestore cluster
  5. run the backend:
    cd backend
    go build -o backend
    ./backend --config config.toml
  6. run the frontend
    cd web
    yarn
    yarn dev
  7. open your browser to http://localhost:3000
  8. generate some solar systems
    -- run this once
    insert into solar_system (x, y) values (floor(rand(now()) * 500), floor(rand(now() + 1) * 500));
    
    -- then run this a couple times, each time will double the number of solar systems. I don't recommend running more than 1000 solar systems on a single machine.
    insert into solar_system (x, y) select floor(rand(now() + sid) * 500) x, floor(rand(now() + sid + 1) * 500) y from solar_system;

Have fun!

You might also like...

This plugin allows side-by-side notetaking with videos. Annotate your notes with timestamps to directly control the video and remember where each note comes from.

Obsidian Timestamp Notes Use Case Hello Obsidian users! Like all of you, I love using Obsidian for taking notes. My usual workflow is a video in my br

Jan 2, 2023

aka Scaletor, take screenshots of a piece of a map and scale/compare with other parts of the map

scale-a-tron A quick-and-dirty map that lets you compare one area to another. Draw a shape around a region, zoom in to another place on the map, and c

Nov 7, 2022

The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

The full power of the Go Compiler directly in your browser, including a virtual file system implementation. Deployable as a static website.

Static Go Playground Features Full Go Compiler running on the browser. Supports using custom build tags. Incremental builds (build cache). Supports mu

Jun 16, 2022

Space Travelers' Hub - a web application that facilitates booking rockets and join selected space missions

Space Travelers' Hub - a web application that facilitates booking rockets and join selected space missions

This is a web application that facilitates booking rockets and join selected space missions. It is built for a company that offers both commercial and scientific space travel services. The application also works with real live data from the SpaceX API.

Mar 29, 2022

"Space-Travelers-Hub" is a website that allows users to book rockets and join selected space missions by using data from the SpaceX API.

Space-Travelers-Hub This project was bootstrapped with Create React App. Description "Space-Travelers-Hub" is a website that allows users to book rock

Mar 13, 2022

A web application for a company that provides commercial and scientific space travel services. The application will allow users to book rockets and join selected space missions.

A web application for a company that provides commercial and scientific space travel services. The application will allow users to book rockets and join selected space missions.

Space Travelers A web application for a company that provides commercial and scientific space travel services. The application will allow users to boo

Apr 6, 2022

Welcome to Space Traveler's HUB, this web app allows the user to take a fictional tour across the space.

Welcome to Space Traveler's HUB, this web app allows the user to take a fictional tour across the space.

Welcome to Space Traveler's HUB, this web app allows the user to take a fictional tour across the space. The user can choose a rocket from our catalog interface, and reserve it. Also, the user can see recent special missions and join them. Finally, the user will be able to keep track of all your rockets and mission they are subscribed to. Build with React, Redux, React-router, and Railwindcss.

Jan 27, 2022

This web application provides commercial and scientific space travel services. The application allows users to book rockets and join selected space missions.

This web application provides commercial and scientific space travel services. The application allows users to book rockets and join selected space missions.

space-hub About Project "Space Traveler's Hub" is A web application that provides commercial and scientific space travelling services, We are working

Nov 2, 2022

This a web application for a company that provides commercial and scientific space travel services. The application will allow users to book rockets, dragons and join selected space missions.

Space Travelers' Hub In this project, we have worked with the real live data from the SpaceX API. Our task was to build a web application for a compan

Oct 31, 2022
Comments
  • Bump vite from 2.9.12 to 2.9.13 in /web

    Bump vite from 2.9.12 to 2.9.13 in /web

    Bumps vite from 2.9.12 to 2.9.13.

    Changelog

    Sourced from vite's changelog.

    2.9.13 (2022-06-27)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Make ships aware of whether the ships they can see are of the same strategy

    Make ships aware of whether the ships they can see are of the same strategy

    Add a flag to the per-seen-ship input that tells you whether that ship is of the same type. This would enable strategies ranging from a basic "fight everyone else, don't fight ourselves" to more sophisticated pack hunter type behavior.

    opened by Kylebrown9 0
  • Add wormholes between solar systems to allow agents to spread across the universe

    Add wormholes between solar systems to allow agents to spread across the universe

    Main issue to consider is what happens when one solar system gets too large which could slow things down. We probably need a population cap on each solar system to ensure this doesn't happen.

    rough notes

    to generate neighbors, use veroni and connect solar systems on either side of every edge

    for connections, consider a new wormholes table to track sid -> sid then pack all the edges in the current system (similar to neighbors) and pass it into the step function as another input

    alternatively, add a new entity kind and just add the edges directly to the entities table this is the easiest solution, but requires improving cleanup routines/development workflow to not delete the wormholes

    then the universe map needs to know about the wormholes in order to render edges bewtween each system

    opened by carlsverre 0
Owner
SingleStore Labs
The home of SingleStore community content
SingleStore Labs
A Kubernetes monitoring tool to visualize large-scale activity and real-time comprehensive metrics within your cluster.

Armada A light-weight Kubernetes health monitoring tool. Summary Armada is an open-source tool for monitoring the health of your Kubernetes cluster. I

OSLabs Beta 81 Nov 2, 2022
T3 is a client-side JavaScript framework for building large-scale web applications

Box has migrated using react, webpack, and the latest version of ECMAScript for our frontend projects as of 2018. We no longer support chan

Box 1.6k Dec 8, 2022
🗃️ An in-memory JS database optimized for large scale storage on the frontend.

BlinkDB is a in-memory JS database optimized for large scale storage on the frontend. import { many } from 'blinkdb'; const items = await many(userTa

BlinkDB 64 Dec 23, 2022
A Gun DB extension that ships secure* ephemeral messaging between Gun peers using Bugout, secured by Gun's SEA suite

Bugoff A Gun DB extension that ships secure* ephemeral messaging between Gun peers using Bugout, secured by Gun's SEA suite About Bugoff creates an SE

Daniel Raeder 14 Nov 12, 2022
This is a tic-tac-toe game but differs from most others as it carries the option of playing against an AI (COM) or against a friend.

TIC-TAC-TOE This is a simple tic-tac-toe game with the exception of playing against an algorithm or against a friend. At the very start, you have to s

Paul Ibeabuchi C. 4 Jul 2, 2022
This is a simple web application of a To-do List in which you can add, remove and edit all your tasks and also you can mark each task as completed and delete all completed ones.

To-Do List A simple web application of a to do list Built With HTML, CSS, JS, ES6 & Webpack Getting Started In this repository I created To-Do List SP

Juan Sebastian Sotomayor 12 Apr 11, 2022
A blog to the far universe

Antarishk Brief Info: The Antarishk (a Hindi word, which mean the space) is a website which is made to fetch some cool facts about the Space and Unive

MAINAK CHAUDHURI 25 Dec 17, 2022
This is the backend of Wherechat, which is a chat application that allows users to find and meet each other through their location on the map.

wherechat-backend About the project This is the backend of Wherechat, which is a chat application that allows users to find and meet each other throug

Isaac Ndala 5 Nov 23, 2022