GithubHelp home page GithubHelp logo

tlttnz2018 / xiangqi_viewer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jshou/xiangqi_viewer

0.0 1.0 0.0 810 KB

Javascript plugin for viewing Xiangqi games in a browser

License: MIT License

HTML 5.79% JavaScript 94.21%

xiangqi_viewer's Introduction

Xiangqi Viewer

Xiangqi Viewer is a javascript plugin for viewing Xiangqi (象棋) games in a browser.

Screenshot of rendered XiangiViewer

Usage

Xiangqi Viewer depends on jquery and snap.svg, so include both libraries before including xiangqi_viewer.js.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="snap.svg-min.js"></script>
<script type="text/javascript" src="xiangqi_viewer.js"></script>

Xiangqi Viewer also has some required images. Copy the "images/xiangqi_viewer" directory into your "images" directory.

Next, initialize a XiangqiViewer.Board.

<div id="xiangqi-example"></div>

<script>
  var cellSize = 55; // width of each square on the board in pixels
  var lineWidth = 2.5; // width of each line on the chessboard in pixels
  var enableUI = true; // show/hide the UI for stepping through moves

  var board = new XiangqiViewer.Board('#xiangqi-example', cellSize, lineWidth, enableUI);
</script>

Then, place pieces on the board one by one:

board.place([
  // files are counted from the left, from 0 to 8
  // ranks are counted from the top, from 0 to 9
  {code: 'e', red: false, file: 2, rank: 0},
  {code: 'r', red: true, file: 0, rank: 8},
]);

The piece codes are as follows:

Code Red piece Black piece
r
h
e
a
k
p
c

Or use the default positioning:

board.defaultSetup();

Finally, add the list of moves:

board.setMoveList([
  {instruction: 'c2=5', red: true, analysis: 'This is the most common opening.'},
  {instruction: 'c8=5', red: false, analysis: 'The parallel cannon defense.'},
  {instruction: 'h2+3', red: true, analysis: "Horse comes up to defend the center."},
  {instruction: 'e3+1', red: false, analysis: "This is a terrible move."},
  {instruction: 'a6+5', red: true, analysis: "This is a defensive move."}
]);

The analysis field is optional, and will show up in the Notes section of the viewer for its corresponding move.

xiangqi_viewer's People

Contributors

jshou avatar

Watchers

James Cloos 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.