just_chess 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/just_chess.gemspec +1 -1
- data/lib/just_chess/pieces/piece.rb +6 -93
- data/lib/just_chess/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 513e0e3d88555f73b703cf696f3af05c52015b5be36ce85493493f538009fffd
|
4
|
+
data.tar.gz: d5af65bc28abc00dd7cffb897fb20d6b310b8ffcab0c036cc6eaec92409d6c83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fb19fcb38947cf44382d3954a9226da4ee43c0f93b32d0db987ec45cd88159671e7cfec29818b102408ccf0a3bf8e50354c1a350da2e9e4e4f09ea5228547cf
|
7
|
+
data.tar.gz: b0db033c28bb159a35b6f521a335745de02932f36ab2ca60cd2ba37212d8c9144924cf5edb70a8f393b6571986b0f7ba00f9f268e9922dea93305189a0d0a7d7
|
data/just_chess.gemspec
CHANGED
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency "rake", "~> 13.0.1"
|
28
28
|
spec.add_development_dependency "minitest", "~> 5.14.0"
|
29
29
|
|
30
|
-
spec.add_runtime_dependency "board_game_grid", "~> 0.1.
|
30
|
+
spec.add_runtime_dependency "board_game_grid", "~> 0.1.6"
|
31
31
|
end
|
@@ -1,33 +1,21 @@
|
|
1
|
+
require 'board_game_grid'
|
2
|
+
|
1
3
|
module JustChess
|
2
4
|
|
3
5
|
# = Piece
|
4
6
|
#
|
5
7
|
# A piece that can move on a chess board
|
6
|
-
class Piece
|
8
|
+
class Piece < BoardGameGrid::Piece
|
7
9
|
def initialize(id: , player_number: , type: nil, has_moved: false)
|
8
10
|
@id = id
|
9
11
|
@player_number = player_number
|
10
12
|
@has_moved = has_moved
|
11
13
|
end
|
12
14
|
|
13
|
-
# @return [Fixnum] the identifier of the piece.
|
14
|
-
attr_reader :id
|
15
|
-
|
16
|
-
# @return [Fixnum] the owner of the piece.
|
17
|
-
attr_reader :player_number
|
18
|
-
|
19
15
|
# @return [Boolean] determines if the piece has moved.
|
20
16
|
attr_reader :has_moved
|
21
|
-
|
22
17
|
alias_method :has_moved?, :has_moved
|
23
18
|
|
24
|
-
# The opposing player number
|
25
|
-
#
|
26
|
-
# @return [Fixnum]
|
27
|
-
def opponent
|
28
|
-
player_number == 1 ? 2 : 1
|
29
|
-
end
|
30
|
-
|
31
19
|
# mark the piece as moved
|
32
20
|
#
|
33
21
|
# @return [TrueClass]
|
@@ -35,88 +23,13 @@ module JustChess
|
|
35
23
|
@has_moved = true
|
36
24
|
end
|
37
25
|
|
38
|
-
#
|
26
|
+
# Has the piece not moved yet?
|
39
27
|
#
|
40
|
-
# @return [
|
28
|
+
# @return [TrueClass, FalseClass]
|
41
29
|
def has_not_moved?
|
42
30
|
!has_moved?
|
43
31
|
end
|
44
32
|
|
45
|
-
# The stringified identifier of the piece type.
|
46
|
-
#
|
47
|
-
# @return [String]
|
48
|
-
def type
|
49
|
-
self.class.to_s.split('::').last.downcase
|
50
|
-
end
|
51
|
-
|
52
|
-
# Can the piece move from a square, to a square, given the game state?
|
53
|
-
#
|
54
|
-
# @param [Square] from
|
55
|
-
# the origin square.
|
56
|
-
#
|
57
|
-
# @param [Square] to
|
58
|
-
# the destination square.
|
59
|
-
#
|
60
|
-
# @param [GameState] game_state
|
61
|
-
# the current game state.
|
62
|
-
#
|
63
|
-
# @return [Boolean]
|
64
|
-
def can_move?(from, to, game_state)
|
65
|
-
destinations(from, game_state).include?(to)
|
66
|
-
end
|
67
|
-
|
68
|
-
# All the squares that the piece can move to and/or capture.
|
69
|
-
#
|
70
|
-
# @param [Square] square
|
71
|
-
# the origin square.
|
72
|
-
#
|
73
|
-
# @param [GameState] game_state
|
74
|
-
# the current game state.
|
75
|
-
#
|
76
|
-
# @return [SquareSet]
|
77
|
-
def destinations(square, game_state)
|
78
|
-
[]
|
79
|
-
end
|
80
|
-
|
81
|
-
# All the squares that the piece can move to.
|
82
|
-
#
|
83
|
-
# @param [Square] square
|
84
|
-
# the origin square.
|
85
|
-
#
|
86
|
-
# @param [GameState] game_state
|
87
|
-
# the current game state.
|
88
|
-
#
|
89
|
-
# @return [SquareSet]
|
90
|
-
def move_squares(square, game_state)
|
91
|
-
destinations(square, game_state)
|
92
|
-
end
|
93
|
-
|
94
|
-
# All the squares that the piece can capture.
|
95
|
-
#
|
96
|
-
# @param [Square] square
|
97
|
-
# the origin square.
|
98
|
-
#
|
99
|
-
# @param [GameState] game_state
|
100
|
-
# the current game state.
|
101
|
-
#
|
102
|
-
# @return [SquareSet]
|
103
|
-
def capture_squares(square, game_state)
|
104
|
-
destinations(square, game_state)
|
105
|
-
end
|
106
|
-
|
107
|
-
# All the squares that the piece could potential capture. (e.g. if a piece was there)
|
108
|
-
#
|
109
|
-
# @param [Square] square
|
110
|
-
# the origin square.
|
111
|
-
#
|
112
|
-
# @param [GameState] game_state
|
113
|
-
# the current game state.
|
114
|
-
#
|
115
|
-
# @return [SquareSet]
|
116
|
-
def potential_capture_squares(square, game_state)
|
117
|
-
capture_squares(square, game_state)
|
118
|
-
end
|
119
|
-
|
120
33
|
# returns a serialized piece as a hash
|
121
34
|
#
|
122
35
|
# @return [Hash]
|
@@ -129,4 +42,4 @@ module JustChess
|
|
129
42
|
}
|
130
43
|
end
|
131
44
|
end
|
132
|
-
end
|
45
|
+
end
|
data/lib/just_chess/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_chess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
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-04-
|
11
|
+
date: 2020-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.6
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.6
|
69
69
|
description: Provides a representation of a chess game complete with rules enforcement
|
70
70
|
and serialisation.
|
71
71
|
email:
|