just_chess 0.1.0

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.
@@ -0,0 +1,86 @@
1
+ require 'just_chess/direction'
2
+
3
+ module JustChess
4
+
5
+ # = Vector
6
+ #
7
+ # An element of Vector space
8
+ class Vector
9
+
10
+ # New objects can be instantiated by passing in a two points with x and y co-ordinates
11
+ #
12
+ # @param [Point] origin
13
+ # the start point.
14
+ #
15
+ # @param [Point] destination
16
+ # the end point.
17
+ #
18
+ # ==== Example:
19
+ # # Instantiates a new Vector
20
+ # JustChess::Vector.new(
21
+ # Struct.new(:x, :y).new(1, 1),
22
+ # Struct.new(:x, :y).new(3, 3)
23
+ # })
24
+ def initialize(origin, destination)
25
+ @origin, @destination = origin, destination
26
+ end
27
+
28
+ # @return [Object] the origin.
29
+ attr_reader :origin
30
+
31
+ # @return [Object] the destination.
32
+ attr_reader :destination
33
+
34
+ # The direction of the vector as a object
35
+ #
36
+ # @return [Direction]
37
+ def direction
38
+ Direction.new(dx, dy)
39
+ end
40
+
41
+ # The biggest difference between co-ordinates
42
+ #
43
+ # @return [Fixnum]
44
+ def magnitude
45
+ [dx.abs, dy.abs].max
46
+ end
47
+
48
+ # Is the vector orthogonal?
49
+ #
50
+ # @return [Boolean]
51
+ def orthogonal?
52
+ dx == 0 || dy == 0
53
+ end
54
+
55
+ # Is the vector diagonal?
56
+ #
57
+ # @return [Boolean]
58
+ def diagonal?
59
+ dx.abs == dy.abs
60
+ end
61
+
62
+ # Is the vector not orthogonal or diagonal?
63
+ #
64
+ # @return [Boolean]
65
+ def not_orthogonal_or_diagonal?
66
+ !(orthogonal? || diagonal?)
67
+ end
68
+
69
+ # Is the vector orthogonal or diagonal?
70
+ #
71
+ # @return [Boolean]
72
+ def orthogonal_or_diagonal?
73
+ orthogonal? || diagonal?
74
+ end
75
+
76
+ private
77
+
78
+ def dx
79
+ destination.x - origin.x
80
+ end
81
+
82
+ def dy
83
+ destination.y - origin.y
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,4 @@
1
+ module JustChess
2
+ # :nodoc:
3
+ VERSION = "0.1.0"
4
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: just_chess
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Humphreys
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Provides a representation of a chess game complete with rules enforcement
56
+ and serialisation.
57
+ email:
58
+ - mark@mrlhumphreys.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - just_chess.gemspec
72
+ - lib/just_chess.rb
73
+ - lib/just_chess/direction.rb
74
+ - lib/just_chess/errors/causes_check_error.rb
75
+ - lib/just_chess/errors/error.rb
76
+ - lib/just_chess/errors/invalid_move_error.rb
77
+ - lib/just_chess/errors/invalid_promotion_error.rb
78
+ - lib/just_chess/errors/moved_into_check_error.rb
79
+ - lib/just_chess/errors/no_piece_error.rb
80
+ - lib/just_chess/errors/not_players_turn_error.rb
81
+ - lib/just_chess/errors/off_board_error.rb
82
+ - lib/just_chess/game_state.rb
83
+ - lib/just_chess/piece_factory.rb
84
+ - lib/just_chess/pieces/bishop.rb
85
+ - lib/just_chess/pieces/king.rb
86
+ - lib/just_chess/pieces/knight.rb
87
+ - lib/just_chess/pieces/pawn.rb
88
+ - lib/just_chess/pieces/piece.rb
89
+ - lib/just_chess/pieces/queen.rb
90
+ - lib/just_chess/pieces/rook.rb
91
+ - lib/just_chess/point.rb
92
+ - lib/just_chess/square.rb
93
+ - lib/just_chess/square_set.rb
94
+ - lib/just_chess/vector.rb
95
+ - lib/just_chess/version.rb
96
+ homepage: https://github.com/mrlhumphreys/just_chess
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '2.1'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.11
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: A chess engine written in ruby
120
+ test_files: []