text2048 0.4.0 → 0.5.0

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
  SHA1:
3
- metadata.gz: a002ee28cb82470ec94b93d63f285f907d2eaaa2
4
- data.tar.gz: 1c290e6b0968fbcc2978d701f640f8f0c750a383
3
+ metadata.gz: f364841e360557b497346d9675f24e39bdbb89d1
4
+ data.tar.gz: 1031bd3cea22c6120431459873d7631720578a30
5
5
  SHA512:
6
- metadata.gz: 0a5da8d1544c359adfd7212a9cd9cac4ec81cd7f4f056ddbf5b6ee5ac2e81cc3963727f0bb0ba4a1b0a69b72893fd9902b0ebec7c8b3c8b018e92f806a0e7a92
7
- data.tar.gz: 51f12d2914d8ebb9cff9a10500a9de1494a9d48936cf777d1bba2261c763b546c12063eecdedb2b57d5da0af45b41e87dffc46fd36141a8070e8d1393414a09e
6
+ metadata.gz: e4a9a739cac549134076522d78d58bd573ce241af8ff57d92e27672db25f3acbe2e078adeda68f3efdb405558075d253c9c92eb5731eaaa84d26c8b03dfa8803
7
+ data.tar.gz: 400794ed86e36d7ecb25fabe136d24c4c2cf0cbc22475abb5d214cc975549027e335fea4e9a4a082e84fdc85c6aa63ffebc489540ab551f4f9de0665f3b082dd
data/Rakefile CHANGED
@@ -39,7 +39,7 @@ end
39
39
  begin
40
40
  require 'reek/rake/task'
41
41
  Reek::Rake::Task.new do |t|
42
- t.fail_on_error = false
42
+ t.fail_on_error = true
43
43
  t.verbose = false
44
44
  t.reek_opts = '--quiet'
45
45
  t.source_files = FileList['lib/**/*.rb']
@@ -4,7 +4,7 @@ require 'text2048'
4
4
 
5
5
  Given(/^a board:$/) do |string|
6
6
  layout = string.split("\n").reduce([]) do |memo, row|
7
- memo << row.split(' ').map { |each| each == '_' ? nil : each.to_i }
7
+ memo << row.split(' ').map { |each| each.to_i }
8
8
  end
9
9
  @view = Text2048::TextView.new(output)
10
10
  @board = Text2048::Board.new(layout)
data/lib/text2048.rb CHANGED
@@ -2,4 +2,5 @@
2
2
 
3
3
  require 'text2048/board'
4
4
  require 'text2048/curses_view'
5
+ require 'text2048/monkey_patch/array'
5
6
  require 'text2048/text_view'
data/lib/text2048/app.rb CHANGED
@@ -28,7 +28,7 @@ module Text2048
28
28
  end
29
29
 
30
30
  def start
31
- @view.update(@board)
31
+ generate 2
32
32
  loop do
33
33
  @view.win if @board.win?
34
34
  @view.game_over if @board.lose?
@@ -62,8 +62,8 @@ module Text2048
62
62
  last
63
63
  end
64
64
 
65
- def generate
66
- @board.generate
65
+ def generate(num_tiles = 1)
66
+ num_tiles.times { @board.generate }
67
67
  @view.update(@board)
68
68
  @view.zoom_tiles(@board.generated_tiles)
69
69
  end
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'text2048/monkey_patch/array'
3
4
  require 'text2048/tile'
4
- require 'text2048/tiles'
5
5
 
6
6
  # This module smells of :reek:UncommunicativeModuleName
7
7
  module Text2048
@@ -10,26 +10,21 @@ module Text2048
10
10
  attr_reader :score
11
11
  attr_reader :tiles
12
12
 
13
- def initialize(tiles = nil, score = 0)
13
+ def initialize(tiles = Array.new(4) { Array.new(4, 0) }, score = 0)
14
+ @tiles = tiles.to_h
14
15
  @score = score
15
- if tiles
16
- @tiles = tiles.to_h
17
- else
18
- @tiles = (Array.new(4) { Array.new(4) }).to_h
19
- 2.times { generate }
20
- end
21
16
  end
