How mcalus3/color-wars-web works
Purpose and runtime
ColorWars is a browser-based, local hot-seat territory game for up to eight players. It is a TypeScript React application using Redux for Model-View-Update-style state management, Konva-backed game rendering, and react-bootstrap controls. Static hosting is implied by the browser entry document at public/index.html.
Application entry and composition
src/index.tsx mounts the React application and loads global styling from src/index.css; src/ColorWars/Game.tsx is the game-level composition root. It assembles the board, player/status displays, controls, settings, and input surfaces. src/registerServiceWorker.ts provides the optional client-side service-worker integration boundary.
Central game state and dispatch boundary
Redux is the authoritative game model. Action names and shared constants originate in src/ColorWars/ReduxStore/actionTypes.ts and src/ColorWars/ReduxStore/constants.ts; the root state transition layer is src/ColorWars/ReduxStore/reducers/GameReducer.ts. UI components do not need to own simulation state: container adapters in src/ColorWars/ReduxStore/containers/Game.ts and src/ColorWars/ReduxStore/containers/GameBoard.ts connect rendered views to state and dispatch.
Simulation lifecycle
Game setup creates or changes the world, player count, board dimensions, and map configuration through reducer-stage modules such as src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts, src/ColorWars/ReduxStore/reducers/GameLogic/SetPlayersAmount.ts, and src/ColorWars/ReduxStore/reducers/GameLogic/ResizeBoard.ts. Runtime advancement is centered on src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts, which advances the match timer and player/game evolution per update cycle.
Rules, movement, and territory
Player movement is controlled through keyboard/input direction changes in src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts and src/ColorWars/ReduxStore/reducers/GameLogic/changeDirection.ts. Territory capture and tail-cutting outcomes are encapsulated by src/ColorWars/ReduxStore/reducers/GameLogic/claimingAlgorithm.ts; player creation and mutations are handled by src/ColorWars/ReduxStore/reducers/GameLogic/addPlayer.ts and src/ColorWars/ReduxStore/reducers/GameLogic/modifyPlayer.ts. This reducer layer is the key boundary for gameplay-rule changes.
Rendering and interaction
The visual board is represented by src/ColorWars/ReactView/components/GameBoard.tsx, with field-level rendering in src/ColorWars/ReactView/components/Fields.tsx and player trails in src/ColorWars/ReactView/components/Tails.tsx. HUD/state projections include src/ColorWars/ReactView/components/ScoreBoard.tsx, src/ColorWars/ReactView/components/GameElements/Timer.tsx, and src/ColorWars/ReactView/components/GameElements/KillsLabel.tsx. Touch input is isolated in src/ColorWars/ReactView/components/TouchScreen.tsx.
Configuration and AI
In-match settings are exposed through src/ColorWars/ReactView/components/SettingsComponent.tsx and player-specific controls under src/ColorWars/ReactView/components/Settings/PlayerSettings.tsx; corresponding state changes pass through Redux containers. AI-controlled players are managed separately from rendering by src/ColorWars/AI/AIManager.ts, src/ColorWars/AI/UpdateAi.ts, and src/ColorWars/AI/AiFunctions.ts, which should produce the same movement/state actions used for human players.
Data model and deployment boundary
Shared game object types and initial state live in src/ColorWars/utils/objectTypes.ts and src/ColorWars/utils/initialState.ts, defining the model consumed by reducers, AI, and views. There is no backend or external game service evident: matches run entirely in the browser, with public assets under public/.
Main entry points: GameReducer.ts Game reducer · Game.tsx Game composition · index.tsx React entry · GameBoard.ts Board container
Components 19
Browser bootstrap
- Browser document
public/index.html - React entry
src/index.tsx - Service worker bridge
src/registerServiceWorker.ts
React UI
- Game composition
src/ColorWars/Game.tsx - Game container
src/ColorWars/ReduxStore/containers/Game.ts - Board container
src/ColorWars/ReduxStore/containers/GameBoard.ts - Konva board · Renders fields and player trails.
src/ColorWars/ReactView/components/GameBoard.tsx - Fields and tails
src/ColorWars/ReactView/components/Fields.tsx - Score and status HUD
src/ColorWars/ReactView/components/ScoreBoard.tsx - Settings and player controls
src/ColorWars/ReactView/components/SettingsComponent.tsx - Touch input
src/ColorWars/ReactView/components/TouchScreen.tsx
Redux game engine
- Game reducer · Authoritative game model and dispatch boundary.
src/ColorWars/ReduxStore/reducers/GameReducer.ts - Actions and constants
src/ColorWars/ReduxStore/actionTypes.ts - World setup · Creates worlds and changes players, board size, and map configuration.
src/ColorWars/ReduxStore/reducers/GameLogic/CreateWorld.ts - Match tick · Advances timer and match evolution.
src/ColorWars/ReduxStore/reducers/GameLogic/Tick.ts - Movement and territory rules · Handles direction, captures, tail cuts, and player mutations.
src/ColorWars/ReduxStore/reducers/GameLogic/HandleKeyboardInput.ts - Game types and initial state
src/ColorWars/utils/objectTypes.ts
AI control
- AI manager · Produces the same movement actions as human players.
src/ColorWars/AI/AIManager.ts - AI update and decisions
src/ColorWars/AI/UpdateAi.ts
Connections 23
- Browser document → React entry: loads
- React entry → Game composition: mounts
- React entry → Service worker bridge: optionally registers
- Game composition → Game container: composes
- Game composition → Board container: composes
- Game composition → Score and status HUD: composes
- Game composition → Settings and player controls: composes
- Game composition → Touch input: composes
- Game container → Game reducer: reads and dispatches
- Board container → Game reducer: reads and dispatches
- Board container → Konva board: supplies state
- Konva board → Fields and tails: renders
- Score and status HUD → Game reducer: projects state
- Settings and player controls → Game reducer: dispatches changes
- Touch input → Game reducer: dispatches direction
- Actions and constants → Game reducer: defines action protocol
- Game reducer → World setup: delegates setup
- Game reducer → Match tick: delegates updates
- Game reducer → Movement and territory rules: delegates rules
- Game reducer → Game types and initial state: uses state model
- AI manager → AI update and decisions: runs
- AI update and decisions → Game reducer: dispatches movement actions
- AI update and decisions → Game types and initial state: reads game state