just_shogi 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 +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +24 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/just_shogi.gemspec +29 -0
- data/lib/just_shogi.rb +8 -0
- data/lib/just_shogi/errors/causes_check_error.rb +22 -0
- data/lib/just_shogi/errors/dropped_into_check_error.rb +22 -0
- data/lib/just_shogi/errors/error.rb +20 -0
- data/lib/just_shogi/errors/invalid_move_error.rb +22 -0
- data/lib/just_shogi/errors/invalid_promotion_error.rb +22 -0
- data/lib/just_shogi/errors/moved_into_check_error.rb +22 -0
- data/lib/just_shogi/errors/no_piece_error.rb +22 -0
- data/lib/just_shogi/errors/not_players_turn_error.rb +22 -0
- data/lib/just_shogi/errors/off_board_error.rb +22 -0
- data/lib/just_shogi/errors/piece_not_found_error.rb +22 -0
- data/lib/just_shogi/errors/square_occupied_error.rb +22 -0
- data/lib/just_shogi/game_state.rb +355 -0
- data/lib/just_shogi/hand.rb +48 -0
- data/lib/just_shogi/piece_factory.rb +87 -0
- data/lib/just_shogi/pieces/fuhyou.rb +23 -0
- data/lib/just_shogi/pieces/ginshou.rb +23 -0
- data/lib/just_shogi/pieces/gyokushou.rb +9 -0
- data/lib/just_shogi/pieces/hisha.rb +23 -0
- data/lib/just_shogi/pieces/kakugyou.rb +23 -0
- data/lib/just_shogi/pieces/keima.rb +23 -0
- data/lib/just_shogi/pieces/kin_base.rb +23 -0
- data/lib/just_shogi/pieces/kinshou.rb +9 -0
- data/lib/just_shogi/pieces/kyousha.rb +23 -0
- data/lib/just_shogi/pieces/narigin.rb +9 -0
- data/lib/just_shogi/pieces/narikei.rb +9 -0
- data/lib/just_shogi/pieces/narikyou.rb +9 -0
- data/lib/just_shogi/pieces/ou_base.rb +70 -0
- data/lib/just_shogi/pieces/oushou.rb +9 -0
- data/lib/just_shogi/pieces/piece.rb +18 -0
- data/lib/just_shogi/pieces/ryuuma.rb +23 -0
- data/lib/just_shogi/pieces/ryuuou.rb +23 -0
- data/lib/just_shogi/pieces/tokin.rb +9 -0
- data/lib/just_shogi/promotion_factory.rb +71 -0
- data/lib/just_shogi/square.rb +51 -0
- data/lib/just_shogi/square_set.rb +64 -0
- data/lib/just_shogi/version.rb +3 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: baa8a0c184b06f45745883501e31f89fb32382be0872a211f807cd92380c1910
|
4
|
+
data.tar.gz: 00d2bc98222f9a525535e51e25e17266bd65e0caee4546ed7a4171f471129113
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1bf5d7b03cb04995be193b191bf68e0e6302301e49c7fb5a4848b274c467b5e4384bd43c1ab74d107dc22168a03714beecca67f16cff0b413c2f8aa5bd107aa1
|
7
|
+
data.tar.gz: 4d2e75eeea5e9b124754cb0048a8fcff35920430ed1c84588340a1abcf462982321ea6d71cac4ec8015cd3c533bb523e48c47c19250b5a7bdb54e8e699ef1265
|
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_shogi (0.1.0)
|
5
|
+
board_game_grid (~> 0.1.6)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
board_game_grid (0.1.6)
|
11
|
+
minitest (5.14.0)
|
12
|
+
rake (13.0.1)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
bundler (~> 2.1.4)
|
19
|
+
just_shogi!
|
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) 2020 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,80 @@
|
|
1
|
+
# JustShogi
|
2
|
+
|
3
|
+
A shogi engine written in ruby. It provides a representation of a shogi 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_shogi'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install just_shogi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To start, a new game state can be instantiated with the default state:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
game_state = JustShogi::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. The last argument is optional and if specified to true will attempt to promote the piece.
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
game_state.move(1, '77', '78', true)
|
33
|
+
```
|
34
|
+
|
35
|
+
Drops can be made by passing in the player number, the id of the piece in hand and the id of the square that the piece will be placed on. It will return true if the move is valid. Otherwise it will return false.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
game_state.drop(1, 23, '78')
|
39
|
+
```
|
40
|
+
|
41
|
+
The last change with all its details are found in the `last_change` attribute.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
game_state.last_change
|
45
|
+
```
|
46
|
+
|
47
|
+
If something unexpected happens, errors may be found in the errors attribute.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
game_state.errors
|
51
|
+
```
|
52
|
+
|
53
|
+
The winner can be gound by calling winner on the object.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
game_state.winner
|
57
|
+
```
|
58
|
+
|
59
|
+
Also, the game can be serialized into a hash.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
game_state.as_json
|
63
|
+
```
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
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.
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mrlhumphreys/just_shogi. 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_shogi/blob/master/CODE_OF_CONDUCT.md).
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
77
|
+
|
78
|
+
## Code of Conduct
|
79
|
+
|
80
|
+
Everyone interacting in the JustShogi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mrlhumphreys/just_shogi/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_shogi"
|
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
data/just_shogi.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/just_shogi/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "just_shogi"
|
5
|
+
spec.version = JustShogi::VERSION
|
6
|
+
spec.authors = ["Mark Humphreys"]
|
7
|
+
spec.email = ["mark@mrlhumphreys.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{A Shogi engine written in ruby}
|
10
|
+
spec.description = %q{Provides a representation of a shogi game complete with rules enforcement and serialisation.}
|
11
|
+
spec.homepage = "https://github.com/mrlhumphreys/just_shogi"
|
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.6"
|
29
|
+
end
|
data/lib/just_shogi.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
4
|
+
|
5
|
+
# = CausesCheckError
|
6
|
+
#
|
7
|
+
# A causes check error with a message
|
8
|
+
class CausesCheckError < Error
|
9
|
+
|
10
|
+
# New causes check errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new CausesCheckError
|
17
|
+
# JustShogi::CausesCheckError.new("Custom Message")
|
18
|
+
def initialize(message="That move would put the ou in check.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
4
|
+
|
5
|
+
# = DroppedIntoCheckError
|
6
|
+
#
|
7
|
+
# A dropped into check error with a message
|
8
|
+
class DroppedIntoCheckError < 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 DroppedIntoCheckError
|
17
|
+
# JustShogi::DroppedIntoCheckError.new("Custom Message")
|
18
|
+
def initialize(message="This move would leave the ou in check.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module JustShogi
|
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
|
+
# JustShogi::Error.new('Custom Message')
|
16
|
+
def initialize(message='Genertic Error')
|
17
|
+
@message = message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
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
|
+
# JustShogi::InvalidMoveError.new("Custom Message")
|
18
|
+
def initialize(message="Move is invalid.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
4
|
+
|
5
|
+
# = InvalidPromotionError
|
6
|
+
#
|
7
|
+
# An invalid promotion error with a message
|
8
|
+
class InvalidPromotionError < Error
|
9
|
+
|
10
|
+
# New invalid promotion errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new InvalidPromotionError
|
17
|
+
# JustShogi::InvalidPromotionError.new("Custom Message")
|
18
|
+
def initialize(message="This piece cannot promote.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
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
|
+
# JustShogi::MovedIntoCheckError.new("Custom Message")
|
18
|
+
def initialize(message="This move would leave the ou in check.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|