22
17
 
23
18
  def initialize_copy(board)
24
19
  @tiles = board.tiles.dup
25
20
  end
26
21
 
22
+ def [](coord)
23
+ @tiles[coord]
24
+ end
25
+
27
26
  def to_a
28
- @tiles.reduce(Array.new(4) { Array.new(4) }) do |array, (key, value)|
29
- row, col = key
30
- array[row][col] = value && value.to_i
31
- array
32
- end
27
+ [0, 1, 2, 3].map { |each| row(each) }
33
28
  end
34
29
 
35
30
  def win?
@@ -42,24 +37,21 @@ module Text2048
42
37
  end.size == 4 * 4
43
38
  end
44
39
 
45
- def left
46
- tiles, score = move(:left)
47
- self.class.new tiles, @score + score
40
+ def right
41
+ board, score = move_right
42
+ self.class.new board, @score + score
48
43
  end
49
44
 
50
- def right
51
- tiles, score = move(:right)
52
- self.class.new tiles, @score + score
45
+ def left
46
+ reverse :right
53
47
  end
54
48
 
55
49
  def up
56
- tiles, score = transpose { move(:left) }
57
- self.class.new tiles, @score + score
50
+ transpose :left
58
51
  end
59
52
 
60
53
  def down
61
- tiles, score = transpose { move(:right) }
62
- self.class.new tiles, @score + score
54
+ transpose :right
63
55
  end
64
56
 
65
57
  def merged_tiles
@@ -73,7 +65,7 @@ module Text2048
73
65
  def generate
74
66
  loop do
75
67
  sample = @tiles.keys.sample
76
- unless @tiles[sample]
68
+ if @tiles[sample] == 0
77
69
  @tiles[sample] = Tile.new(rand < 0.8 ? 2 : 4, :generated)
78
70
  return
79
71
  end
@@ -82,22 +74,31 @@ module Text2048
82
74
 
83
75
  private
84
76
 
85
- def move(direction)
86
- to_a.reduce([[], 0]) do |memo, each|
87
- tiles, score = memo
88
- row, sc = Tiles.new(each).__send__ direction
89
- [tiles << row, score + sc]
77
+ def move_right
78
+ to_a.reduce([[], 0]) do |(board, score), each|
79
+ row, row_score = each.rmerge
80
+ [board << row, score + row_score]
90
81
  end
91
82
  end
92
83
 
84
+ def transpose(direction)
85
+ klass = self.class
86
+ board = klass.new(to_a.transpose, @score).__send__(direction)
87
+ klass.new board.to_a.transpose, board.score
88
+ end
89
+
90
+ def reverse(direction)
91
+ klass = self.class
92
+ board = klass.new(to_a.map(&:reverse), @score).__send__(direction)
93
+ klass.new board.to_a.map(&:reverse), board.score
94
+ end
95
+
93
96
  def find_tiles(status)
94
- @tiles.select { |_key, each| each && each.status == status }.keys
97
+ @tiles.select { |_key, each| each.status == status }.keys
95
98
  end
96
99
 
97
- def transpose(&block)
98
- board = self.class.new(to_a.transpose, @score)
99
- tiles, score = board.instance_eval(&block)
100
- [tiles.transpose, score]
100
+ def row(index)
101
+ [index].product([0, 1, 2, 3]).map { |each| @tiles[each] }
101
102
  end
102
103
  end
103
104
  end
@@ -7,11 +7,12 @@ module Text2048
7
7
  # 2048 related methods
8
8
  module Board
9
9
  def to_h
10
- tiles = {}
11
- [0, 1, 2, 3].product([0, 1, 2, 3]).each do |col, row|
12
- tiles[[col, row]] = self[col][row]
10
+ [0, 1, 2, 3].product([0, 1, 2, 3]).reduce({}) do |memo, (col, row)|
11
+ tile = self[col][row]
12
+ memo[[col, row]] =
13
+ tile.respond_to?(:status) ? tile : Text2048::Tile.new(tile)
14
+ memo
13
15
  end
14
- tiles
15
16
  end
16
17
  end
17
18
  end
