deckcrystel 1.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/deckcrystel.rb +71 -0
  3. metadata +43 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '037186f018366a70ac2500a21244c347769a0289f50b3f90391cd91c7f8b14e3'
4
+ data.tar.gz: 4e7884eafc79cc864a083da9e6005bb2d2cfc76852b258affcedd9536e84488c
5
+ SHA512:
6
+ metadata.gz: a6e2685d88e56752863624fc79149bb7fa6406763af431aafc621b8b3216e18339e6a87e8dab17d0565baf66ce255dd6fe590e91ca844ed4da46b36ac64d9905
7
+ data.tar.gz: fd12a01ba9bc2e8863cde5b22286249a4d049ee7dd6d733aaddd24362a5d7703b1943e1b91b18d081abba8599266fea6f1077b464c44a65ec4fca9f95806b146
@@ -0,0 +1,71 @@
1
+ class Deck
2
+ attr_accessor :position
3
+ attr_accessor :groups
4
+ def swap(one=rand(@position.size), two=rand(@position.size))
5
+ swap = @position[one]
6
+ @position[one] = @position[two]
7
+ @position[two] = swap
8
+ self
9
+ end
10
+ def shuffle
11
+ for x in 0..200
12
+ swap
13
+ end
14
+ self
15
+ end
16
+ def initialize
17
+ @position = []
18
+ @groups = []
19
+ ["c", "h", "s", "d"].each do |suit|
20
+ for card in 2..10
21
+ @position.push("#{card}#{suit}")
22
+ end
23
+ ["a", "j", "q", "k"].each do |card|
24
+ @position.push("#{card}#{suit}")
25
+ end
26
+ end
27
+ shuffle
28
+ end
29
+ def card_at(card)
30
+ @position[card]
31
+ end
32
+ def index_of(card)
33
+ @position.index(card)
34
+ end
35
+ def top(number)
36
+ if number > @position.length + 1
37
+ @position
38
+ else
39
+ @position[0...number]
40
+ end
41
+ end
42
+ def deal(num_cards, num_hands)
43
+ for i in 0...num_hands
44
+ @groups.push(top(num_cards))
45
+ for x in 0...num_cards
46
+ @position.shift
47
+ end
48
+ end
49
+ self
50
+ end
51
+ def combine
52
+ @position.push(@groups.flatten).flatten!
53
+ @groups = []
54
+ self
55
+ end
56
+ def deal_in
57
+ combine
58
+ end
59
+ end
60
+ class EukerDeck < Deck
61
+ def initialize
62
+ @position = []
63
+ @groups = []
64
+ ["c", "h", "s", "d"].each do |suit|
65
+ [9, 10, "a", "j", "q", "k"].each do |card|
66
+ @position.push("#{card}#{suit}")
67
+ end
68
+ end
69
+ shuffle
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deckcrystel
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin M
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: I made this originally as a subset of my other gem, crystel. It acts
14
+ as a virtual deck of cards.
15
+ email: benjaminnner@icloud.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/deckcrystel.rb
21
+ homepage: https://github.com/benjaminner/Ruby/tree/master/crystel/deckcrystel
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.0.8
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Deck Of Cards.
43
+ test_files: []