just_xiangqi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -0
- data/README.md +71 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/just_xiangqi.gemspec +29 -0
- data/lib/just_xiangqi/errors/error.rb +21 -0
- data/lib/just_xiangqi/errors/invalid_move_error.rb +23 -0
- data/lib/just_xiangqi/errors/moved_into_check_error.rb +23 -0
- data/lib/just_xiangqi/errors/no_legal_moves_error.rb +23 -0
- data/lib/just_xiangqi/errors/no_piece_error.rb +23 -0
- data/lib/just_xiangqi/errors/not_players_turn_error.rb +23 -0
- data/lib/just_xiangqi/errors/off_board_error.rb +23 -0
- data/lib/just_xiangqi/errors/piece_not_found_error.rb +23 -0
- data/lib/just_xiangqi/errors/square_occupied_error.rb +23 -0
- data/lib/just_xiangqi/game_state.rb +286 -0
- data/lib/just_xiangqi/piece_factory.rb +71 -0
- data/lib/just_xiangqi/pieces/jiang.rb +31 -0
- data/lib/just_xiangqi/pieces/ju.rb +19 -0
- data/lib/just_xiangqi/pieces/ma.rb +60 -0
- data/lib/just_xiangqi/pieces/pao.rb +58 -0
- data/lib/just_xiangqi/pieces/piece.rb +14 -0
- data/lib/just_xiangqi/pieces/shi.rb +31 -0
- data/lib/just_xiangqi/pieces/xiang.rb +29 -0
- data/lib/just_xiangqi/pieces/zu.rb +43 -0
- data/lib/just_xiangqi/square.rb +41 -0
- data/lib/just_xiangqi/square_set.rb +69 -0
- data/lib/just_xiangqi/version.rb +3 -0
- data/lib/just_xiangqi.rb +9 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8bb310a00877fd7e9c6dd65f268096471a03269aaeb32267f0f101b385c2a4e3
|
4
|
+
data.tar.gz: 388f1b172abd699738dc3b0f88fa242a356a675d10595ed652a29ec1d492cc91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2db50ce472215026b0fd881152bbbe62337748704afecbd8079ac025ba7511c41d0f1ef4ca1589dbf71989916ede5a0dd3fcec9637e4fa9e3afafb5b5a58e15
|
7
|
+
data.tar.gz: 2d68309b2b1298178c26aa07b8f5a91bba4030fe045adb504fa13f3842f4798581c421bcc555ee186a5f1f0266bdc01ab7d0a85ea954db4572562d6f83c09af8
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at mark@mrlhumphreys.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
just_xiangqi (0.1.0)
|
5
|
+
board_game_grid (~> 0.1.9)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
board_game_grid (0.1.9)
|
11
|
+
minitest (5.14.4)
|
12
|
+
rake (13.0.3)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 2.1.4)
|
19
|
+
just_xiangqi!
|
20
|
+
minitest (~> 5.14.0)
|
21
|
+
rake (~> 13.0.1)
|
22
|
+
|
23
|
+
BUNDLED WITH
|
24
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Mark Humphreys
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# JustXiangqi
|
2
|
+
|
3
|
+
A Xiangqi engine written in ruby. It provides a representation of a xiangqi game complete with rules enforcement and serialisation.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'just_xiangqi'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install just_xiangqi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To start, a new game state can be instantiated with the default state:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
game_state = JustXiangqi::GameState.default
|
27
|
+
```
|
28
|
+
|
29
|
+
Moves can be made by passing in the player number and the from and to ids. It will return true if the move is valid, otherwise it will return false.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
game_state.move(1, 'XX', 'YY')
|
33
|
+
```
|
34
|
+
|
35
|
+
The last change with all its details are found in the `last_change` attribute.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
game_state.last_change
|
39
|
+
```
|
40
|
+
|
41
|
+
If something unexpected happens, errors may be found in the errors attribute.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
game_state.errors
|
45
|
+
```
|
46
|
+
|
47
|
+
Also, the game can be serialized into a hash
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
game_state.as_json
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
## Development
|
55
|
+
|
56
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
|
+
|
58
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mrlhumphreys/just_xiangqi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mrlhumphreys/just_xiangqi/blob/master/CODE_OF_CONDUCT.md).
|
63
|
+
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
68
|
+
|
69
|
+
## Code of Conduct
|
70
|
+
|
71
|
+
Everyone interacting in the JustXiangqi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mrlhumphreys/just_xiangqi/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "just_xiangqi"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/just_xiangqi/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "just_xiangqi"
|
5
|
+
spec.version = JustXiangqi::VERSION
|
6
|
+
spec.authors = ["Mark Humphreys"]
|
7
|
+
spec.email = ["mark@mrlhumphreys.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A Xiangqi engine written in ruby}
|
10
|
+
spec.description = %q{Provides a representation of a xiangqi game complete with rules enforcement and serialisation.}
|
11
|
+
spec.homepage = "https://github.com/mrlhumphreys/just_xiangqi"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
25
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
26
|
+
spec.add_development_dependency "minitest", "~> 5.14.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "board_game_grid", "~> 0.1.9"
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module JustXiangqi
|
2
|
+
|
3
|
+
# = Error
|
4
|
+
#
|
5
|
+
# An error with a message
|
6
|
+
class Error
|
7
|
+
|
8
|
+
# New errors can be instantiated with
|
9
|
+
#
|
10
|
+
# @option [String] message
|
11
|
+
# the message to display.
|
12
|
+
#
|
13
|
+
# ==== Example:
|
14
|
+
# # Instantiates a new Error
|
15
|
+
# JustXiangqi::Error.new('Custom Message')
|
16
|
+
def initialize(message='Genertic Error')
|
17
|
+
@message = message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = InvalidMoveError
|
6
|
+
#
|
7
|
+
# An invalid move error with a message
|
8
|
+
class InvalidMoveError < Error
|
9
|
+
|
10
|
+
# New invalid move errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new InvalidMoveError
|
17
|
+
# JustXiangqi::InvalidMoveError.new("Custom Message")
|
18
|
+
def initialize(message="Move is invalid.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = MovedIntoCheckError
|
6
|
+
#
|
7
|
+
# A moved into check error with a message
|
8
|
+
class MovedIntoCheckError < Error
|
9
|
+
|
10
|
+
# New moved into check errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new MovedIntoCheckError
|
17
|
+
# JustXiangqi::MovedIntoCheckError.new("Custom Message")
|
18
|
+
def initialize(message="This move would leave the ou in check.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = NoLegalMovesError
|
6
|
+
#
|
7
|
+
# A no legal moves error with a message
|
8
|
+
class NoLegalMovesError < Error
|
9
|
+
|
10
|
+
# New no legal moves errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new NoLegalMovesError
|
17
|
+
# JustXiangqi::NoLegalMovesError.new("Custom Message")
|
18
|
+
def initialize(message="Piece cannot move from that square.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = NoPieceError
|
6
|
+
#
|
7
|
+
# A no piece error with a message
|
8
|
+
class NoPieceError < Error
|
9
|
+
|
10
|
+
# New no piece errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new NoPieceError
|
17
|
+
# JustXiangqi::NoPieceError.new("Custom Message")
|
18
|
+
def initialize(message="There is no piece to move.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = NotPlayersTurnError
|
6
|
+
#
|
7
|
+
# A not players turn error with a message
|
8
|
+
class NotPlayersTurnError < Error
|
9
|
+
|
10
|
+
# New not players turn errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Intantiates a new NotPlayersTurnError
|
17
|
+
# JustXiangqi::NotPlayersTurnError.new("Custom Message")
|
18
|
+
def initialize(message="It is not the player's turn yet.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = OffBoardError
|
6
|
+
#
|
7
|
+
# An off board error with a message
|
8
|
+
class OffBoardError < Error
|
9
|
+
|
10
|
+
# New off board errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new OffBoardError
|
17
|
+
# JustXiangqi::OffBoardError.new("Custom Message")
|
18
|
+
def initialize(message="Cannot move off board.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = PieceNotFoundError
|
6
|
+
#
|
7
|
+
# An piece not found error with a message
|
8
|
+
class PieceNotFoundError < Error
|
9
|
+
|
10
|
+
# New piece not found errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new PieceNotFoundError
|
17
|
+
# JustXiangqi::PieceNotFoundError.new("Custom Message")
|
18
|
+
def initialize(message="The piece could not be found.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'just_xiangqi/errors/error'
|
2
|
+
|
3
|
+
module JustXiangqi
|
4
|
+
|
5
|
+
# = SquareOccupiedError
|
6
|
+
#
|
7
|
+
# A square occupied error with a message
|
8
|
+
class SquareOccupiedError < Error
|
9
|
+
|
10
|
+
# New square occupied errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new SquareOccupiedError
|
17
|
+
# JustXiangqi::SquareOccupiedError.new("Custom Message")
|
18
|
+
def initialize(message="Square is already occupied.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|