eighty-one 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/eighty-one.gemspec +1 -2
- data/lib/.eighty_one.rb.swp +0 -0
- data/lib/{eighty_one → eighty-one}/board.rb +17 -12
- data/lib/{eighty_one → eighty-one}/face.rb +0 -0
- data/lib/{eighty_one → eighty-one}/piece.rb +0 -0
- data/lib/{eighty_one → eighty-one}/version.rb +1 -1
- data/lib/eighty_one.rb +7 -7
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f168f13b8a1936253330c0ba7059c5ee9fdab2a3bd1571ecec691faf7975de1
|
4
|
+
data.tar.gz: e621f4fd21d71e47b9cf58b15e28add3fe562e49a10b02e4838e3e6c3362fa34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c167a48ab324ddea7d83ff599e988bde19e200271f86ef306804e5e1303c8ba20148a9469c0f8f68ff7b0fd0c5387adc4c87537f70831fd409577ba533c2aa82
|
7
|
+
data.tar.gz: 8fe40b61a2710c4258e1519d342b7243f3f49bbce385d256ea40bbaf7c259bab2f9d71a10e38ae4abebcb444c9c1ec5ad1fd5c59f3334c2c1e4d5142c411cece
|
data/eighty-one.gemspec
CHANGED
Binary file
|
@@ -28,10 +28,10 @@ module EightyOne
|
|
28
28
|
self[i, 9] = Pieces::Ki.new(:sente)
|
29
29
|
self[i, 1] = Pieces::Ki.new(:gote)
|
30
30
|
end
|
31
|
-
self[
|
32
|
-
self[
|
33
|
-
self[
|
34
|
-
self[
|
31
|
+
self[8, 8] = Pieces::Ka.new(:sente)
|
32
|
+
self[2, 2] = Pieces::Ka.new(:gote)
|
33
|
+
self[2, 8] = Pieces::Hi.new(:sente)
|
34
|
+
self[8, 2] = Pieces::Hi.new(:gote)
|
35
35
|
self[5, 9] = Pieces::Ou.new(:sente)
|
36
36
|
self[5, 1] = Pieces::Ou.new(:gote)
|
37
37
|
end
|
@@ -56,12 +56,14 @@ module EightyOne
|
|
56
56
|
|
57
57
|
def []=(col, row, value)
|
58
58
|
assert(inside?(col, row))
|
59
|
-
assert(value.nil? || Piece === value)
|
59
|
+
assert(value.nil? || Piece === value, "pieace must be a class Piece: #{value.class}")
|
60
60
|
@board[(row - 1) * 9 + 9 - col] = value
|
61
61
|
end
|
62
62
|
|
63
63
|
def [](col, row)
|
64
|
-
@board[(row - 1) * 9 + 9 - col]
|
64
|
+
piece = @board[(row - 1) * 9 + 9 - col]
|
65
|
+
assert(piece.nil? || Piece === piece, "piece is not a class Piece: #{piece.class}")
|
66
|
+
piece
|
65
67
|
end
|
66
68
|
|
67
69
|
def sente_hands
|
@@ -78,9 +80,14 @@ module EightyOne
|
|
78
80
|
@board[(row - 1) * 9, 9].reverse
|
79
81
|
end
|
80
82
|
|
83
|
+
def each_cells(&block)
|
84
|
+
return @board.to_enum unless block
|
85
|
+
@board.each &block
|
86
|
+
end
|
87
|
+
|
81
88
|
def dests_from(col, row)
|
82
89
|
piece = self.at(col, row)
|
83
|
-
|
90
|
+
return [] unless piece
|
84
91
|
dest = Proc.new{|(c, r)| [col + c, piece.sente? ? row - r : row + r] }
|
85
92
|
piece.face.movements.map do |m|
|
86
93
|
if EightyOne::Faces::Direction === m
|
@@ -107,7 +114,6 @@ module EightyOne
|
|
107
114
|
def place(piece, col, row)
|
108
115
|
dest = self.at(col, row)
|
109
116
|
if dest
|
110
|
-
assert(Piece === dest)
|
111
117
|
assert(dest.turn != piece.turn)
|
112
118
|
capture(dest.reset(piece.turn))
|
113
119
|
end
|
@@ -150,14 +156,14 @@ module EightyOne
|
|
150
156
|
board
|
151
157
|
end
|
152
158
|
|
153
|
-
def
|
159
|
+
def to_usi
|
154
160
|
(1..9).map do |i|
|
155
|
-
"P#{i}" + row(i).map{|c| c ? c.to_s : ' * '}.join
|
161
|
+
"P#{i}" + row(i).reverse.map{|c| c ? c.to_s : ' * '}.join
|
156
162
|
end.join(?\n)
|
157
163
|
end
|
158
164
|
|
159
165
|
def to_s
|
160
|
-
self.
|
166
|
+
self.to_usi
|
161
167
|
end
|
162
168
|
|
163
169
|
class Movement
|
@@ -167,7 +173,6 @@ module EightyOne
|
|
167
173
|
@from = [col, row]
|
168
174
|
@board = board
|
169
175
|
@piece = board.at(col, row)
|
170
|
-
assert(Piece === @piece)
|
171
176
|
end
|
172
177
|
|
173
178
|
def to(col, row)
|
File without changes
|
File without changes
|
data/lib/eighty_one.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
1
|
+
require_relative "eighty-one/version"
|
2
2
|
|
3
3
|
module EightyOne
|
4
4
|
class CantGetMovement < RuntimeError; end
|
5
5
|
module Helper
|
6
|
-
def assert(
|
7
|
-
unless
|
8
|
-
e = RuntimeError.new
|
6
|
+
def assert(cond, message = "")
|
7
|
+
unless cond
|
8
|
+
e = RuntimeError.new "assert error: #{message}"
|
9
9
|
e.set_backtrace(caller)
|
10
10
|
raise e
|
11
11
|
end
|
@@ -13,6 +13,6 @@ module EightyOne
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
require_relative 'eighty-one/face'
|
17
|
+
require_relative 'eighty-one/piece'
|
18
|
+
require_relative 'eighty-one/board'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eighty-one
|
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
|
- youchan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,11 +68,12 @@ files:
|
|
68
68
|
- bin/console
|
69
69
|
- bin/setup
|
70
70
|
- eighty-one.gemspec
|
71
|
+
- lib/.eighty_one.rb.swp
|
72
|
+
- lib/eighty-one/board.rb
|
73
|
+
- lib/eighty-one/face.rb
|
74
|
+
- lib/eighty-one/piece.rb
|
75
|
+
- lib/eighty-one/version.rb
|
71
76
|
- lib/eighty_one.rb
|
72
|
-
- lib/eighty_one/board.rb
|
73
|
-
- lib/eighty_one/face.rb
|
74
|
-
- lib/eighty_one/piece.rb
|
75
|
-
- lib/eighty_one/version.rb
|
76
77
|
homepage: https://github.com/youchan/eighty-one
|
77
78
|
licenses:
|
78
79
|
- MIT
|
@@ -92,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|
95
|
-
|
96
|
-
rubygems_version: 2.7.3
|
96
|
+
rubygems_version: 3.0.1
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: A game engine of Shogi.
|