just_shogi 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/just_shogi/errors/no_legal_moves_error.rb +22 -0
- data/lib/just_shogi/errors/square_occupied_error.rb +1 -1
- data/lib/just_shogi/errors/two_fuhyou_in_file_error.rb +22 -0
- data/lib/just_shogi/game_state.rb +7 -0
- data/lib/just_shogi/pieces/fuhyou.rb +8 -0
- data/lib/just_shogi/pieces/keima.rb +8 -0
- data/lib/just_shogi/pieces/kyousha.rb +8 -0
- data/lib/just_shogi/pieces/piece.rb +4 -0
- data/lib/just_shogi/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d31c70ff7ceddc45ee52b52d8538a37ac9b67abf63a5e8762a5b998ba4d7b9a1
|
4
|
+
data.tar.gz: 821eb7578d342a5333e710cf880eeffc501f3aa65772d870ab4461413d9b3398
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87f590e5099ee1914c6bfbd18901123df1a8b2cdb900ab0b139d1cb02d4562bccf16e39b931c639db8f0643ba6793f64aef1682cd98aa36e5890cf53e14d08d7
|
7
|
+
data.tar.gz: eb920e2eabf17564f29bb2dd25ce5663d6af76e82bd74f31299f76ad7bb45542f50e568156d8bb5b021ffd62f7dbd27dfacc5baba97e552b81913e4161a87f65
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
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
|
+
# JustShogi::NoLegalMovesError.new("Custom Message")
|
18
|
+
def initialize(message="Piece cannot move from that square.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -7,7 +7,7 @@ module JustShogi
|
|
7
7
|
# A square occupied error with a message
|
8
8
|
class SquareOccupiedError < Error
|
9
9
|
|
10
|
-
# New
|
10
|
+
# New square occupied errors can be instantiated with
|
11
11
|
#
|
12
12
|
# @option [String] message
|
13
13
|
# the message to display.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'just_shogi/errors/error'
|
2
|
+
|
3
|
+
module JustShogi
|
4
|
+
|
5
|
+
# = TwoFuhyouInFileError
|
6
|
+
#
|
7
|
+
# A two fuhyou in file error with a message
|
8
|
+
class TwoFuhyouInFileError < Error
|
9
|
+
|
10
|
+
# New two fuhyou in file errors can be instantiated with
|
11
|
+
#
|
12
|
+
# @option [String] message
|
13
|
+
# the message to display.
|
14
|
+
#
|
15
|
+
# ==== Example:
|
16
|
+
# # Instantiates a new TwoFuhyouInFileError
|
17
|
+
# JustShogi::TwoFuhyouInFileError.new("Custom Message")
|
18
|
+
def initialize(message="Cannot place two fuhyou in the same file.")
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -6,10 +6,13 @@ require 'just_shogi/errors/moved_into_check_error'
|
|
6
6
|
require 'just_shogi/errors/invalid_promotion_error'
|
7
7
|
require 'just_shogi/errors/piece_not_found_error'
|
8
8
|
require 'just_shogi/errors/square_occupied_error'
|
9
|
+
require 'just_shogi/errors/no_legal_moves_error'
|
10
|
+
require 'just_shogi/errors/two_fuhyou_in_file_error'
|
9
11
|
require 'just_shogi/errors/dropped_into_check_error'
|
10
12
|
require 'just_shogi/square_set'
|
11
13
|
require 'just_shogi/hand'
|
12
14
|
require 'just_shogi/promotion_factory'
|
15
|
+
require 'just_shogi/pieces/fuhyou'
|
13
16
|
|
14
17
|
module JustShogi
|
15
18
|
|
@@ -228,6 +231,10 @@ module JustShogi
|
|
228
231
|
@errors.push JustShogi::OffBoardError.new
|
229
232
|
elsif square.occupied?
|
230
233
|
@errors.push JustShogi::SquareOccupiedError.new
|
234
|
+
elsif !piece.has_legal_moves_from_y(square.y)
|
235
|
+
@errors.push JustShogi::NoLegalMovesError.new
|
236
|
+
elsif squares.where(x: square.x).occupied_by_piece(JustShogi::Fuhyou).occupied_by_player(player_number).any?
|
237
|
+
@errors.push JustShogi::TwoFuhyouInFileError.new
|
231
238
|
else
|
232
239
|
duplicate = self.clone
|
233
240
|
duplicate.perform_complete_drop(player_number, piece_id, square_id)
|
@@ -19,5 +19,13 @@ module JustShogi
|
|
19
19
|
def destinations(square, game_state)
|
20
20
|
game_state.squares.in_range(square, 1).in_direction(square, forwards_direction).orthogonal(square).unoccupied_or_occupied_by_opponent(player_number).unblocked(square, game_state.squares)
|
21
21
|
end
|
22
|
+
|
23
|
+
def has_legal_moves_from_y(y)
|
24
|
+
if player_number == 1
|
25
|
+
y != 0
|
26
|
+
else
|
27
|
+
y != 8
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
@@ -19,5 +19,13 @@ module JustShogi
|
|
19
19
|
def destinations(square, game_state)
|
20
20
|
game_state.squares.in_direction(square, forwards_direction).ranks_away(square, 2).files_away(square, 1).unoccupied_or_occupied_by_opponent(player_number)
|
21
21
|
end
|
22
|
+
|
23
|
+
def has_legal_moves_from_y(y)
|
24
|
+
if player_number == 1
|
25
|
+
y > 1
|
26
|
+
else
|
27
|
+
y < 7
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
@@ -19,5 +19,13 @@ module JustShogi
|
|
19
19
|
def destinations(square, game_state)
|
20
20
|
game_state.squares.orthogonal(square).in_direction(square, forwards_direction).unoccupied_or_occupied_by_opponent(player_number).unblocked(square, game_state.squares)
|
21
21
|
end
|
22
|
+
|
23
|
+
def has_legal_moves_from_y(y)
|
24
|
+
if player_number == 1
|
25
|
+
y != 0
|
26
|
+
else
|
27
|
+
y != 8
|
28
|
+
end
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
data/lib/just_shogi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_shogi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Humphreys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,11 +91,13 @@ files:
|
|
91
91
|
- lib/just_shogi/errors/invalid_move_error.rb
|
92
92
|
- lib/just_shogi/errors/invalid_promotion_error.rb
|
93
93
|
- lib/just_shogi/errors/moved_into_check_error.rb
|
94
|
+
- lib/just_shogi/errors/no_legal_moves_error.rb
|
94
95
|
- lib/just_shogi/errors/no_piece_error.rb
|
95
96
|
- lib/just_shogi/errors/not_players_turn_error.rb
|
96
97
|
- lib/just_shogi/errors/off_board_error.rb
|
97
98
|
- lib/just_shogi/errors/piece_not_found_error.rb
|
98
99
|
- lib/just_shogi/errors/square_occupied_error.rb
|
100
|
+
- lib/just_shogi/errors/two_fuhyou_in_file_error.rb
|
99
101
|
- lib/just_shogi/game_state.rb
|
100
102
|
- lib/just_shogi/hand.rb
|
101
103
|
- lib/just_shogi/piece_factory.rb
|