@@ -7,22 +7,29 @@ module Text2048
7
7
  # 2048 related methods
8
8
  module Tile
9
9
  def rmerge
10
- score = 0
11
- tiles = dup
12
- (size - 1).downto(1) do |each|
13
- if tiles[each - 1] && tiles[each - 1] == tiles[each]
14
- tiles[each] = Text2048::Tile.new(tiles[each].to_i * 2, :merged)
15
- tiles[each - 1] = nil
16
- score += tiles[each].to_i
17
- end
10
+ shrink
11
+ score = (size - 1).downto(1).reduce(0) do |memo, each|
12
+ memo + (self[each] == self[each - 1] ? merge_left(each) : 0)
18
13
  end
19
- [tiles, score]
14
+ [fill_length(4), score]
20
15
  end
21
16
 
22
- def rshrink
23
- orig_size = size
24
- tiles = compact
25
- ::Array.new(orig_size - tiles.size) + tiles
17
+ def merge_left(index)
18
+ value = self[index].to_i * 2
19
+ self[index] = Text2048::Tile.new(value, :merged)
20
+ self[index - 1] = nil
21
+ value
22
+ end
23
+
24
+ def shrink
25
+ delete(0)
26
+ map! { |each| each.clear_status }
27
+ end
28
+
29
+ def fill_length(len)
30
+ compact!
31
+ unshift(Text2048::Tile.new(0)) until size == len
32
+ self
26
33
  end
27
34
  end
28
35
  end
@@ -11,7 +11,7 @@ module Text2048
11
11
  end
12
12
 
13
13
  def to_s
14
- @row.map { |each| each ? each.to_s : '_' }.join(' ')
14
+ @row.map { |each| each != 0 ? each : '_' }.join(' ')
15
15
  end
16
16
  end
17
17
 
data/lib/text2048/tile.rb CHANGED
@@ -15,6 +15,15 @@ module Text2048
15
15
  @status = status
16
16
  end
17
17
 
18
+ def clear_status
19
+ @status = nil
20
+ self
21
+ end
22
+
23
+ def merged?
24
+ @status == :merged
25
+ end
26
+
18
27
  def ==(other)
19
28
  @value == other.to_i
20
29
  end
@@ -3,5 +3,5 @@
3
3
  # This module smells of :reek:UncommunicativeModuleName
4
4
  module Text2048
5
5
  # gem version.
6
- VERSION = '0.4.0'.freeze
6
+ VERSION = '0.5.0'.freeze
7
7
  end
