just_checkers 0.1.2 → 0.1.3
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_checkers.gemspec +1 -1
- data/lib/just_checkers/game_state.rb +10 -14
- data/lib/just_checkers/piece.rb +7 -7
- data/lib/just_checkers/square.rb +9 -9
- data/lib/just_checkers/square_set.rb +4 -4
- data/lib/just_checkers/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f9a84872947e5dddb0826c13edd669786b581fe
|
4
|
+
data.tar.gz: 34a9dbadce0fc0b47e8d564fbb0888a342ae093c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd608fe24b0e129f86a580c24902340b6119da7962aafcec9f75cae7b55b72b6f628284823e4f9cfe068d143e7dc9bd4115cf16f50f14c80bf9c1c2a3099b9ae
|
7
|
+
data.tar.gz: d252d1405ea6fca132d01d379a0ad5ecafe34a3549a97d03b2dcbb6c7ca74fb170d4619895aa80868b664c202840666b6acd7e9471534694a9c5b44b4f3499dd
|
data/just_checkers.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.required_ruby_version = '~> 2.
|
22
|
+
spec.required_ruby_version = '~> 2.1'
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.11"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -26,18 +26,18 @@ module JustCheckers
|
|
26
26
|
# { x: 1, y: 0, piece: { player_number: 1, direction: 1, king: false }}
|
27
27
|
# ]
|
28
28
|
# })
|
29
|
-
def initialize(
|
30
|
-
@current_player_number =
|
31
|
-
@squares = SquareSet.new(squares:
|
29
|
+
def initialize(current_player_number: , squares: [])
|
30
|
+
@current_player_number = current_player_number
|
31
|
+
@squares = SquareSet.new(squares: squares)
|
32
32
|
@messages = []
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# @return [Fixnum] who's turn it is.
|
36
36
|
attr_reader :current_player_number
|
37
|
-
|
37
|
+
|
38
38
|
# @return [Array<Square>] the board state.
|
39
39
|
attr_reader :squares
|
40
|
-
|
40
|
+
|
41
41
|
# @return [Array<String>] useful messages if any.
|
42
42
|
attr_reader :messages
|
43
43
|
|
@@ -95,14 +95,10 @@ module JustCheckers
|
|
95
95
|
#
|
96
96
|
# @return [Hash]
|
97
97
|
def as_json
|
98
|
-
{
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
#
|
103
|
-
# @return String
|
104
|
-
def to_json
|
105
|
-
as_json.to_json
|
98
|
+
{
|
99
|
+
current_player_number: current_player_number,
|
100
|
+
squares: squares.as_json
|
101
|
+
}
|
106
102
|
end
|
107
103
|
|
108
104
|
# The player number of the winner. It returns nil if there is no winner.
|
data/lib/just_checkers/piece.rb
CHANGED
@@ -25,21 +25,21 @@ module JustCheckers
|
|
25
25
|
# direction: 1,
|
26
26
|
# king: false
|
27
27
|
# })
|
28
|
-
def initialize(
|
29
|
-
@player_number =
|
30
|
-
@direction =
|
31
|
-
@king =
|
28
|
+
def initialize(player_number: , direction: , king: false)
|
29
|
+
@player_number = player_number
|
30
|
+
@direction = direction
|
31
|
+
@king = king
|
32
32
|
end
|
33
33
|
|
34
34
|
# @return [Fixnum] the owner of the piece.
|
35
35
|
attr_reader :player_number
|
36
|
-
|
36
|
+
|
37
37
|
# @return [Fixnum] the direction forward on the board, 1 for moving down, -1 for moving up.
|
38
38
|
attr_reader :direction
|
39
|
-
|
39
|
+
|
40
40
|
# @return [Boolean] set to true if the piece has been crowned.
|
41
41
|
attr_reader :king
|
42
|
-
|
42
|
+
|
43
43
|
alias_method :king?, :king
|
44
44
|
|
45
45
|
# promotes the piece by setting the +king+ attribute to true.
|
data/lib/just_checkers/square.rb
CHANGED
@@ -29,22 +29,22 @@ module JustCheckers
|
|
29
29
|
# y: 0,
|
30
30
|
# piece: { player_number: 1, direction: 1, king: false }
|
31
31
|
# })
|
32
|
-
def initialize(
|
33
|
-
@x =
|
34
|
-
@y =
|
35
|
-
if
|
36
|
-
|
32
|
+
def initialize(x: , y: , piece: nil)
|
33
|
+
@x = x
|
34
|
+
@y = y
|
35
|
+
@piece = if piece.is_a?(Hash)
|
36
|
+
Piece.new(piece)
|
37
37
|
else
|
38
|
-
|
38
|
+
piece
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
# @return [Fixnum] the x co-ordinate of the square.
|
43
|
-
attr_reader :x
|
44
|
-
|
43
|
+
attr_reader :x
|
44
|
+
|
45
45
|
# @return [Fixnum] the y co-ordinate of the square.
|
46
46
|
attr_reader :y
|
47
|
-
|
47
|
+
|
48
48
|
# @return [Piece,NilClass] The piece on the square if any.
|
49
49
|
attr_accessor :piece
|
50
50
|
|
@@ -26,11 +26,11 @@ module JustCheckers
|
|
26
26
|
# { x: 1, y: 0, piece: { player_number: 1, direction: 1, king: false }}
|
27
27
|
# ]
|
28
28
|
# })
|
29
|
-
def initialize(
|
30
|
-
if
|
31
|
-
|
29
|
+
def initialize(squares: [])
|
30
|
+
@squares = if squares.first.class == Square
|
31
|
+
squares
|
32
32
|
else
|
33
|
-
|
33
|
+
squares.map { |s| Square.new(s) }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_checkers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Humphreys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
requirements:
|
91
91
|
- - "~>"
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version: '2.
|
93
|
+
version: '2.1'
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
@@ -103,4 +103,3 @@ signing_key:
|
|
103
103
|
specification_version: 4
|
104
104
|
summary: A checkers engine written in ruby
|
105
105
|
test_files: []
|
106
|
-
has_rdoc:
|