TwentyFortyEight 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/README.md +1 -42
- data/bin/2048 +2 -2
- data/lib/TwentyFortyEight.rb +13 -11
- data/lib/TwentyFortyEight/cli.rb +7 -7
- data/lib/TwentyFortyEight/game.rb +1 -1
- data/lib/TwentyFortyEight/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe83920a037beecde5b1bfb7abe7c81f6722a90a
|
4
|
+
data.tar.gz: 6506f6288be1a550cb4fee734797f7d933a7eab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '039c7e5d4462a0191bd0c21de97b129ba74dad41a8224161f878f93b4a45b02faa4c3fece018b242d2f7d100cf17acfe49787c6caef414294771e51268cce82d'
|
7
|
+
data.tar.gz: 656d2266224a829cd6c2ba195670d0b943607827e9f1955f65f29f1e2e72194efc8d538795ee238f58c4c3b1036287a3f7c71740821e7a0259b1c2ebeaf442cc
|
data/README.md
CHANGED
@@ -1,42 +1 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/TwentyFortyEight`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
TODO: Write docs
|
7
|
-
TODO: Write tests
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'TwentyFortyEight'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install TwentyFortyEight
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
TODO: Write usage instructions here
|
28
|
-
|
29
|
-
## Development
|
30
|
-
|
31
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
-
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
-
|
35
|
-
## Contributing
|
36
|
-
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/Sidney Liebrand/TwentyFortyEight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
-
|
39
|
-
|
40
|
-
## License
|
41
|
-
|
42
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
1
|
+
Docs can be found on: https://sidofc.github.io/projects/2048/
|
data/bin/2048
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative '../lib/TwentyFortyEight'
|
3
3
|
|
4
|
-
|
5
|
-
TwentyFortyEight.send
|
4
|
+
options = TwentyFortyEight::Cli.parse!
|
5
|
+
TwentyFortyEight.send options.mode, options do
|
6
6
|
down || left || right || up
|
7
7
|
end
|
data/lib/TwentyFortyEight.rb
CHANGED
@@ -15,10 +15,11 @@ module TwentyFortyEight
|
|
15
15
|
@@best = nil
|
16
16
|
|
17
17
|
def self.play(settings = {}, &block)
|
18
|
-
|
19
|
-
|
20
|
-
dirs
|
21
|
-
|
18
|
+
settings = Options.new settings if settings.is_a? Hash
|
19
|
+
game = Game.new @@games.count, settings
|
20
|
+
dirs = game.directions - (settings.except || [])
|
21
|
+
dirs = dirs - (settings.only || [])
|
22
|
+
dsl = Dsl.new settings, &block if block_given?
|
22
23
|
|
23
24
|
@@best ||= game
|
24
25
|
|
@@ -32,14 +33,15 @@ module TwentyFortyEight
|
|
32
33
|
restart = false
|
33
34
|
non_blocking = dirs
|
34
35
|
|
35
|
-
render_game game, settings
|
36
|
+
render_game game, settings if settings.verbose?
|
36
37
|
|
37
38
|
loop do
|
38
39
|
@@best = game if @@best != game && game.score > @@best.score
|
39
|
-
|
40
|
+
# binding.pry
|
40
41
|
if game.end?
|
41
|
-
break if settings.mode?
|
42
|
-
|
42
|
+
break if settings.mode?(:endless) ||
|
43
|
+
!settings.verbose? ||
|
44
|
+
!settings.interactive?
|
43
45
|
render_game game, settings, true
|
44
46
|
|
45
47
|
action = :default
|
@@ -54,8 +56,8 @@ module TwentyFortyEight
|
|
54
56
|
if settings.interactive?
|
55
57
|
action = Screen.handle_keypress until Game::ACTIONS.include?(action)
|
56
58
|
else
|
57
|
-
action = dsl && dsl.apply(game.dup) || non_blocking.sample
|
58
59
|
non_blocking = game.changed? ? dirs : non_blocking - [action]
|
60
|
+
action = dsl && dsl.apply(game.dup) || non_blocking.sample
|
59
61
|
|
60
62
|
if non_blocking.empty?
|
61
63
|
non_blocking.concat settings.except if settings.except?
|
@@ -63,8 +65,8 @@ module TwentyFortyEight
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
game.action action
|
69
|
+
render_game game, settings if settings.verbose? || settings.interactive?
|
68
70
|
sleep(settings.delay.to_f / 1000) if settings.delay?
|
69
71
|
end
|
70
72
|
end
|
data/lib/TwentyFortyEight/cli.rb
CHANGED
@@ -9,8 +9,7 @@ module TwentyFortyEight
|
|
9
9
|
settings[:mode] = :play unless TwentyFortyEight.modes.include? mode
|
10
10
|
|
11
11
|
OptionParser.new do |cli|
|
12
|
-
cli.banner =
|
13
|
-
|
12
|
+
cli.banner = ''
|
14
13
|
cli.separator "options:"
|
15
14
|
|
16
15
|
cli.on('-i', '--interactive', 'Can you reach the 2048 tile?') do
|
@@ -32,11 +31,6 @@ module TwentyFortyEight
|
|
32
31
|
settings[:delay] = ms
|
33
32
|
end
|
34
33
|
|
35
|
-
cli.on('-aSOLVER', '--a=SOLVER', String,
|
36
|
-
'Specify a solver to play the game') do |solver|
|
37
|
-
settings[:solver] = solver.to_sym
|
38
|
-
end
|
39
|
-
|
40
34
|
cli.on('-sSIZE', '--size=SIZE', Integer,
|
41
35
|
'Set grid size of the board') do |size|
|
42
36
|
settings[:size] = size
|
@@ -55,6 +49,12 @@ module TwentyFortyEight
|
|
55
49
|
end
|
56
50
|
|
57
51
|
cli.on('--help', 'Display this help') do
|
52
|
+
puts 'usage: 2048 [mode] [options]'
|
53
|
+
puts 'modes:'
|
54
|
+
puts ' play' + (' ' * 28) + 'Plays the game automatically in order :down, :left, :right, :up'
|
55
|
+
puts ' endless' + (' ' * 25) + 'Loops play until ctrl+C'
|
56
|
+
puts ''
|
57
|
+
puts ' When no mode is supplied, it will default to: 2048 play -i -s 4'
|
58
58
|
puts cli
|
59
59
|
exit 0
|
60
60
|
end
|