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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baa8a0c184b06f45745883501e31f89fb32382be0872a211f807cd92380c1910
4
- data.tar.gz: 00d2bc98222f9a525535e51e25e17266bd65e0caee4546ed7a4171f471129113
3
+ metadata.gz: d31c70ff7ceddc45ee52b52d8538a37ac9b67abf63a5e8762a5b998ba4d7b9a1
4
+ data.tar.gz: 821eb7578d342a5333e710cf880eeffc501f3aa65772d870ab4461413d9b3398
5
5
  SHA512:
6
- metadata.gz: 1bf5d7b03cb04995be193b191bf68e0e6302301e49c7fb5a4848b274c467b5e4384bd43c1ab74d107dc22168a03714beecca67f16cff0b413c2f8aa5bd107aa1
7
- data.tar.gz: 4d2e75eeea5e9b124754cb0048a8fcff35920430ed1c84588340a1abcf462982321ea6d71cac4ec8015cd3c533bb523e48c47c19250b5a7bdb54e8e699ef1265
6
+ metadata.gz: 87f590e5099ee1914c6bfbd18901123df1a8b2cdb900ab0b139d1cb02d4562bccf16e39b931c639db8f0643ba6793f64aef1682cd98aa36e5890cf53e14d08d7
7
+ data.tar.gz: eb920e2eabf17564f29bb2dd25ce5663d6af76e82bd74f31299f76ad7bb45542f50e568156d8bb5b021ffd62f7dbd27dfacc5baba97e552b81913e4161a87f65
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.swp
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- just_shogi (0.1.0)
4
+ just_shogi (0.1.1)
5
5
  board_game_grid (~> 0.1.6)
6
6
 
7
7
  GEM
@@ -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 invalid promotion errors can be instantiated with
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
@@ -14,5 +14,9 @@ module JustShogi
14
14
  def switch_player
15
15
  @player_number = opponent
16
16
  end
17
+
18
+ def has_legal_moves_from_y(_)
19
+ true
20
+ end
17
21
  end
18
22
  end
@@ -1,3 +1,3 @@
1
1
  module JustShogi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-05-20 00:00:00.000000000 Z
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