Comments (2)
@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.
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)
- Returns a bitboard which includes all pieces of the given player color
- Incorrect parsing of SFEN with 10 or more pieces of the same type in hands
- unmake_move with capture doesn't decrement number of pieces in hands HOT 1
- broken links in documentation HOT 1
- Is there any reason why `find_king()` is private? HOT 3
- [Security] Workflow lint.yml is using vulnerable action actions/checkout
- RUSTSEC-2021-0127: serde_cbor is unmaintained
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shogi-rs.