TwentyFortyEight 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd1e0f1d57806e35b302242178e84246f788f6e2
4
- data.tar.gz: 559e666fa0cfd84c1986a7fb0618324570706975
3
+ metadata.gz: fe83920a037beecde5b1bfb7abe7c81f6722a90a
4
+ data.tar.gz: 6506f6288be1a550cb4fee734797f7d933a7eab1
5
5
  SHA512:
6
- metadata.gz: 818a1636527209ef35db2ae0d3629209181ce4c26508ba43a2fe1737b3836d62c85f5c579366dde9953e8296cc7af643f39af6fe2856c13728c45f867deaacfd
7
- data.tar.gz: '069c5d9fd01bda5d83db715ca50c6cf8ccecc78177c3d6e3e6554d4ece02596979a5fa5952b7ef0bcad86f012860199719c6116d2d740918727b30f8d08dc4d2'
6
+ metadata.gz: '039c7e5d4462a0191bd0c21de97b129ba74dad41a8224161f878f93b4a45b02faa4c3fece018b242d2f7d100cf17acfe49787c6caef414294771e51268cce82d'
7
+ data.tar.gz: 656d2266224a829cd6c2ba195670d0b943607827e9f1955f65f29f1e2e72194efc8d538795ee238f58c4c3b1036287a3f7c71740821e7a0259b1c2ebeaf442cc
data/README.md CHANGED
@@ -1,42 +1 @@
1
- # TwentyFortyEight
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
- opts = TwentyFortyEight::Cli.parse!
5
- TwentyFortyEight.send opts.mode, opts do
4
+ options = TwentyFortyEight::Cli.parse!
5
+ TwentyFortyEight.send options.mode, options do
6
6
  down || left || right || up
7
7
  end
@@ -15,10 +15,11 @@ module TwentyFortyEight
15
15
  @@best = nil
16
16
 
17
17
  def self.play(settings = {}, &block)
18
- game = Game.new @@games.count, settings
19
- dirs = game.directions - (settings.except || [])
20
- dirs = dirs - (settings.only || [])
21
- dsl = Dsl.new settings, &block if block_given?
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? :endless
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
- render_game game.action(action), settings if settings.verbose? ||
67
- settings.interactive?
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
@@ -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 = "2048 [mode] [options]"
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
@@ -68,7 +68,7 @@ module TwentyFortyEight
68
68
  end
69
69
 
70
70
  def move(dir, **opts)
71
- return self unless directions.include? dir
71
+ return self unless directions.include? dir.to_sym
72
72
 
73
73
  @prev_score = score
74
74
  @prev_available = available
@@ -1,3 +1,3 @@
1
1
  module TwentyFortyEight
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: TwentyFortyEight
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
  - Sidney Liebrand