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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 608d79543717c3d25a2c22590db7e807d153a3b9c3cce49026d40d70dd0a0d00
4
- data.tar.gz: 3aa116facf776eca0c8b9229c11864fdb5c4731225d86cfc9390fc83dfecdd89
3
+ metadata.gz: 5f168f13b8a1936253330c0ba7059c5ee9fdab2a3bd1571ecec691faf7975de1
4
+ data.tar.gz: e621f4fd21d71e47b9cf58b15e28add3fe562e49a10b02e4838e3e6c3362fa34
5
5
  SHA512:
6
- metadata.gz: a0885c724c76d86b541d7cc66e1f89ec3fe79fefed1a47268eeca021dee20de5ff8f03841f2aa3e9f8e8930f2b1486c9ac96133d3d290ee28d15bf3fd2633606
7
- data.tar.gz: 4403cf8c809dfdbb12f5a105a4ed26f7bf30d9041dbab42bfd0b58c082516c742787988a70720079b5e1fa37120ebbdddc42ef0ac99017e0300d715f35618d2f
6
+ metadata.gz: c167a48ab324ddea7d83ff599e988bde19e200271f86ef306804e5e1303c8ba20148a9469c0f8f68ff7b0fd0c5387adc4c87537f70831fd409577ba533c2aa82
7
+ data.tar.gz: 8fe40b61a2710c4258e1519d342b7243f3f49bbce385d256ea40bbaf7c259bab2f9d71a10e38ae4abebcb444c9c1ec5ad1fd5c59f3334c2c1e4d5142c411cece
@@ -1,7 +1,6 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "eighty_one/version"
3
+ require "eighty-one/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "eighty-one"
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[2, 8] = Pieces::Ka.new(:sente)
32
- self[8, 2] = Pieces::Ka.new(:gote)
33
- self[8, 8] = Pieces::Hi.new(:sente)
34
- self[2, 2] = Pieces::Hi.new(:gote)
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
- assert(Piece === piece)
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 to_csi
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.to_csi
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
@@ -1,3 +1,3 @@
1
1
  module EightyOne
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,11 +1,11 @@
1
- require "eighty_one/version"
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(*conds)
7
- unless conds.all?
8
- e = RuntimeError.new 'assert error'
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
- require 'eighty_one/face'
17
- require 'eighty_one/piece'
18
- require 'eighty_one/board'
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.0
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: 2018-02-17 00:00:00.000000000 Z
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
- rubyforge_project:
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.