@@ -0,0 +1,189 @@
1
+ # encoding: utf-8
2
+
3
+ require 'text2048'
4
+
5
+ describe Array do
6
+ def tiles_with(contents)
7
+ contents.map { |each| Text2048::Tile.new(each) }
8
+ end
9
+
10
+ context '[0, 0, 0, 0]' do
11
+ Given(:tiles) { tiles_with([0, 0, 0, 0]) }
12
+
13
+ describe '#rmerge' do
14
+ When(:score) { tiles.rmerge[1] }
15
+
16
+ Then { tiles == [0, 0, 0, 0] }
17
+ And { score == 0 }
18
+ And { !tiles[0].merged? }
19
+ And { !tiles[1].merged? }
20
+ And { !tiles[2].merged? }
21
+ And { !tiles[3].merged? }
22
+ end
23
+ end
24
+
25
+ context '[2, 0, 0, 0]' do
26
+ Given(:tiles) { tiles_with([2, 0, 0, 0]) }
27
+
28
+ describe '#rmerge' do
29
+ When(:score) { tiles.rmerge[1] }
30
+
31
+ Then { tiles == [0, 0, 0, 2] }
32
+ And { score == 0 }
33
+ And { !tiles[0].merged? }
34
+ And { !tiles[1].merged? }
35
+ And { !tiles[2].merged? }
36
+ And { !tiles[3].merged? }
37
+ end
38
+ end
39
+
40
+ context '[0, 2, 0, 0]' do
41
+ Given(:tiles) { tiles_with([0, 2, 0, 0]) }
42
+
43
+ describe '#rmerge' do
44
+ When(:score) { tiles.rmerge[1] }
45
+
46
+ Then { tiles == [0, 0, 0, 2] }
47
+ And { score == 0 }
48
+ And { !tiles[0].merged? }
49
+ And { !tiles[1].merged? }
50
+ And { !tiles[2].merged? }
51
+ And { !tiles[3].merged? }
52
+ end
53
+ end
54
+
55
+ context '[0, 0, 2, 0]' do
56
+ Given(:tiles) { tiles_with([0, 0, 2, 0]) }
57
+
58
+ describe '#rmerge' do
59
+ When(:score) { tiles.rmerge[1] }
60
+
61
+ Then { tiles == [0, 0, 0, 2] }
62
+ And { score == 0 }
63
+ And { !tiles[0].merged? }
64
+ And { !tiles[1].merged? }
65
+ And { !tiles[2].merged? }
66
+ And { !tiles[3].merged? }
67
+ end
68
+ end
69
+
70
+ context '[0, 0, 0, 2]' do
71
+ Given(:tiles) { tiles_with([0, 0, 0, 2]) }
72
+
73
+ describe '#rmerge' do
74
+ When(:score) { tiles.rmerge[1] }
75
+
76
+ Then { tiles == [0, 0, 0, 2] }
77
+ And { score == 0 }
78
+ And { !tiles[0].merged? }
79
+ And { !tiles[1].merged? }
80
+ And { !tiles[2].merged? }
81
+ And { !tiles[3].merged? }
82
+ end
83
+ end
84
+
85
+ context '[0, 2, 0, 2]' do
86
+ Given(:tiles) { tiles_with([0, 2, 0, 2]) }
87
+
88
+ describe '#rmerge' do
89
+ When(:score) { tiles.rmerge[1] }
90
+
91
+ Then { tiles == [0, 0, 0, 4] }
92
+ And { score == 4 }
93
+ And { !tiles[0].merged? }
94
+ And { !tiles[1].merged? }
95
+ And { !tiles[2].merged? }
96
+ And { tiles[3].merged? }
97
+ end
98
+ end
99
+
100
+ context '[2, 2, 0, 0]' do
101
+ Given(:tiles) { tiles_with([2, 2, 0, 0]) }
102
+
103
+ describe '#rmerge' do
104
+ When(:score) { tiles.rmerge[1] }
105
+
106
+ Then { tiles == [0, 0, 0, 4] }
107
+ And { score == 4 }
108
+ And { !tiles[0].merged? }
109
+ And { !tiles[1].merged? }
110
+ And { !tiles[2].merged? }
111
+ And { tiles[3].merged? }
112
+ end
113
+ end
114
+
115
+ context '[2, 2, 2, 0]' do
116
+ Given(:tiles) { tiles_with([2, 2, 2, 0]) }
117
+
118
+ describe '#rmerge' do
119
+ When(:score) { tiles.rmerge[1] }
120
+
121
+ Then { tiles == [0, 0, 2, 4] }
122
+ And { score == 4 }
123
+ And { !tiles[0].merged? }
124
+ And { !tiles[1].merged? }
125
+ And { !tiles[2].merged? }
126
+ And { tiles[3].merged? }
127
+ end
128
+ end
129
+
130
+ context '[2, 2, 2, 2]' do
131
+ Given(:tiles) { tiles_with([2, 2, 2, 2]) }
132
+
133
+ describe '#rmerge' do
134
+ When(:score) { tiles.rmerge[1] }
135
+
136
+ Then { tiles == [0, 0, 4, 4] }
137
+ And { score == 8 }
138
+ And { !tiles[0].merged? }
139
+ And { !tiles[1].merged? }
140
+ And { tiles[2].merged? }
141
+ And { tiles[3].merged? }
142
+ end
143
+ end
144
+
145
+ context '[4, 4, 2, 2]' do
146
+ Given(:tiles) { tiles_with([4, 4, 2, 2]) }
147
+
148
+ describe '#rmerge' do
149
+ When(:score) { tiles.rmerge[1] }
150
+
151
+ Then { tiles == [0, 0, 8, 4] }
152
+ And { score == 12 }
153
+ And { !tiles[0].merged? }
154
+ And { !tiles[1].merged? }
155
+ And { tiles[2].merged? }
156
+ And { tiles[3].merged? }
157
+ end
158
+ end
159
+
160
+ context '[0, 4, 0, 2]' do
161
+ Given(:tiles) { tiles_with([0, 4, 0, 2]) }
162
+
163
+ describe '#rmerge' do
164
+ When(:score) { tiles.rmerge[1] }
165
+
166
+ Then { tiles == [0, 0, 4, 2] }
167
+ And { score == 0 }
168
+ And { !tiles[0].merged? }
169
+ And { !tiles[1].merged? }
170
+ And { !tiles[2].merged? }
171
+ And { !tiles[3].merged? }
172
+ end
173
+ end
174
+
175
+ context 'with [16, 8, 4, 2]' do
176
+ Given(:tiles) { tiles_with([16, 8, 4, 2]) }
177
+
178
+ describe '#rmerge' do
179
+ When(:score) { tiles.rmerge[1] }
180
+
181
+ Then { tiles == [16, 8, 4, 2] }
182
+ And { score == 0 }
183
+ And { !tiles[0].merged? }
184
+ And { !tiles[1].merged? }
185
+ And { !tiles[2].merged? }
186
+ And { !tiles[3].merged? }
187
+ end
188
+ end
189
+ end
@@ -3,22 +3,57 @@
3
3
  require 'text2048'
