liars_dice 0.0.5 → 0.0.6
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/liars_dice.gemspec +5 -4
- data/lib/liars_dice.rb +1 -2
- data/lib/liars_dice/bots/human_bot.rb +61 -0
- data/lib/liars_dice/bots/random_bot.rb +46 -0
- data/lib/liars_dice/command_line_watcher.rb +7 -7
- data/lib/liars_dice/game.rb +1 -1
- data/lib/liars_dice/watcher.rb +13 -10
- metadata +4 -4
- data/lib/liars_dice/human_bot.rb +0 -58
- data/lib/liars_dice/random_bot.rb +0 -42
data/liars_dice.gemspec
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'liars_dice'
|
3
|
-
gem.version = '0.0.
|
4
|
-
gem.date = '2013-07-
|
3
|
+
gem.version = '0.0.6'
|
4
|
+
gem.date = '2013-07-12'
|
5
5
|
gem.summary = "Liar's Dice game"
|
6
6
|
gem.description = "A liar's dice botting environment, developed by Aisle50"
|
7
7
|
gem.authors = ['Ben Schmeckpeper', 'Chris Doyle', 'Max Page', 'Molly Struve']
|
8
8
|
gem.email = 'dev@aisle50.com'
|
9
9
|
|
10
|
-
exclusions =
|
11
|
-
|
10
|
+
exclusions = %w{ .rvmrc }
|
11
|
+
included_bots = %w{ lib/liars_dice/bots/human_bot.rb lib/liars_dice/bots/random_bot.rb }
|
12
|
+
gem.files = `git ls-files`.split($\) + included_bots - exclusions
|
12
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
14
|
gem.require_paths = ["lib"]
|
14
15
|
end
|
data/lib/liars_dice.rb
CHANGED
@@ -5,5 +5,4 @@ require 'liars_dice/event'
|
|
5
5
|
require 'liars_dice/game'
|
6
6
|
require 'liars_dice/seat'
|
7
7
|
require 'liars_dice/command_line_watcher'
|
8
|
-
|
9
|
-
require 'liars_dice/human_bot'
|
8
|
+
Dir[File.dirname(__FILE__) + '/liars_dice/bots/*.rb'].each {|file| require file }
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module LiarsDice
|
2
|
+
module Bots
|
3
|
+
class HumanBot
|
4
|
+
attr_accessor :prev_bid, :dice, :seat_number, :name
|
5
|
+
|
6
|
+
def initialize(seat_number, number_of_players, number_of_dice)
|
7
|
+
self.seat_number = seat_number
|
8
|
+
self.name = "HumanBot"
|
9
|
+
puts "You're playing as HumanBot in seat #{seat_number}"
|
10
|
+
puts "When asked for a bid, either enter <TOTAL> <FACE_VALUE> or BS"
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle_event(event)
|
14
|
+
if event.is_a? LiarsDice::BidMadeEvent
|
15
|
+
self.prev_bid = event.bid
|
16
|
+
return if event.seat_number.to_i == self.seat_number.to_i
|
17
|
+
puts event.message
|
18
|
+
elsif event.is_a? LiarsDice::BSCalledEvent
|
19
|
+
return if event.seat_number.to_i == self.seat_number.to_i
|
20
|
+
puts event.message
|
21
|
+
elsif event.is_a? LiarsDice::LoserEvent
|
22
|
+
puts "There were #{event.dice.flatten.select{|i| i == prev_bid.face_value or i == 1}.length} #{prev_bid.face_value}s"
|
23
|
+
if event.seat_number == self.seat_number
|
24
|
+
puts "You lose a die"
|
25
|
+
else
|
26
|
+
puts event.message
|
27
|
+
end
|
28
|
+
puts
|
29
|
+
self.prev_bid = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_event(event)
|
34
|
+
return if event.seat_number.to_i == seat_number.to_i
|
35
|
+
event.message
|
36
|
+
end
|
37
|
+
|
38
|
+
def dice=(dice)
|
39
|
+
@dice = dice
|
40
|
+
puts "Your dice are #{dice.inspect.to_s}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def bid
|
44
|
+
puts "You're bidding first" unless prev_bid
|
45
|
+
|
46
|
+
print "What do you bid? "
|
47
|
+
bid_string = gets.chomp
|
48
|
+
if bid_string.downcase == "bs"
|
49
|
+
return BS.new
|
50
|
+
end
|
51
|
+
parts = bid_string.split(" ").map(&:to_i)
|
52
|
+
if parts.length == 2
|
53
|
+
ret = Bid.new(*parts)
|
54
|
+
return ret if ret.valid?
|
55
|
+
end
|
56
|
+
print "Invalid bid"
|
57
|
+
return bid
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module LiarsDice
|
2
|
+
module Bots
|
3
|
+
class RandomBot
|
4
|
+
attr_accessor :prev_bid, :name
|
5
|
+
|
6
|
+
def initialize(seat_number, number_of_players, number_of_dice)
|
7
|
+
self.name = "RandomBot#{seat_number}"
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def handle_event(event)
|
12
|
+
if event.is_a? LiarsDice::BidMadeEvent
|
13
|
+
self.prev_bid = event.bid
|
14
|
+
elsif event.is_a? LiarsDice::LoserEvent
|
15
|
+
self.prev_bid = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def dice=(dice); end
|
20
|
+
|
21
|
+
def bid
|
22
|
+
if prev_bid
|
23
|
+
choice = (0...10).to_a.sample
|
24
|
+
|
25
|
+
if choice == 0
|
26
|
+
# Call BS 10% of the time
|
27
|
+
LiarsDice::BS.new
|
28
|
+
elsif choice <= 6
|
29
|
+
# Up the total 50% of the time
|
30
|
+
LiarsDice::Bid.new(prev_bid.total + 1, prev_bid.face_value)
|
31
|
+
else
|
32
|
+
# Up the number 40% of the time
|
33
|
+
r = LiarsDice::Bid.new(prev_bid.total, prev_bid.face_value + 1)
|
34
|
+
if r.face_value > 6
|
35
|
+
r.total += 1
|
36
|
+
r.face_value = 2
|
37
|
+
end
|
38
|
+
r
|
39
|
+
end
|
40
|
+
else
|
41
|
+
LiarsDice::Bid.new(1, 2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -6,13 +6,13 @@ module LiarsDice
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
self.names = {}
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
after_dice_rolled :print_dice
|
10
|
+
after_bid lambda{|seat, bid| puts "#{name(seat, true)} bids #{bid}" }
|
11
|
+
after_bs lambda{|seat| puts "#{name(seat)} calls BS" }
|
12
|
+
after_game lambda{|winner| puts "Game over. #{name(winner)} wins." }
|
13
|
+
after_round lambda{|loser| puts "#{name(loser)} loses a die" }
|
14
|
+
after_invalid_bid lambda{|seat| puts "#{name(seat)} made an invalid bid" }
|
15
|
+
after_seats_assigned lambda{|assignments| self.names = assignments }
|
16
16
|
end
|
17
17
|
|
18
18
|
def name(seat_number, justified=false)
|
data/lib/liars_dice/game.rb
CHANGED
data/lib/liars_dice/watcher.rb
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
module LiarsDice
|
2
2
|
module Watcher
|
3
|
-
attr_reader :after_roll, :after_bid, :after_round, :after_bs, :after_game, :after_dice_rolled, :after_seats_assigned, :after_invalid_bid
|
4
3
|
|
5
|
-
def
|
4
|
+
def after_bid(callback)
|
6
5
|
append_callback(:after_bid, callback)
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
8
|
+
def after_round(callback)
|
10
9
|
append_callback(:after_round, callback)
|
11
10
|
end
|
12
11
|
|
13
|
-
def
|
12
|
+
def after_bs(callback)
|
14
13
|
append_callback(:after_bs, callback)
|
15
14
|
end
|
16
15
|
|
17
|
-
def
|
16
|
+
def after_game(callback)
|
18
17
|
append_callback(:after_game, callback)
|
19
18
|
end
|
20
19
|
|
21
|
-
def
|
20
|
+
def after_dice_rolled(callback)
|
22
21
|
append_callback(:after_dice_rolled, callback)
|
23
22
|
end
|
24
23
|
|
25
|
-
def
|
24
|
+
def after_seats_assigned(callback)
|
26
25
|
append_callback(:after_seats_assigned, callback)
|
27
26
|
end
|
28
27
|
|
29
|
-
def
|
28
|
+
def after_invalid_bid(callback)
|
30
29
|
append_callback(:after_invalid_bid, callback)
|
31
30
|
end
|
32
31
|
|
@@ -54,15 +53,19 @@ module LiarsDice
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def append_callback(callback_name, callback)
|
57
|
-
raise ArgumentError.new("Callback does not respond to call") unless callback.respond_to? :call
|
58
56
|
raise ArgumentError.new("Unsupported callback #{callback_name}") unless allowed_callbacks.include? callback_name
|
57
|
+
raise ArgumentError.new("Callback does not respond to call") unless callback.respond_to?(:call) or callback.is_a? Symbol
|
59
58
|
watcher_callbacks[callback_name] << callback
|
60
59
|
end
|
61
60
|
|
62
61
|
def fire(callback_name, *args)
|
63
62
|
raise ArgumentError.new("Unsupported callback #{callback_name}") unless allowed_callbacks.include? callback_name
|
64
63
|
watcher_callbacks[callback_name].each do |callback|
|
65
|
-
callback.
|
64
|
+
if callback.is_a? Symbol
|
65
|
+
send(callback, *args)
|
66
|
+
else
|
67
|
+
callback.call(*args)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
end
|
68
71
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liars_dice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-07-
|
15
|
+
date: 2013-07-12 00:00:00.000000000Z
|
16
16
|
dependencies: []
|
17
17
|
description: A liar's dice botting environment, developed by Aisle50
|
18
18
|
email: dev@aisle50.com
|
@@ -25,12 +25,12 @@ files:
|
|
25
25
|
- liars_dice.gemspec
|
26
26
|
- lib/liars_dice.rb
|
27
27
|
- lib/liars_dice/bid.rb
|
28
|
+
- lib/liars_dice/bots/human_bot.rb
|
29
|
+
- lib/liars_dice/bots/random_bot.rb
|
28
30
|
- lib/liars_dice/command_line_watcher.rb
|
29
31
|
- lib/liars_dice/engine.rb
|
30
32
|
- lib/liars_dice/event.rb
|
31
33
|
- lib/liars_dice/game.rb
|
32
|
-
- lib/liars_dice/human_bot.rb
|
33
|
-
- lib/liars_dice/random_bot.rb
|
34
34
|
- lib/liars_dice/seat.rb
|
35
35
|
- lib/liars_dice/watcher.rb
|
36
36
|
- spec/bid_spec.rb
|
data/lib/liars_dice/human_bot.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module LiarsDice
|
2
|
-
class HumanBot
|
3
|
-
attr_accessor :prev_bid, :dice, :seat_number
|
4
|
-
|
5
|
-
def initialize(seat_number, number_of_players, number_of_dice)
|
6
|
-
self.seat_number = seat_number
|
7
|
-
puts "You're playing as HumanBot in seat #{seat_number}"
|
8
|
-
puts "When asked for a bid, either enter <TOTAL> <FACE_VALUE> or BS"
|
9
|
-
end
|
10
|
-
|
11
|
-
def handle_event(event)
|
12
|
-
if event.is_a? LiarsDice::BidMadeEvent
|
13
|
-
self.prev_bid = event.bid
|
14
|
-
return if event.seat_number.to_i == self.seat_number.to_i
|
15
|
-
puts event.message
|
16
|
-
elsif event.is_a? LiarsDice::BSCalledEvent
|
17
|
-
return if event.seat_number.to_i == self.seat_number.to_i
|
18
|
-
puts event.message
|
19
|
-
elsif event.is_a? LiarsDice::LoserEvent
|
20
|
-
puts "There were #{event.dice.flatten.select{|i| i == prev_bid.face_value or i == 1}.length} #{prev_bid.face_value}s"
|
21
|
-
if event.seat_number == self.seat_number
|
22
|
-
puts "You lose a die"
|
23
|
-
else
|
24
|
-
puts event.message
|
25
|
-
end
|
26
|
-
puts
|
27
|
-
self.prev_bid = nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def format_event(event)
|
32
|
-
return if event.seat_number.to_i == seat_number.to_i
|
33
|
-
event.message
|
34
|
-
end
|
35
|
-
|
36
|
-
def dice=(dice)
|
37
|
-
@dice = dice
|
38
|
-
puts "Your dice are #{dice.inspect.to_s}"
|
39
|
-
end
|
40
|
-
|
41
|
-
def bid
|
42
|
-
puts "You're bidding first" unless prev_bid
|
43
|
-
|
44
|
-
print "What do you bid? "
|
45
|
-
bid_string = gets.chomp
|
46
|
-
if bid_string.downcase == "bs"
|
47
|
-
return BS.new
|
48
|
-
end
|
49
|
-
parts = bid_string.split(" ").map(&:to_i)
|
50
|
-
if parts.length == 2
|
51
|
-
ret = Bid.new(*parts)
|
52
|
-
return ret if ret.valid?
|
53
|
-
end
|
54
|
-
print "Invalid bid"
|
55
|
-
return bid
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module LiarsDice
|
2
|
-
class RandomBot
|
3
|
-
attr_accessor :prev_bid
|
4
|
-
|
5
|
-
def initialize(seat_number, number_of_players, number_of_dice); end
|
6
|
-
|
7
|
-
|
8
|
-
def handle_event(event)
|
9
|
-
if event.is_a? LiarsDice::BidMadeEvent
|
10
|
-
self.prev_bid = event.bid
|
11
|
-
elsif event.is_a? LiarsDice::LoserEvent
|
12
|
-
self.prev_bid = nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def dice=(dice); end
|
17
|
-
|
18
|
-
def bid
|
19
|
-
if prev_bid
|
20
|
-
choice = (0...10).to_a.sample
|
21
|
-
|
22
|
-
if choice == 0
|
23
|
-
# Call BS 10% of the time
|
24
|
-
LiarsDice::BS.new
|
25
|
-
elsif choice <= 6
|
26
|
-
# Up the total 50% of the time
|
27
|
-
LiarsDice::Bid.new(prev_bid.total + 1, prev_bid.face_value)
|
28
|
-
else
|
29
|
-
# Up the number 40% of the time
|
30
|
-
r = LiarsDice::Bid.new(prev_bid.total, prev_bid.face_value + 1)
|
31
|
-
if r.face_value > 6
|
32
|
-
r.total += 1
|
33
|
-
r.face_value = 2
|
34
|
-
end
|
35
|
-
r
|
36
|
-
end
|
37
|
-
else
|
38
|
-
LiarsDice::Bid.new(1, 2)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|