GithubHelp home page GithubHelp logo

wandererxii / shogiops Goto Github PK

View Code? Open in Web Editor NEW
8.0 0.0 3.0 3.23 MB

Shogi rules and operations in TypeScript

License: GNU General Public License v3.0

TypeScript 100.00%
shogi shogi-game typescript sfen kif csa minishogi chushogi

shogiops's Introduction

shogiops

Test npm

Shogi and operations in TypeScript forked from chessops, rewritten for shogi.

Features

  • Read and write SFEN
  • Vocabulary (Square, SquareSet, Color, Role, Piece, Board, Position)
  • Shogi
    • Move/drop making
    • Legal move and drop move generation
    • Game end and outcome
    • Setup validation
  • Attacks and rays using hyperbola quintessence
  • Read and write USI, Japanese, Western and Kitao-Kawasaki notation
  • Read and write KIF and CSA notation
  • Currently supported variants - shogi, minishogi, chushogi, annan shogi and kyoto shogi.
  • Compatibility with shogiground
  • Compatibility with lishogi

File an issue to request more or report a bug.

Example

Test directory has a lot of examples and use-cases.

import { Shogi } from 'shogiops/shogi';
import { parseUsi } from 'shogiops/util';

const pos = Shogi.default();
const usi = parseUsi('7g7f')!;
pos.play(usi);

License

shogiops is licensed under the GNU General Public License 3 or any later version at your choice. See LICENSE.txt for details.

shogiops's People

Contributors

fnogatz avatar grantjenk avatar maconard avatar niklasf avatar wandererxii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shogiops's Issues

pos.clone() is not defined

I'm attempting to make a Discord bot which displays a player's recent games, with a human-readable move list. But I see in shogi.js that clone() is defined, so I must be making a coding error somehow:
image

https://github.com/ddugovic/lishogi-discord/blob/2ca5f2519bb535f78fdad6e39bf1b2a587540e48/lib/format-variation.js#L1-L34

export function parseCsaMoves(pos: Position, csaMoves: string[]): Move[] {
pos = pos.clone();
const moves: Move[] = [];
for (const m of csaMoves) {
const move = parseCsaMove(pos, m);
if (!move) return moves;
pos.play(move);
moves.push(move);
}
return moves;
}

SquareSet.first is bugged

Testing code

var shogi = require('shogiops').Shogi.fromSetup(require('shogiops/fen').parseFen('9/5n1+R+B/5pk2/9/9/9/9/9/9 w rb4g4s3n4l17p 2').unwrap(), false).unwrap();
var dests = shogi.allDests();
console.log(dests);

// array of possible squares the king can move to, should print [ 50 ]
console.log(Array.from(dests.get(60)))

// should print 50 but prints 26 instead for some reason
console.log(dests.get(60).first())

I worked around the bug in ui/learn by using Array.from(dests.get(60))[0] instead of .first(), so there is no rush fixing it.

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.