4
4
 
5
5
  describe Text2048::Board, '.new' do
6
+ context 'without arguments' do
7
+ Given(:board) { Text2048::Board.new }
8
+
9
+ Then { board.generated_tiles.empty? }
10
+ And { board.merged_tiles.empty? }
11
+ And { board.score == 0 }
12
+
13
+ describe '#generate' do
14
+ When { board.generate }
15
+ Then { board.generated_tiles.size == 1 }
16
+ end
17
+ end
18
+
19
+ context 'with one 2048 tile' do
20
+ Given(:board) do
21
+ Text2048::Board.new([[0, 0, 0, 0],
22
+ [0, 0, 0, 0],
23
+ [0, 2048, 0, 0],
24
+ [0, 0, 0, 0]])
25
+ end
26
+
27
+ Then { board.win? }
28
+ end
29
+
30
+ context 'with tiles which cannot be merged' do
31
+ Given(:board) do
32
+ Text2048::Board.new([[2, 4, 8, 16],
33
+ [4, 8, 16, 32],
34
+ [8, 16, 32, 64],
35
+ [16, 32, 64, 128]])
36
+ end
37
+
38
+ Then { board.lose? }
39
+ end
40
+
6
41
  context 'with all zeroes' do
7
42
  Given(:board) do
8
- Text2048::Board.new([[nil, nil, nil, nil],
9
- [nil, nil, nil, nil],
10
- [nil, nil, nil, nil],
11
- [nil, nil, nil, nil]])
43
+ Text2048::Board.new([[0, 0, 0, 0],
44
+ [0, 0, 0, 0],
45
+ [0, 0, 0, 0],
46
+ [0, 0, 0, 0]])
12
47
  end
13
48
 
14
49
  describe '#to_a' do
15
50
  When(:result) { board.to_a }
16
51
 
17
52
  Then do
18
- result == [[nil, nil, nil, nil],
19
- [nil, nil, nil, nil],
20
- [nil, nil, nil, nil],
21
- [nil, nil, nil, nil]]
53
+ result == [[0, 0, 0, 0],
54
+ [0, 0, 0, 0],
55
+ [0, 0, 0, 0],
56
+ [0, 0, 0, 0]]
22
57
  end
23
58
  end
24
59
 
@@ -26,51 +61,55 @@ describe Text2048::Board, '.new' do
26
61
  When(:result) { board.right }
27
62
 
28
63
  Then do
29
- result.to_a == [[nil, nil, nil, nil],
30
- [nil, nil, nil, nil],
31
- [nil, nil, nil, nil],
32
- [nil, nil, nil, nil]]
64
+ result.to_a == [[0, 0, 0, 0],
65
+ [0, 0, 0, 0],
66
+ [0, 0, 0, 0],
67
+ [0, 0, 0, 0]]
33
68
  end
