poker_eval 0.0.2

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.
data/lib/poker_eval.rb ADDED
@@ -0,0 +1,76 @@
1
+ # support multiple ruby version (fat binaries under windows)
2
+ begin
3
+ require 'poker_eval_api'
4
+ end
5
+
6
+ # define version string to be used internally for the Gem by Hoe.
7
+ class PokerEval
8
+ module GemVersion
9
+ VERSION = '0.0.1'
10
+ end
11
+
12
+ def self.best args
13
+ results = self.eval_hand(args)
14
+ results["combination"].each_with_index do |i, index|
15
+ if index > 0
16
+ results["combination"][index] = self.card2string(i.to_i)
17
+ end
18
+ end
19
+
20
+ return results
21
+ end
22
+
23
+ def self.winner args
24
+ index2index = {}
25
+ normalized_pockets = []
26
+ normalized_index = 0
27
+ pockets = args["pockets"]
28
+
29
+ pockets.each_with_index do |pocket, index|
30
+ if !args["fill_pockets"]
31
+ if pocket.find_index("__")
32
+ pockets[index] = []
33
+ end
34
+ end
35
+
36
+ if !pockets[index].empty?
37
+ normalized_pockets << pockets[index]
38
+ index2index[index] = normalized_index
39
+ normalized_index += 1
40
+ end
41
+ end
42
+
43
+ args["pockets"] = normalized_pockets
44
+ results = self.eval(args)
45
+
46
+
47
+ count = results["info"]["samples"]
48
+ haslopot = results["info"]["haslopot"]
49
+ hashipot = results["info"]["hashipot"]
50
+
51
+ winners = { 'low' => [], 'hi' => [] }
52
+
53
+ pockets.each_with_index do |pocket, index|
54
+ if !index2index[index].nil?
55
+ result = results["eval"][index2index[index]]
56
+ if result["winhi"] == 1 or result["tiehi"] == 1
57
+ winners["hi"] << index
58
+ end
59
+ if result["winlo"] == 1 || result["tielo"] == 1
60
+ winners["low"] << index
61
+ end
62
+ end
63
+ end
64
+
65
+ if !haslopot || winners["low"].empty?
66
+ winners.delete("low")
67
+ end
68
+
69
+ if !hashipot
70
+ winners.delete("hi")
71
+ end
72
+
73
+ return winners
74
+
75
+ end
76
+ end
@@ -0,0 +1,55 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "poker_eval"
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Miks Mikelsons"]
12
+ s.date = "2012-01-04"
13
+ s.description = "poker evaluation Ruby Interface"
14
+ s.email = "miks@cube.lv"
15
+ s.extensions = ["ext/poker_eval_api/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "README.txt"
18
+ ]
19
+ s.files = [
20
+ "COPYING",
21
+ "COPYING.ja",
22
+ "Gemfile",
23
+ "History.txt",
24
+ "README.txt",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "ext/poker_eval_api/extconf.rb",
28
+ "ext/poker_eval_api/poker_eval.c",
29
+ "lib/poker_eval.rb",
30
+ "poker_eval.gemspec",
31
+ "tasks/jeweler.rake",
32
+ "tasks/native.rake",
33
+ "test/test_poker_eval.rb"
34
+ ]
35
+ s.homepage = "http://cubesystems.lv"
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.10"
38
+ s.summary = "poker evaluation Ruby Interface"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
45
+ s.add_runtime_dependency(%q<rake-compiler>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<jeweler>, [">= 0"])
48
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
49
+ end
50
+ else
51
+ s.add_dependency(%q<jeweler>, [">= 0"])
52
+ s.add_dependency(%q<rake-compiler>, [">= 0"])
53
+ end
54
+ end
55
+
@@ -0,0 +1,25 @@
1
+ # encoding: UTF-8
2
+ task :release do
3
+ sh "vim HISTORY.markdown"
4
+ sh "vim README.markdown"
5
+ sh "git commit -a -m 'prerelease adjustments'; true"
6
+ end
7
+
8
+ require 'jeweler'
9
+ jeweler_tasks = Jeweler::Tasks.new do |gem|
10
+ gem.name = 'poker_eval'
11
+ gem.summary = 'poker evaluation Ruby Interface'
12
+ gem.description = gem.summary
13
+ gem.email = 'miks@cube.lv'
14
+ gem.homepage = 'http://cubesystems.lv'
15
+ gem.authors = ['Miks Mikelsons']
16
+ gem.extensions = FileList['ext/**/extconf.rb']
17
+
18
+ gem.files.include('lib/poker_eval.*') # add native stuff
19
+ end
20
+
21
+ $gemspec = jeweler_tasks.gemspec
22
+ $gemspec.version = jeweler_tasks.jeweler.version
23
+
24
+ Jeweler::GemcutterTasks.new
25
+
data/tasks/native.rake ADDED
@@ -0,0 +1,30 @@
1
+ # use rake-compiler for building the extension
2
+ require 'rake/extensiontask'
3
+
4
+ Rake::ExtensionTask.new('poker_eval_api', $gemspec) do |ext|
5
+ # automatically add build options to avoid need of manual input
6
+ # ext.cross_compile = true
7
+ ext.cross_config_options << "--with-poker-eval-include=/usr/local/include"
8
+ ext.cross_config_options << "--with-poker-eval-lib=/usr/local/lib/opt"
9
+ end
10
+
11
+ CLEAN.include 'lib/**/*.so'
12
+
13
+ # ensure things are compiled prior testing
14
+ task :test => [:compile]
15
+
16
+ # Workaround for rake-compiler, which YAML-dump-loads the
17
+ # gemspec, which leads to errors since Procs can't be loaded
18
+ Rake::Task.tasks.each do |task_name|
19
+ case task_name.to_s
20
+ when /^native/
21
+ task_name.prerequisites.unshift("fix_rake_compiler_gemspec_dump")
22
+ end
23
+ end
24
+
25
+ task :fix_rake_compiler_gemspec_dump do
26
+ %w{files extra_rdoc_files test_files}.each do |accessor|
27
+ $gemspec.send(accessor).instance_eval { @exclude_procs = Array.new }
28
+ end
29
+ end
30
+
@@ -0,0 +1,37 @@
1
+ #!/usr/local/bin/ruby
2
+ # $Id: test.rb 244 2009-02-01 08:43:39Z tommy $
3
+
4
+ require "test/unit"
5
+ require 'ostruct'
6
+ require "poker_eval"
7
+
8
+ class TC_PokerEval < Test::Unit::TestCase
9
+ def test_eval()
10
+ pockets = [["tc", "ac"], ["th", "ah"], ["8c", "6h"]]
11
+ board = ["7h","3s", "2c", "7s", "7d"]
12
+ game = "holdem"
13
+ result = PokerEval.eval({"game"=>game, "pockets"=>pockets, "board"=>board, "iterations"=>10000})
14
+ expect = {"info"=>{"samples"=>10000, "haslopot"=>0, "hashipot"=>1}, "eval"=>[{"scoop"=>0, "winhi"=>0, "losehi"=>0, "tiehi"=>10000, "winlo"=>0, "loselo"=>0, "tielo"=>0, "ev"=>500}, {"scoop"=>0, "winhi"=>0, "losehi"=>0, "tiehi"=>10000, "winlo"=>0, "loselo"=>0, "tielo"=>0, "ev"=>500}, {"scoop"=>0, "winhi"=>0, "losehi"=>10000, "tiehi"=>0, "winlo"=>0, "loselo"=>0, "tielo"=>0, "ev"=>0}]}
15
+ assert_equal(result, expect);
16
+ end
17
+
18
+ def test_best()
19
+ hand = ["Ac", "As", "Td", "7s", "7h", "3s", "2c"]
20
+ side = "hi"
21
+ result = PokerEval.best({"side"=>side, "hand"=>hand})
22
+ expect = {"value"=>34363392, "combination"=>["TwoPair", "As", "Ac", "7s", "7h", "Td"]}
23
+ assert_equal(result, expect);
24
+ end
25
+
26
+ def test_best_board()
27
+ board = [ 'As', '4d', '6h', '7d', '3c' ]
28
+ hand = [ '2s', '5s', 'Jd', 'Ks' ]
29
+ # hand = ["Ac", "As", "Td", "7s", "7h", "3s", "2c"]
30
+ # board = [ 'As', '4d', '5h', '7d', '9c' ]
31
+ side = "hi"
32
+ result = PokerEval.best({"side"=>side, "hand"=>hand, "board" => board})
33
+ expect = {"value"=>67371008, "combination"=>["Straight", "6h", "5s", "4d", "3c", "2s"]}
34
+ assert_equal(result, expect);
35
+ end
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poker_eval
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Miks Mikelsons
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jeweler
16
+ requirement: &70223472571760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70223472571760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake-compiler
27
+ requirement: &70223472571260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70223472571260
36
+ description: poker evaluation Ruby Interface
37
+ email: miks@cube.lv
38
+ executables: []
39
+ extensions:
40
+ - ext/poker_eval_api/extconf.rb
41
+ extra_rdoc_files:
42
+ - README.txt
43
+ files:
44
+ - COPYING
45
+ - COPYING.ja
46
+ - Gemfile
47
+ - History.txt
48
+ - README.txt
49
+ - Rakefile
50
+ - VERSION
51
+ - ext/poker_eval_api/extconf.rb
52
+ - ext/poker_eval_api/poker_eval.c
53
+ - lib/poker_eval.rb
54
+ - poker_eval.gemspec
55
+ - tasks/jeweler.rake
56
+ - tasks/native.rake
57
+ - test/test_poker_eval.rb
58
+ homepage: http://cubesystems.lv
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.10
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: poker evaluation Ruby Interface
82
+ test_files: []