rbstar 1.1.0 → 1.3.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.
- checksums.yaml +4 -4
- data/bin/rbstar +12 -12
- data/lib/rbstar.rb +69 -54
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb1281b5edcb46fc45c7adf97ea35af1543e2a24a8fe49ef12fbf793c691f9a
|
4
|
+
data.tar.gz: f1a8b79eb0b9153336c7f07f3397636f771bd935a12779d78a6f4da11cf830ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92ad199cc2a98af6665fc5a3c13e0318d9ebf1734b01935ba189a16ab44c6b3b246cf1ec12d304116e7e3290f94fc90ecd2091ed4e20167d9691306d5b995634
|
7
|
+
data.tar.gz: a8de6bd3482fc7bec326648eba27956d3b4069fd68b5e5020a59c74cf288e380a4b6d4362a1d4afac71c5e6e4ff2ec7fd540063b7c8859289099d8e70a82bead
|
data/bin/rbstar
CHANGED
@@ -6,23 +6,23 @@ require 'curses'
|
|
6
6
|
require 'rbstar'
|
7
7
|
|
8
8
|
def display_curses( field,
|
9
|
-
theme = {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
theme = { field.cells[:actor] => '()',
|
10
|
+
field.cells[:blocker] => '[]',
|
11
|
+
field.cells[:wall] => '██',
|
12
|
+
field.cells[:gem] => '<>',
|
13
|
+
field.cells[:emptiness] => ' ' } )
|
14
14
|
Curses.setpos 0, 0
|
15
|
-
Curses.addstr "Level #{field.level}, #{field.count_gifts} gems left, #{
|
15
|
+
Curses.addstr "Level #{field.level + 1}/#{field.levels.length}, #{theme[ field.whats_moving ]} moving, #{field.count_gifts} gems left, score: #{field.distance} "
|
16
16
|
|
17
|
-
|
17
|
+
field.height.times do |y|
|
18
18
|
Curses.setpos y + 2, 0
|
19
19
|
|
20
|
-
|
20
|
+
field.width.times do |x|
|
21
21
|
cell = field.get_cell( x, y )
|
22
22
|
|
23
23
|
Curses.attrset( Curses::A_BOLD ) if cell == field.whats_moving
|
24
24
|
|
25
|
-
Curses.addstr theme[ cell ]
|
25
|
+
Curses.addstr theme[ cell ]
|
26
26
|
|
27
27
|
Curses.attrset( Curses::A_NORMAL )
|
28
28
|
end
|
@@ -62,13 +62,13 @@ def ncurses_main( level )
|
|
62
62
|
when ' '
|
63
63
|
field.switch_moving
|
64
64
|
when 'n'
|
65
|
-
# finished = true
|
66
65
|
field.next_level
|
67
66
|
when 'p'
|
68
|
-
# finished = true
|
69
67
|
field.prev_level
|
70
68
|
when 'q'
|
71
69
|
break
|
70
|
+
when 'r'
|
71
|
+
field.reload_level
|
72
72
|
end
|
73
73
|
rescue Curses::RequestDeniedError
|
74
74
|
'prout'
|
@@ -85,6 +85,6 @@ def ncurses_main( level )
|
|
85
85
|
end
|
86
86
|
|
87
87
|
level = 0
|
88
|
-
level = ARGV.first.to_i if ARGV.length == 1
|
88
|
+
level = ARGV.first.to_i - 1 if ARGV.length == 1
|
89
89
|
|
90
90
|
ncurses_main( level )
|
data/lib/rbstar.rb
CHANGED
@@ -1,51 +1,57 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module RbStar
|
4
|
-
VERSION = '1.
|
5
|
-
|
6
|
-
LEVEL_HEIGHT = 9
|
7
|
-
LEVEL_WIDTH = 16
|
4
|
+
VERSION = '1.3.0'
|
8
5
|
|
9
6
|
class Board
|
10
7
|
attr_reader :board,
|
8
|
+
:levels,
|
9
|
+
:cells,
|
10
|
+
:height,
|
11
|
+
:width,
|
11
12
|
:level,
|
12
13
|
:whats_moving,
|
13
14
|
:distance
|
14
15
|
|
15
16
|
def initialize( level = 0 )
|
16
|
-
@
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@
|
17
|
+
@height = 9
|
18
|
+
@width = 16
|
19
|
+
@levels = ['#################@## x#H## x #### ##x ## ## x #### x x x ## x x## x ## ##x x#################',
|
20
|
+
' # # # # # ### x @# #x #x x # # x x # # # x # # #H# x # # # # #xx## # # # # ',
|
21
|
+
'################# x#@## ## ##H## #x x ## x x## x## #x x x# x### ##x #x x x####x ##x #################',
|
22
|
+
'################# #H## # ###x#x x#x#x#x#x## # #x x# # # ####x#x#x x#x#x#x## # ## # #@ #################',
|
23
|
+
' ############## #@ # # # ## #x # x x # ### # # ##x #x# #### # x # ##x# # # # #H## # x# #x# ############## ',
|
24
|
+
' ############ # x #x x# # x # ## # x ##@ x ### x # ### x # ##H # x ##x #################',
|
25
|
+
'################# # ## ### #x ##x# #x #x # # # # # # ### ## ## # #x# #x# # ## @#x H #x#################',
|
26
|
+
'############### # x## ### #x ## x ## x## # #x ### ## #x# ### # x#x ##xHx# x #@# ### # ###############',
|
27
|
+
' # ########### #x#x # @##x x# x # # # x## x# ## #x #xHx x## x## # #x#x # # # ############ ',
|
28
|
+
' ########### #### x ## H ###x x# x## x #x #x # # # x # x##x#x # x# #@# #x ### ### # # # # ######### # #',
|
29
|
+
'################# # @## #xx xx #### x ## x##x #x#xx ##### ## ## ##x x# x H x###x### # ## ## ########### ',
|
30
|
+
'## ## #### #@#####x ### x### xx x ## ## ##x #x# ## # x ###x ## ## ## ## #H# ## x ## x #################',
|
31
|
+
' ############## # @# x ### # #x x## ## x # ## x #x## # x ### x x #x##H # x # # # ############## ',
|
32
|
+
'#################x#x x#x## x#@ ## ## H x ## x# ## x ## x# # ##x#x x#x#################',
|
33
|
+
' ###### ####### # x# x ## # x # # x ## @# #xx #x # # # # x H# ##x # #x # # x # #x x# ############## ',
|
34
|
+
'################## H#x x x##x @x#x #### ### x #### x#x# ##xx x#x ### x ####x ###x# # #################',
|
35
|
+
'################# x# #@ ## # x#xx#x # ## #x##x# x ## x# x# ## x#x x# ## # # ##x# # ## x #x H #################',
|
36
|
+
'################# x x H# ## #x#x #x ## #x# #x ## x # x#x ## #x# # x# ## x#x # x # ##x#@ # # #################',
|
37
|
+
'#################x ## ##x## # # #x ## x# x## x ## # #x ## # x# ## ## x# ##x #H## x# #x ##@#################',
|
38
|
+
'################# x#x ###x x# ##x ### # # x # # ## H # ## # @x## # # x # # ### x## #x x### x#x #################',
|
39
|
+
'################# ### x ### # # ### ##x x ## x x x ### # ###x ## x x @ H x xx################# ',
|
40
|
+
'#################x# #x# #x # ## # ##x # #x x ### #x x #### x # ###x ## #@#H x ################# ',
|
41
|
+
' ############## # # #x# #x # ## x # ### # x #x ## #x # xx x ###x # ## x ## #@#H x # ############## ',
|
42
|
+
'################# # ### ##x x ##x### #x x# #### xx x# ## ## #x x # ## ## ## @#H###xx################# ',
|
43
|
+
'################# # ## x ##x x ## #x x ## ## x ## #x ## #x x# x ## ##x #@ H ################# '].freeze
|
44
|
+
@cells = { actor: '@',
|
45
|
+
blocker: 'H',
|
46
|
+
wall: '#',
|
47
|
+
gem: 'x',
|
48
|
+
emptiness: ' ' }.freeze
|
49
|
+
@whats_moving = cells[:actor]
|
44
50
|
@distance = 0
|
45
51
|
@level = if level.negative?
|
46
52
|
0
|
47
|
-
elsif level >
|
48
|
-
|
53
|
+
elsif level > levels.size
|
54
|
+
levels.size - 1
|
49
55
|
else
|
50
56
|
level
|
51
57
|
end
|
@@ -57,41 +63,41 @@ module RbStar
|
|
57
63
|
def get_pos( actor )
|
58
64
|
pos = {}
|
59
65
|
p = @board.index( actor )
|
60
|
-
pos[
|
61
|
-
pos[
|
66
|
+
pos[ :y ] = ( p / width ).floor
|
67
|
+
pos[ :x ] = p - ( pos[ :y ] * width )
|
62
68
|
|
63
69
|
pos
|
64
70
|
end
|
65
71
|
|
66
72
|
def get_cell( x, y )
|
67
|
-
@board[ y *
|
73
|
+
@board[ y * width + x ]
|
68
74
|
end
|
69
75
|
|
70
76
|
def set_cell( x, y, value )
|
71
|
-
@board[ y *
|
77
|
+
@board[ y * width + x ] = value
|
72
78
|
end
|
73
79
|
|
74
80
|
def move( direction )
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
81
|
+
delta = { x: 0, y: 0 }
|
82
|
+
delta[ :x ] = -1 if direction == :left
|
83
|
+
delta[ :x ] = 1 if direction == :right
|
84
|
+
delta[ :y ] = -1 if direction == :up
|
85
|
+
delta[ :y ] = 1 if direction == :down
|
80
86
|
|
81
87
|
coord = get_pos( @whats_moving )
|
82
88
|
|
83
|
-
while ( coord[
|
84
|
-
( coord[
|
85
|
-
( get_cell( coord[
|
86
|
-
( @whats_moving ==
|
87
|
-
get_cell( coord[
|
89
|
+
while ( coord[ :y ] + delta[ :y ] >= 0 && coord[ :y ] + delta[ :y ] < height ) &&
|
90
|
+
( coord[ :x ] + delta[ :x ] >= 0 && coord[ :x ] + delta[ :x ] < width ) &&
|
91
|
+
( get_cell( coord[ :x ] + delta[ :x ], coord[ :y ] + delta[ :y ] ) == cells[:emptiness] ) ||
|
92
|
+
( @whats_moving == cells[:actor] &&
|
93
|
+
get_cell( coord[ :x ] + delta[ :x ], coord[ :y ] + delta[ :y ] ) == cells[:gem] )
|
88
94
|
|
89
|
-
set_cell( coord[
|
95
|
+
set_cell( coord[ :x ], coord[ :y ], ' ' )
|
90
96
|
|
91
|
-
coord[
|
92
|
-
coord[
|
97
|
+
coord[ :x ] = coord[ :x ] + delta[ :x ]
|
98
|
+
coord[ :y ] = coord[ :y ] + delta[ :y ]
|
93
99
|
|
94
|
-
set_cell( coord[
|
100
|
+
set_cell( coord[ :x ], coord[ :y ], @whats_moving )
|
95
101
|
|
96
102
|
@distance += 1
|
97
103
|
end
|
@@ -99,7 +105,16 @@ module RbStar
|
|
99
105
|
|
100
106
|
def load_level( level )
|
101
107
|
@level = level
|
108
|
+
@level = 0 if @level.negative?
|
109
|
+
@level = (@levels.length - 1) if @level >= @levels.length
|
110
|
+
|
102
111
|
@board = @levels[ @level ].dup
|
112
|
+
@distance = 0
|
113
|
+
@whats_moving = cells[:actor]
|
114
|
+
end
|
115
|
+
|
116
|
+
def reload_level
|
117
|
+
load_level( @level )
|
103
118
|
end
|
104
119
|
|
105
120
|
def prev_level
|
@@ -111,11 +126,11 @@ module RbStar
|
|
111
126
|
end
|
112
127
|
|
113
128
|
def switch_moving
|
114
|
-
@whats_moving = @whats_moving ==
|
129
|
+
@whats_moving = @whats_moving == cells[:actor] ? cells[:blocker] : cells[:actor]
|
115
130
|
end
|
116
131
|
|
117
132
|
def count_gifts
|
118
|
-
@board.count(
|
133
|
+
@board.count( cells[:gem] )
|
119
134
|
end
|
120
135
|
|
121
136
|
def success?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbstar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gwenhael Le Moine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|