69
+ And { result.score == 0 }
34
70
  end
35
71
  end
36
72
 
37
73
  context 'with four 2s' do
38
74
  Given(:board) do
39
- Text2048::Board.new([[2, nil, nil, nil],
40
- [nil, 2, nil, nil],
41
- [nil, nil, 2, nil],
42
- [nil, nil, nil, 2]])
75
+ Text2048::Board.new([[2, 0, 0, 0],
76
+ [0, 2, 0, 0],
77
+ [0, 0, 2, 0],
78
+ [0, 0, 0, 2]])
43
79
  end
44
80
 
45
81
  describe '#right' do
46
82
  When(:result) { board.right }
47
83
 
48
84
  Then do
49
- result.to_a == [[nil, nil, nil, 2],
50
- [nil, nil, nil, 2],
51
- [nil, nil, nil, 2],
52
- [nil, nil, nil, 2]]
85
+ result.to_a == [[0, 0, 0, 2],
86
+ [0, 0, 0, 2],
87
+ [0, 0, 0, 2],
88
+ [0, 0, 0, 2]]
53
89
  end
90
+ And { result.score == 0 }
54
91
  end
55
92
  end
56
93
 
57
94
  context 'with six 2s that can be merged' do
58
95
  Given(:board) do
59
- Text2048::Board.new([[2, nil, 2, nil],
60
- [nil, 2, nil, nil],
61
- [nil, 2, nil, 2],
62
- [nil, nil, nil, 2]])
96
+ Text2048::Board.new([[2, 0, 2, 0],
97
+ [0, 2, 0, 0],
98
+ [0, 2, 0, 2],
99
+ [0, 0, 0, 2]])
63
100
  end
64
101
 
65
102
  describe '#right' do
66
103
  When(:result) { board.right }
67
104
 
68
105
  Then do
69
- result.to_a == [[nil, nil, nil, 4],
70
- [nil, nil, nil, 2],
71
- [nil, nil, nil, 4],
72
- [nil, nil, nil, 2]]
106
+ result.to_a == [[0, 0, 0, 4],
107
+ [0, 0, 0, 2],
108
+ [0, 0, 0, 4],
109
+ [0, 0, 0, 2]]
73
110
  end
111
+ And { result[[0, 3]].merged? }
112
+ And { result.score == 8 }
74
113
  end
75
114
  end
76
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text2048
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuhito Takamiya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-07 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,11 +57,10 @@ files:
57
57
  - lib/text2048/monkey_patch/array/tile.rb
58
58
  - lib/text2048/text_view.rb
59
59
  - lib/text2048/tile.rb
60
- - lib/text2048/tiles.rb
61
60
  - lib/text2048/version.rb
61
+ - spec/array_spec.rb
62
62
  - spec/spec_helper.rb
63
63
  - spec/text2048/board_spec.rb
64
- - spec/text2048/tiles_spec.rb
65
64
  - text2048.gemspec
66
65
  homepage: http://github.com/yasuhito/text2048
67
66
  licenses:
@@ -88,9 +87,9 @@ signing_key:
88
87
  specification_version: 4
89
88
  summary: Text mode 2048 game.
90
89
  test_files:
90
+ - spec/array_spec.rb
91
91
  - spec/spec_helper.rb
92
92
  - spec/text2048/board_spec.rb
93
- - spec/text2048/tiles_spec.rb
94
93
  - features/game_over.feature
95
94
  - features/move_down.feature
