Giter VIP home page Giter VIP logo

pyrisk's Introduction

pyrisk

Intro

A simple implementation of a variant of the Risk board game for python, designed for playing with AIs.

Runs in python (2.7 or 3.x) using the curses library to display the map (but can be run in pure-console mode).

Usage

python pyrisk.py FooAI BarAI*2

Use --help to see more detailed options, such as multi-game running. The AI loader assumes that SomeAI translates to a class SomeAI inheriting from AI in ai/some.py.

Rules

A minimal version of the Risk rules are used:

  • Players start with 35 - 5*players armies.
  • At the start of the game, territories are chosen one by one until all are claimed, and then the remaining armies may be deployed one at a time to reinforce claimed territories.
  • Each turn, players recieve 3 + territories/3 reinforcements, plus a bonus for any complete continents.
  • A player may make unlimited attacks per round into adjacent territories (including from freshly-conquered territories).
    • Each combat round, the attacker can attack with up to three armies.
    • Upon victory, a minimum of that combat round's attackers are moved into the target territory.
    • The attacker may cease the attack at the end of any combat round.
    • The defender defends with two armies (unless only one is available).
    • Each attacking and defending army rolls 1d6. The rolls on each side are ordered and compared. The loser of each complete pair is removed, with the defender winning ties.
  • At the end of each turn, a player may make one free move
  • Victory is achieved by world domination.

API

Write a new class extending the AI class in ai/__init__.py. The methods are documented in that file. At a minimum, the following functions need to be implemented:

  • initial_placement(self, empty, remaining): Return an empty territory if any are still listed in empty, else an existing territory to reinforce.
  • reinforce(self, available): Return a dictionary of territory -> count for the reinforcement step.
  • attack(self): Yield (from, to, attack_strategy, move_strategy) tuples for each attack you want to make.

The AI base class provides objects game, player and world which can be inspected for the current game state. These are unproxied versions of the main game data structures, so you're trusted not to modify them.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.