Giter Site home page Giter Site logo

nchess's Introduction

n-dimensional chess

4d board

This is a work-in-progress implementation of a n-dimensional Chess framework.

Rules

Bishop

For an n-d game, the Bishop could move to the vertices of an integer i-cube (2 <= i <= n) in n-d space centered in the current position of the Bishop. This is equivalent to say the Bishop can move through its diagonals.

For example, in a 3-d game, the Bishop could move according to (k * _ for _ in BishopOffsets[i]), with k being an integer from 1 to board.size - 1.

BishopOffsets = [
    # 2-cube vertices in 3-d space
    (1, 1, 0),
    (1, -1, 0),
    (-1, 1, 0),
    (-1, -1, 0),

    # 3-cube vertices in 3-d space
    (1, 1, 1),
    (1, 1, -1),
    (1, -1, 1),
    (1, -1, -1),
    (-1, 1, 1),
    (-1, 1, -1),
    (-1, -1, 1),
    (-1, -1, -1)
]

King

For an n-d game, the King could move to the vertices of an unit i-cube (2 <= i <= n) in n-d space centered in the current position of the King, and it nearest cardinal positions. This is equivalent to say the King can move 1 spot through every direction.

For example, in a 3-d game, the King can move according to KingOffsets[i].

KingOffsets = [
    # 2-cube vertices in 3-d space
    (1, 1, 0),
    (1, -1, 0),
    (-1, 1, 0),
    (-1, -1, 0),

    # 3-cube vertices in 3-d space
    (1, 1, 1),
    (1, 1, -1),
    (1, -1, 1),
    (1, -1, -1),
    (-1, 1, 1),
    (-1, 1, -1),
    (-1, -1, 1),
    (-1, -1, -1),

    # cardinals in 3-d space
    (1, 0, 0),
    (-1, 0, 0),
    (0, 1, 0),
    (0, -1, 0),
    (0, 0, 1),
    (0, 0, -1)
]

Knight

For an n-d game, the Knight could move 2 spots in a direction and 1 spot in a different direction.

For example, in a 3-d game, the Knight could move according to KnightOffsets[i].

from itertools import product

KnightOffsets = []
for i in range(3): # 3-d space
    for j in range(3): # 3-d space
        if i == j: continue
        for p, q in product((-1, 1), repeat=2):
            offset = [0] * 3 # 3-d space
            offset[i] = 2 * p
            offset[j] = 1 * q
            KnightOffsets.append(tuple(offset))

Pawn

For an n-d game, the Pawn could move forward 1 spot in the dimensions greater than 1. To capture, the Pawn can move one spot in the first dimension (any direction) and forward 1 spot in dimensions greater than 1.

For example, in a 3-d game, the Pawn could move according to PawnOffsets[i], or PawnCaptureOffsets[i] if available.

PawnOffsets = [
    # "Forward 1 spot in the dimensions grater than 1" (unit vectors for dimensions grater than 1)
    # (1, 0, 0),
    (0, 1, 0),
    (0, 0, 1)
]

PawnCaptureOffsets = [
    # "One spot in the first dimension (any direction) and forward 1 spot in the dimensions greater than 1"
    (1, 1, 0),
    (-1, 1, 0),
    (1, 0, 1),
    (-1, 0, 1)
]

Queen

For an n-d game, the Queen could move to the vertices of an integer i-cube (2 <= i <= n) in n-d space centered in the current position of the Queen, and to an integer scaled cardinal position. This is equivalent to say the Queen can move through every direction.

For example, in a 3-d game, the Queen could move according to (k * _ for _ in QueenOffsets[i]), with k being an integer from 1 to board.size - 1.

QueenOffsets = [
    # 2-cube vertices in 3-d space
    (1, 1, 0),
    (1, -1, 0),
    (-1, 1, 0),
    (-1, -1, 0),

    # 3-cube vertices in 3-d space
    (1, 1, 1),
    (1, 1, -1),
    (1, -1, 1),
    (1, -1, -1),
    (-1, 1, 1),
    (-1, 1, -1),
    (-1, -1, 1),
    (-1, -1, -1),

    # cardinals in 3-d space
    (1, 0, 0),
    (-1, 0, 0),
    (0, 1, 0),
    (0, -1, 0),
    (0, 0, 1),
    (0, 0, -1)
]

Rook

For an n-d game, the Rook could move through an integer scaled cardinal position.

For example, in a 3-d game, the Rook could move according to (k * _ for _ in RookOffsets), with k being an integer from 1 to board.size - 1

RookOffsets = [
    (1, 0, 0),
    (-1, 0, 0),
    (0, 1, 0),
    (0, -1, 0),
    (0, 0, 1),
    (0, 0, -1),
]

To do

  • Pawn en passant.
  • Castling.
  • Add event listeners.

nchess's People

Contributors

000alen avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

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.