https://github.com/toomanybees/ruby-chess
https://github.com/toomanybees/ruby-chess
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/toomanybees/ruby-chess
- Owner: TooManyBees
- Created: 2013-08-27T14:25:22.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-10-22T18:36:57.000Z (over 12 years ago)
- Last Synced: 2025-01-17T23:15:32.317Z (over 1 year ago)
- Language: Ruby
- Size: 324 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ruby-Chess
A command line game of chess, written in Ruby.
## Usage
A simple 'ruby chess.rb' will launch a game, or optionally pass it "random" or "chess960" as an argument for [Chess960](https://en.wikipedia.org/wiki/Chess_960) starting positions.
## Implementation
A basic game loop alternates players. On each move, a number of checks are performed:
1. Does the piece belong to the player?
2. Is the destination move a valid move for that piece?
3. Is the destination on the board?
4. Is the path to the destination blocked, or is the destination blocked by a piece of the same color?
5. Will that move place the King in check?
Any checks that detect an invalid move raise an exception, which is used to ensure that all moves follow the rules.
To determine check, the same validations are performed to see if each of the opponent's pieces can make a valid move against the player's King. Any check that actually completes without raising an exception means the King is in check.
To determine checkmate, the board is duplicated and the next turn is simulated on the fake board. If no exceptions are raised, there is a valid move that can either move the King out of check, block the threatening piece, or capture the threatening piece. Since the Board class keeps track of all the threats against a player's King, we know how many threats exist. If a King is in check from two pieces, the only possible escape is moving the king, which reduces the amount of simulations the game has to run.
There is no AI player currently, but one can be made as long as it inherits from Player and implements the get_move method.
## To Do
* Allow input in [algebraic notation](https://en.wikipedia.org/wiki/Algebraic_chess_notation), wherein only the piece type and destination is given, and the piece's starting location is inferred.
* Write a basic AI player