96
95
  - features/move_left.feature
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'forwardable'
4
- require 'text2048/monkey_patch/array'
5
- require 'text2048/tile'
6
-
7
- # This module smells of :reek:UncommunicativeModuleName
8
- module Text2048
9
- # Each row or column of a game board.
10
- class Tiles
11
- extend Forwardable
12
-
13
- def initialize(list)
14
- @list = list.map { |each| each ? Tile.new(each) : nil }
15
- end
16
-
17
- def right
18
- list, score = @list.rshrink.rmerge
19
- [list.rshrink, score]
20
- end
21
-
22
- def left
23
- list, score = @list.reverse.rshrink.rmerge
24
- [list.rshrink.reverse, score]
25
- end
26
-
27
- def_delegators :@list, :map, :rshrink
28
- end
29
- end
@@ -1,115 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'text2048'
4
-
5
- describe Text2048::Tiles, '.new' do
6
- context 'with [nil, nil, nil, nil]' do
7
- Given(:tiles) { Text2048::Tiles.new([nil, nil, nil, nil]) }
8
-
9
- describe '#right' do
10
- When(:result) { tiles.right }
11
-
12
- Then { result[0] == [nil, nil, nil, nil] }
13
- end
14
- end
15
-
16
- context 'with [2, nil, nil, nil]' do
17
- Given(:tiles) { Text2048::Tiles.new([2, nil, nil, nil]) }
18
-
19
- describe '#right' do
20
- When(:result) { tiles.right }
21
-
22
- Then { result[0] == [nil, nil, nil, 2] }
23
- end
24
- end
25
-
26
- context 'with [nil, 2, nil, nil]' do
27
- Given(:tiles) { Text2048::Tiles.new([nil, 2, nil, nil]) }
28
-
29
- describe '#right' do
30
- When(:result) { tiles.right }
31
-
32
- Then { result[0] == [nil, nil, nil, 2] }
33
- end
34
- end
35
-
36
- context 'with [nil, nil, 2, nil]' do
37
- Given(:tiles) { Text2048::Tiles.new([nil, nil, 2, nil]) }
38
-
39
- describe '#right' do
40
- When(:result) { tiles.right }
41
-
42
- Then { result[0] == [nil, nil, nil, 2] }
43
- end
44
- end
45
-
46
- context 'with [nil, nil, nil, 2]' do
47
- Given(:tiles) { Text2048::Tiles.new([nil, nil, nil, 2]) }
48
-
49
- describe '#right' do
50
- When(:result) { tiles.right }
51
-
52
- Then { result[0] == [nil, nil, nil, 2] }
53
- end
54
- end
55
-
56
- context 'with [2, 2, nil, nil]' do
57
- Given(:tiles) { Text2048::Tiles.new([2, 2, nil, nil]) }
58
-
59
- describe '#right' do
60
- When(:result) { tiles.right }
61
-
62
- Then { result[0] == [nil, nil, nil, 4] }
63
- end
64
- end
65
-
66
- context 'with [2, 2, 2, nil]' do
67
- Given(:tiles) { Text2048::Tiles.new([2, 2, 2, nil]) }
68
-
69
- describe '#right' do
70
- When(:result) { tiles.right }
71
-
72
- Then { result[0] == [nil, nil, 2, 4] }
73
- end
74
- end
75
-
76
- context 'with [2, 2, 2, 2]' do
77
- Given(:tiles) { Text2048::Tiles.new([2, 2, 2, 2]) }
78
-
79
- describe '#right' do
80
- When(:result) { tiles.right }
81
-
82
- Then { result[0] == [nil, nil, 4, 4] }
83
- end
84
- end
85
-
86
- context 'with [4, 4, 2, 2]' do
87
- Given(:tiles) { Text2048::Tiles.new([4, 4, 2, 2]) }
88
-
89
- describe '#right' do
90
- When(:result) { tiles.right }
91
-
92
- Then { result[0] == [nil, nil, 8, 4] }
93
- end
94
- end
95
-
96
- context 'with [nil, 4, nil, 2]' do
97
- Given(:tiles) { Text2048::Tiles.new([nil, 4, nil, 2]) }
98
-
99
- describe '#right' do
100
- When(:result) { tiles.right }
101
-
102
- Then { result[0] == [nil, nil, 4, 2] }
103
- end
104
- end
105
-
106
- context 'with [16, 8, 4, 2]' do
107
- Given(:tiles) { Text2048::Tiles.new([16, 8, 4, 2]) }
108
-
109
- describe '#right' do
110
- When(:result) { tiles.right }
111
-
112
- Then { result[0] == [16, 8, 4, 2] }
113
- end
114
- end
115
- end