Giter Club home page Giter Club logo

Comments (2)

nozaq avatar nozaq commented on May 29, 2024

@ZelphirKaltstahl When you call Position#make_move() and the resulting position after the move is invalid, it returns MoveError. You can detect checkmate and repetition using this result as follows.

1. Checkmate

If you get MoveError::InCheck from make_move(), this means that the move is illegal since the king is still in check even after making a move. Given the king is already in check, you can detect the player is checkmated by trying every possible moves and check if no legal move exist.
Position#move_candidates() could be used to produce possible moves though, it's necessary to call it with each piece on the board. Currently the only way to get each piece on the board is to iterate through all squares and call [Position#piece_at()])(https://nozaq.github.io/shogi-rs/shogi/position/struct.Position.html#method.piece_at).
I'm thinking to implement an easier way to iterate over pieces of the particular player, which hopefully improve the performance of iteration.

2. Repetition

This case is simple. If you get MoveError::Repetition after making a move, that means the game should be drawn because of repetition.
Note that there is a special case in repetition situation called Perpetual Check(see https://en.wikipedia.org/wiki/Shogi). MoveError::PerpetualCheckWin and MoveError::PerpetualCheckLose exist for this case.

Hope this would help, please let me know if you have other questions :)

from shogi-rs.

ZelphirKaltstahl avatar ZelphirKaltstahl commented on May 29, 2024

Thanks for your response. I already thought of trying all moves, but was hoping there was something better. It should still be OKish performance, but of course a more efficient way would be great. I would also need to try with inserting pieces everywhere, unless I involve some logic about what piece puts the king in check and squares where it can be etc.

Thanks for the hint about perpetual check as well, I only recently learned about that on https://www.gnu.org/software/gnushogi/manual/The-rules-of-shogi.html .

from shogi-rs.

Related Issues (8)

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.