npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@civ-clone/core-strategy

v0.1.1

Published

A framework for building modular AI. The idea being that `Strategy`s can handle one of many `PlayerAction`s and it should be easy enough to register new `Strategy`s to handle newly added `PlayerAction`s or specific custom `Unit`s and their actions (`Carav

Downloads

1

Readme

core-strategy

A framework for building modular AI. The idea being that Strategys can handle one of many PlayerActions and it should be easy enough to register new Strategys to handle newly added PlayerActions or specific custom Units and their actions (Caravan, Diplomat, etc).

The consumer AIClient, StrategyAIClient, is available at civ-clone/core-strategy-ai-client.

Another aim for this set of classes is to be able to automate simple tasks (explore, improve terrain, go-to, etc.).

Lastly, there's the possibility for primitive Barbarian behaviour, without having a "ghost" player (like Civ1).

Current state

This is purely illustrative and might change quite substantially until I've got a reasonable working implementation.

import Strategy from '@civ-clone/core-strategy/Strategy';

// Export your base `Strategy`:
export class MyStrategy extends Strategy {
  // Inject dependencies (e.g. `Registry`s) into the `constructor` as usual

  attempt(action: PlayerAction<SpecificItemClass>): boolean {
    // Check if your `Routine` can handle this type of action first, fail early as lots of routines will be even
    // more expensive to check otherwise.
    if (!(action instanceof MyHandleableAction)) {
      return false;
    }

    // In here you can use any existing code, for example you could trigger existing `Action`s for `Unit`s...

    // If you need to share data across many `Strategy`s or `Routine`s you can use the `StrategyNoteRegistry` (with
    // an optional custom `generateKey` method to ensure you always use the expected key).
    const existingNote = strategyNoteRegistryInstance.getByKey(
      myCustomKeyGenerator(action.value())
    );

    if (!existingNote) {
      return false;
    }

    const data = existingNote.value(),
      newAction = new DoSomething(data.x(), data.y(), data.thing());

    newAction.perform(action);

    // When you have handled the action, ensure you return `true` to prevent any more actions from triggering.
    return true;
  }
}

// The core `generateKey` method exists in `StrategyNote`, but having a more specific function associated to your
// `Strategy` can help ensure you are passing the expected entities and get consistent keys.
import { generateKey } from '@civ-clone/core-strategy/StrategyNote';

export const myCustomKeyGenerator = (item: SpecificItemClass) =>
  generateKey(item, MyStrategy.name);

// To control the priority of your `Routine`s you need to use `Priority` `Rule`s and you can even take the `Leader`s
// `Trait`s into consideration if you wish:
import { High, Normal } from '@civ-clone/core-rule/Priorities';
import {
  TraitRegistry,
  instance as traitRegistryInstance,
} from '@civ-clone/core-civilization/TraitRegistry';
import Expansionist from '@civ-clone/base-leader-trait-development/Development/Expansionist';
import Player from '@civ-clone/core-player/Player';
import Priority from '@civ-clone/core-strategy/Rules/Priority';
import Routine from '@civ-clone/core-strategy/Strategy';
import Trait from '@civ-clone/core-civilization/Trait';

export const getRules = (
  traitRegistry: TraitRegistry = traitRegistryInstance
): Priority[] => [
  new Priority(
    new Criterion(
      (player: Player, strategy: Strategy) => routine instanceof MyRoutine
    ),
    new Effect((player: Player) => {
      const civilization = player.civilization(),
        leader = civilization.leader();

      if (
        leader &&
        traitRegistry.some(
          (trait: Trait) =>
            leader instanceof trait.leader() && trait instanceof Expansionist
        )
      ) {
        // Could be any arbitrary `Priority` (from `core-rule`) to give more fine-grained control.
        return new High();
      }

      return new Normal();
    })
  ),
];

// In the main entrypoint make sure you register the `Rule`s and the `Strategy`:
import { instance as ruleRegistryInstance } from '@civ-clone/core-rule/RuleRegistry';
import { instance as strategyRegistryInstance } from '@civ-clone/core-strategy/StrategyRegistry';

ruleRegistryInstance.register(...getRules());
strategyRegistryInstance.register(new MyStrategy());

// `StrategyNote`s can be written from anywhere, for example when first making contact with another `Player` or when a
// `Tile` is discovered, which can then be acted upon.