gambit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/CHANGELOG +7 -0
- data/COPYING +340 -0
- data/INSTALL +23 -0
- data/LICENSE +7 -0
- data/README +25 -0
- data/Rakefile +87 -0
- data/TODO +6 -0
- data/examples/bird_wars/game.rb +434 -0
- data/examples/bird_wars/html/chest.rhtml +37 -0
- data/examples/bird_wars/html/combat.rhtml +38 -0
- data/examples/bird_wars/html/fight.rhtml +71 -0
- data/examples/bird_wars/html/fridge.rhtml +31 -0
- data/examples/bird_wars/html/help.rhtml +30 -0
- data/examples/bird_wars/html/house.rhtml +36 -0
- data/examples/bird_wars/html/images/albatross.jpg +0 -0
- data/examples/bird_wars/html/images/alka_seltzer_small.png +0 -0
- data/examples/bird_wars/html/images/bazooka_small.png +0 -0
- data/examples/bird_wars/html/images/bb_gun_small.png +0 -0
- data/examples/bird_wars/html/images/cat_small.png +0 -0
- data/examples/bird_wars/html/images/combat.png +0 -0
- data/examples/bird_wars/html/images/crossbow_small.png +0 -0
- data/examples/bird_wars/html/images/cuckoo.jpg +0 -0
- data/examples/bird_wars/html/images/fridge.png +0 -0
- data/examples/bird_wars/html/images/gull.jpg +0 -0
- data/examples/bird_wars/html/images/house.jpg +0 -0
- data/examples/bird_wars/html/images/items.png +0 -0
- data/examples/bird_wars/html/images/not_found.png +0 -0
- data/examples/bird_wars/html/images/note.jpg +0 -0
- data/examples/bird_wars/html/images/oil_small.png +0 -0
- data/examples/bird_wars/html/images/one_stone_small.png +0 -0
- data/examples/bird_wars/html/images/owl.jpg +0 -0
- data/examples/bird_wars/html/images/poisoned_seeds_small.png +0 -0
- data/examples/bird_wars/html/images/rice_small.png +0 -0
- data/examples/bird_wars/html/images/shotgun_small.png +0 -0
- data/examples/bird_wars/html/images/slingshot_small.png +0 -0
- data/examples/bird_wars/html/images/soda_rings_small.png +0 -0
- data/examples/bird_wars/html/images/spear_small.png +0 -0
- data/examples/bird_wars/html/images/stork.jpg +0 -0
- data/examples/bird_wars/html/images/weapons.png +0 -0
- data/examples/bird_wars/html/images/woodpecker.jpg +0 -0
- data/examples/bird_wars/html/images/you.jpg +0 -0
- data/examples/bird_wars/html/index.rhtml +13 -0
- data/examples/bird_wars/html/weapons.rhtml +35 -0
- data/examples/cli/blackjack.rb +86 -0
- data/examples/cli/go.rb +93 -0
- data/examples/cli/space_trader2/planet_data +12280 -0
- data/examples/cli/space_trader2/space_trader2.rb +248 -0
- data/examples/cli/space_trader2/world.rb +127 -0
- data/examples/cli/spacetrader.rb +262 -0
- data/examples/cli/yahtzee.rb +161 -0
- data/examples/galactic_courier/Rakefile +9 -0
- data/examples/galactic_courier/bin/galactic_courier.rb +44 -0
- data/examples/galactic_courier/html/console.rhtml +15 -0
- data/examples/galactic_courier/html/images/barren.jpg +0 -0
- data/examples/galactic_courier/html/images/industrial.jpg +0 -0
- data/examples/galactic_courier/html/images/jungle.jpg +0 -0
- data/examples/galactic_courier/html/images/oceanic.jpg +0 -0
- data/examples/galactic_courier/html/images/tundra.jpg +0 -0
- data/examples/galactic_courier/html/images/volcanic.jpg +0 -0
- data/examples/galactic_courier/lib/galaxy.rb +64 -0
- data/examples/galactic_courier/lib/planet.rb +30 -0
- data/examples/galactic_courier/lib/sector.rb +84 -0
- data/examples/galactic_courier/lib/station.rb +18 -0
- data/examples/galactic_courier/test/tc_galaxy.rb +24 -0
- data/examples/galactic_courier/test/tc_planet.rb +22 -0
- data/examples/galactic_courier/test/tc_sector.rb +55 -0
- data/examples/galactic_courier/test/ts_all.rb +12 -0
- data/examples/gambit_mail/html/compose.rhtml +39 -0
- data/examples/gambit_mail/html/index.rhtml +3 -0
- data/examples/gambit_mail/html/mailbox.rhtml +47 -0
- data/examples/gambit_mail/html/message.rhtml +34 -0
- data/examples/gambit_mail/mail.rb +75 -0
- data/lib/gambit.rb +10 -0
- data/lib/gambit/server.rb +269 -0
- data/lib/gambit/server/gambiterror.rb +28 -0
- data/lib/gambit/server/game.rb +185 -0
- data/lib/gambit/server/game/eventform.rb +174 -0
- data/lib/gambit/server/message.rb +85 -0
- data/lib/gambit/server/player.rb +40 -0
- data/lib/gambit/tools.rb +13 -0
- data/lib/gambit/tools/board.rb +275 -0
- data/lib/gambit/tools/cards.rb +11 -0
- data/lib/gambit/tools/cards/card.rb +158 -0
- data/lib/gambit/tools/cards/deck.rb +99 -0
- data/lib/gambit/tools/cards/hand.rb +86 -0
- data/lib/gambit/tools/cards/pile.rb +107 -0
- data/lib/gambit/tools/currency.rb +148 -0
- data/lib/gambit/tools/dice.rb +219 -0
- data/lib/gambit/tools/movehistory.rb +164 -0
- data/lib/gambit/tools/scorecard.rb +333 -0
- data/lib/gambit/viewable.rb +71 -0
- data/setup.rb +1360 -0
- data/test/tc_board.rb +167 -0
- data/test/tc_cards.rb +182 -0
- data/test/tc_currency.rb +99 -0
- data/test/tc_dice.rb +83 -0
- data/test/tc_error.rb +34 -0
- data/test/tc_event.rb +367 -0
- data/test/tc_game.rb +29 -0
- data/test/tc_message.rb +35 -0
- data/test/tc_movehistory.rb +38 -0
- data/test/tc_player.rb +60 -0
- data/test/tc_scorecard.rb +112 -0
- data/test/tc_views.rb +353 -0
- data/test/test_game.rb +19 -0
- data/test/test_view.rhtml +2 -0
- data/test/ts_all.rb +12 -0
- data/test/ts_server.rb +14 -0
- data/test/ts_tools.rb +14 -0
- metadata +183 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_movehistory.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-05-30.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/tools/movehistory"
|
11
|
+
|
12
|
+
class TestMoveHistory < Test::Unit::TestCase
|
13
|
+
def test_chess_history
|
14
|
+
assert_not_nil(hist = Gambit::Tools::MoveHistory.new("James", "Greg"))
|
15
|
+
assert_same(hist, hist << "e4")
|
16
|
+
assert_same(hist, hist << "e5")
|
17
|
+
assert_same(hist, hist << "f4")
|
18
|
+
assert_equal("e5", hist[1, "Greg"])
|
19
|
+
moves = %w{e4 e5 f4}
|
20
|
+
hist.each { |move| assert_equal(moves.shift, move) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_advanced
|
24
|
+
assert_not_nil(hist = Gambit::Tools::MoveHistory.new("James", "Greg"))
|
25
|
+
hist.turn = "Stardate 1005"
|
26
|
+
assert_same(hist, hist.record("James", "Conquered Gray Galaxy!"))
|
27
|
+
assert_equal("Conquered Gray Galaxy!", hist["Stardate 1005", "James"])
|
28
|
+
assert_same(hist, hist.record("Greg", "Visited Gray Alien Race!"))
|
29
|
+
assert_equal("Visited Gray Alien Race!", hist["Stardate 1005", "Greg"])
|
30
|
+
assert_same(hist, hist.record("Greg", "Purchased Alien Liquor!"))
|
31
|
+
assert_equal( [ "Visited Gray Alien Race!",
|
32
|
+
"Purchased Alien Liquor!" ],
|
33
|
+
hist["Stardate 1005", "Greg"] )
|
34
|
+
hist.turn = "Stardate 1010"
|
35
|
+
assert_same(hist, hist.record("James", "Built Alien AI!"))
|
36
|
+
assert_equal("Built Alien AI!", hist["Stardate 1010", "James"])
|
37
|
+
end
|
38
|
+
end
|
data/test/tc_player.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_player.rb
|
4
|
+
#
|
5
|
+
# Created by Gregory Brown on 2005-06-04.
|
6
|
+
# Copyright 2005 smtose.org. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/server/player"
|
11
|
+
require "test_game"
|
12
|
+
|
13
|
+
class TestPlayer < Test::Unit::TestCase
|
14
|
+
def test_login
|
15
|
+
assert_not_nil(player = Gambit::Server::Player.new("James", "NOW!"))
|
16
|
+
assert_equal("James", player.name)
|
17
|
+
assert(player.login?("NOW!"))
|
18
|
+
assert(!player.login?("Junk"))
|
19
|
+
assert(!player.login?("NoW!"))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_messages
|
23
|
+
player = Gambit::Server::Player.new("Greg", "PASS!")
|
24
|
+
message = Gambit::Server::Message.new(
|
25
|
+
"Gregory Brown", "James Gray", "Test",
|
26
|
+
"This is a test!")
|
27
|
+
message2 = Gambit::Server::Message.new(
|
28
|
+
"James Gray", "Gregory Brown", "Hatemail",
|
29
|
+
"I'm a bastard so i'm sending you hatemail.")
|
30
|
+
assert_same(player.mailbox, player.mailbox << message)
|
31
|
+
assert_equal(message, player.mailbox.first)
|
32
|
+
assert_equal(message, player.mailbox.shift)
|
33
|
+
assert_nil(player.mailbox.find { |mes| mes == message })
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_notes
|
37
|
+
assert_not_nil(player = Gambit::Server::Player.new("James", "NOW!"))
|
38
|
+
assert_not_nil(game = MyGame.new)
|
39
|
+
game.player = player
|
40
|
+
assert_equal("", game.notify)
|
41
|
+
assert_same(player.notes, player.notes << "You have five turns left.")
|
42
|
+
assert_equal( "<ul class=\"notification\">\n" +
|
43
|
+
"\t<li>You have five turns left.</li>\n" +
|
44
|
+
"</ul>\n", game.notify )
|
45
|
+
assert_same( player.notes,
|
46
|
+
player.notes << "Greg has declared war on you!" )
|
47
|
+
assert_same( player.notes,
|
48
|
+
player.notes << "Your Earth colony has the plague." )
|
49
|
+
assert_equal( "<ul class=\"notification\">\n" +
|
50
|
+
"\t<li>Greg has declared war on you!</li>\n" +
|
51
|
+
"\t<li>Your Earth colony has the plague.</li>\n" +
|
52
|
+
"</ul>\n", game.notify )
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_game_data
|
56
|
+
assert_not_nil(player = Gambit::Server::Player.new("James", "NOW!"))
|
57
|
+
assert_equal(45, player["Pilot Skill"] = 45)
|
58
|
+
assert_equal(45, player["Pilot Skill"])
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_scorecard.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-02-11.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
require "gambit/tools/scorecard"
|
10
|
+
|
11
|
+
class TestScorecard < Test::Unit::TestCase
|
12
|
+
def test_basic
|
13
|
+
# setup
|
14
|
+
assert_not_nil(sc = Gambit::Tools::Scorecard.new)
|
15
|
+
# test for chaining and show interface
|
16
|
+
assert_same(sc, sc.add_player("James"))
|
17
|
+
assert_same(sc, sc.add_player("Greg"))
|
18
|
+
assert_equal(10, sc.start_at = 10)
|
19
|
+
assert_same(sc, sc.add_players("Apple", "Microsoft"))
|
20
|
+
|
21
|
+
# scores and totaling
|
22
|
+
assert_equal(10, sc.total("James"))
|
23
|
+
assert_equal(15, sc.score("James", 5))
|
24
|
+
assert_equal(15, sc.total("James"))
|
25
|
+
assert_equal(30, sc.score("James") { |count| count * 2 })
|
26
|
+
assert_equal(2, sc.score("Microsoft", -8))
|
27
|
+
|
28
|
+
# win/loss
|
29
|
+
assert_equal("James", sc.winner)
|
30
|
+
assert_equal("Microsoft", sc.loser)
|
31
|
+
assert_equal("Microsoft", sc.winner { |a, b| b <=> a })
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_advanced
|
35
|
+
# setup: define categories with high/low, sets, validation
|
36
|
+
assert_not_nil(yahtzee = Gambit::Tools::Scorecard.new("James", "Greg"))
|
37
|
+
assert_same(yahtzee, yahtzee.use_category("Ones", 0, 6))
|
38
|
+
assert_same(yahtzee, yahtzee.use_category("Twos", [0, 2, 4, 6, 8, 10]))
|
39
|
+
assert_same( yahtzee, yahtzee.use_category( "Threes", [ 0, 3, 6,
|
40
|
+
9, 12, 15 ] ) )
|
41
|
+
assert_same( yahtzee, yahtzee.use_category( "Fours", [ 0, 4, 8,
|
42
|
+
12, 16, 20 ] ) )
|
43
|
+
assert_same( yahtzee, yahtzee.use_category( "Fives", [ 0, 5, 10,
|
44
|
+
15, 20, 25 ] ) )
|
45
|
+
assert_same( yahtzee, yahtzee.use_category( "Sixes", [ 0, 6, 12,
|
46
|
+
18, 24, 30 ] ) )
|
47
|
+
assert_same(yahtzee, yahtzee.use_category("Three of a Kind", 0, 30))
|
48
|
+
assert_same(yahtzee, yahtzee.use_category("Four of a Kind", 0, 30))
|
49
|
+
assert_same(yahtzee, yahtzee.use_category("Full House", [0, 25]))
|
50
|
+
assert_same(yahtzee, yahtzee.use_category("Small Straight", [0, 30]))
|
51
|
+
assert_same(yahtzee, yahtzee.use_category("Large Straight", [0, 40]))
|
52
|
+
assert_same( yahtzee,
|
53
|
+
yahtzee.use_category(
|
54
|
+
"Yahtzee"
|
55
|
+
) { |n| n == 0 or n == 50 or (n - 50) % 100 == 0 } )
|
56
|
+
assert_same(yahtzee, yahtzee.use_category("Chance", 0, 36))
|
57
|
+
assert_same(yahtzee, yahtzee.require_categories)
|
58
|
+
|
59
|
+
# totaling
|
60
|
+
assert_same( yahtzee,
|
61
|
+
yahtzee.set_total( "Bonus", *%w{ Ones Twos Threes
|
62
|
+
Fours Fives Sixes }
|
63
|
+
) { |n| if n >= 63 then 35 else 0 end } )
|
64
|
+
assert_same( yahtzee, yahtzee.set_total( "Upper", *%w{ Ones Twos
|
65
|
+
Threes Fours
|
66
|
+
Fives Sixes
|
67
|
+
Bonus } ) )
|
68
|
+
assert_same( yahtzee, yahtzee.set_total( "Lower", "Three of a Kind",
|
69
|
+
"Four of a Kind",
|
70
|
+
"Full House",
|
71
|
+
"Small Straight",
|
72
|
+
"Large Straight",
|
73
|
+
"Yahtzee",
|
74
|
+
"Chance" ) )
|
75
|
+
assert_same(yahtzee, yahtzee.set_total("Overall", *%w{Upper Lower}))
|
76
|
+
assert_same(yahtzee, yahtzee.set_win("Overall"))
|
77
|
+
|
78
|
+
# usage
|
79
|
+
assert_raise(ArgumentError) { yahtzee.score("James", 10) }
|
80
|
+
assert_raise(ArgumentError) { yahtzee.score("James", 10, "Overall") }
|
81
|
+
assert_raise(ArgumentError) { yahtzee.score("James", 10, "Ones") }
|
82
|
+
assert_equal(3, yahtzee.score("James", 3, "Ones"))
|
83
|
+
assert_equal(3, yahtzee.total("James", "Ones"))
|
84
|
+
assert_equal(3, yahtzee.total("James", "Upper"))
|
85
|
+
assert_equal(3, yahtzee.total("James", "Overall"))
|
86
|
+
assert_equal(0, yahtzee.total("James", "Bonus"))
|
87
|
+
assert_equal(0, yahtzee.total("James", "Lower"))
|
88
|
+
assert_equal(4, yahtzee.score("James", 4, "Twos"))
|
89
|
+
assert_equal(0, yahtzee.total("James", "Bonus"))
|
90
|
+
assert_equal(7, yahtzee.total("James", "Upper"))
|
91
|
+
assert_equal(9, yahtzee.score("James", 9, "Threes"))
|
92
|
+
assert_equal(0, yahtzee.total("James", "Bonus"))
|
93
|
+
assert_equal(16, yahtzee.total("James", "Upper"))
|
94
|
+
assert_equal(8, yahtzee.score("James", 8, "Fours"))
|
95
|
+
assert_equal(0, yahtzee.total("James", "Bonus"))
|
96
|
+
assert_equal(24, yahtzee.total("James", "Upper"))
|
97
|
+
assert_equal(15, yahtzee.score("James", 15, "Fives"))
|
98
|
+
assert_equal(0, yahtzee.total("James", "Bonus"))
|
99
|
+
assert_equal(39, yahtzee.total("James", "Upper"))
|
100
|
+
assert_equal(24, yahtzee.score("James", 24, "Sixes"))
|
101
|
+
assert_equal(35, yahtzee.total("James", "Bonus"))
|
102
|
+
assert_equal(98, yahtzee.total("James", "Upper"))
|
103
|
+
assert_equal(25, yahtzee.score("James", 25, "Full House"))
|
104
|
+
assert_equal(25, yahtzee.total("James", "Lower"))
|
105
|
+
assert_equal(123, yahtzee.total("James", "Overall"))
|
106
|
+
assert_equal(50, yahtzee.score("Greg", 50, "Yahtzee"))
|
107
|
+
assert_equal(150, yahtzee.score("Greg", 100, "Yahtzee"))
|
108
|
+
assert_equal(25, yahtzee.score("Greg", 25, "Fives"))
|
109
|
+
assert_equal(175, yahtzee.total("Greg", "Overall"))
|
110
|
+
assert_equal("Greg", yahtzee.winner)
|
111
|
+
end
|
112
|
+
end
|
data/test/tc_views.rb
ADDED
@@ -0,0 +1,353 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
# tc_views.rb
|
4
|
+
#
|
5
|
+
# Created by James Edward Gray II on 2005-06-01.
|
6
|
+
# Copyright 2005 Gray Productions. All rights reserved.
|
7
|
+
|
8
|
+
require "test/unit"
|
9
|
+
|
10
|
+
require "gambit/viewable"
|
11
|
+
require "gambit/tools"
|
12
|
+
require "gambit/server/gambiterror"
|
13
|
+
|
14
|
+
class TestViews < Test::Unit::TestCase
|
15
|
+
class MyModel
|
16
|
+
include Gambit::Viewable
|
17
|
+
|
18
|
+
def initialize( )
|
19
|
+
@instance_variable = "Instance Variable"
|
20
|
+
end
|
21
|
+
|
22
|
+
def instance_method( )
|
23
|
+
"Instance Method"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_mixin
|
28
|
+
assert_not_nil(model = MyModel.new)
|
29
|
+
|
30
|
+
MyModel.register_view( :empty, "" )
|
31
|
+
assert_equal("", model.view(:empty))
|
32
|
+
assert_raise(ArgumentError) { model.view(:typo) }
|
33
|
+
|
34
|
+
assert_respond_to(model, :h)
|
35
|
+
assert_respond_to(model, :url_encode)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_erb_completion
|
39
|
+
assert_not_nil(model = MyModel.new)
|
40
|
+
MyModel.register_view( :ruby, "Countdown:\n" +
|
41
|
+
"<% 10.downto(1) do |num| %>\n" +
|
42
|
+
"\t<%= num %>...\n" +
|
43
|
+
"<% end %>\n" +
|
44
|
+
"NOW!!!" )
|
45
|
+
assert_equal( "Countdown:\n" +
|
46
|
+
"#{(1..10).to_a.reverse.map { |n| %Q{\t#{n}...\n} }}" +
|
47
|
+
"NOW!!!", model.view(:ruby))
|
48
|
+
|
49
|
+
MyModel.register_view( :shortcut, "Countdown:\n" +
|
50
|
+
"% 10.downto(1) do |num|\n" +
|
51
|
+
"\t<%= num %>...\n" +
|
52
|
+
"% end\n" +
|
53
|
+
"NOW!!!" )
|
54
|
+
assert_equal( "Countdown:\n" +
|
55
|
+
"#{(1..10).to_a.reverse.map { |n| %Q{\t#{n}...\n} }}" +
|
56
|
+
"NOW!!!", model.view(:shortcut))
|
57
|
+
|
58
|
+
MyModel.register_view( :data, "<%= @instance_variable %> and " +
|
59
|
+
"<%= instance_method %>" )
|
60
|
+
assert_equal("Instance Variable and Instance Method", model.view(:data))
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_view_files
|
64
|
+
assert_not_nil(model = MyModel.new)
|
65
|
+
MyModel.register_view( :file,
|
66
|
+
"file:#{File.join(File.dirname(__FILE__), 'test_view.rhtml')}" )
|
67
|
+
MyModel.register_view(:junk_file, "file:DOESN'T_EXIST")
|
68
|
+
assert_equal( "Var: Instance Variable\nMeth: Instance Method\n",
|
69
|
+
model.view(:file) )
|
70
|
+
assert_raise(Gambit::Server::GambitError) { model.view(:junk_file) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_dice
|
74
|
+
roll = 3.d(6)
|
75
|
+
str = roll.to_a.join(", ")
|
76
|
+
str[str.rindex(","), 1] = " and"
|
77
|
+
|
78
|
+
assert_equal( "<ul class=\"dice\">\n" +
|
79
|
+
roll.map { |die| "\t<li>#{die}</li>\n" }.join +
|
80
|
+
"</ul>\n", roll.view(:gambit_html) )
|
81
|
+
assert_equal(str, roll.view(:gambit_text))
|
82
|
+
|
83
|
+
roll = 2.d(6)
|
84
|
+
|
85
|
+
assert_equal( "<ul class=\"dice\">\n" +
|
86
|
+
roll.map { |die| "\t<li>#{die}</li>\n" }.join +
|
87
|
+
"</ul>\n", roll.view(:gambit_html) )
|
88
|
+
assert_equal("#{roll[0]} and #{roll[1]}", roll.view(:gambit_text))
|
89
|
+
|
90
|
+
roll = 1.d(6)
|
91
|
+
|
92
|
+
assert_equal( "<ul class=\"dice\">\n" +
|
93
|
+
"\t<li>#{roll[0]}</li>\n" +
|
94
|
+
"</ul>\n", roll.view(:gambit_html) )
|
95
|
+
assert_equal("a #{roll[0]}", roll.view(:gambit_text))
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_board
|
99
|
+
board = Gambit::Tools::Board.new(2, 2)
|
100
|
+
board["a1"] = "James"
|
101
|
+
board["b1"] = "Dana"
|
102
|
+
board["a2"] = "Greg"
|
103
|
+
board["b2"] = "Bozo the Clown"
|
104
|
+
assert_equal( "<table class=\"board\">\n" +
|
105
|
+
"<tr id=\"row2\">\n" +
|
106
|
+
"\t<td id=\"a2\">Greg</td>\n" +
|
107
|
+
"\t<td id=\"b2\">Bozo the Clown</td>\n" +
|
108
|
+
"</tr><tr id=\"row1\">\n" +
|
109
|
+
"\t<td id=\"a1\">James</td>\n" +
|
110
|
+
"\t<td id=\"b1\">Dana</td>\n" +
|
111
|
+
"</tr>\n" +
|
112
|
+
"</table>\n", board.view(:gambit_html) )
|
113
|
+
assert_equal( " Greg Bozo the Clown\n" +
|
114
|
+
"James Dana\n", board.view(:gambit_text) )
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_cards
|
118
|
+
card = Gambit::Tools::Cards::StandardCard.new(:ace, :spades)
|
119
|
+
assert_equal( "<dl class=\"card\">\n" +
|
120
|
+
"\t<dt>Value:</dt>\n" +
|
121
|
+
"\t<dd>ace</dd>\n" +
|
122
|
+
"\t\n" +
|
123
|
+
"\t<dt>Suit:</dt>\n" +
|
124
|
+
"\t<dd>spades</dd>\n" +
|
125
|
+
"</dl>\n", card.view(:gambit_html) )
|
126
|
+
assert_equal("The Ace of Spades", card.view(:gambit_text))
|
127
|
+
|
128
|
+
deck = Gambit::Tools::Cards::Deck.new
|
129
|
+
assert_equal( "<ol class=\"deck\">\n" +
|
130
|
+
deck.to_a.map { |c| "\t<li>#{c.name}</li>\n" }.join +
|
131
|
+
"</ol>\n", deck.view(:gambit_html) )
|
132
|
+
assert_equal( deck.to_a.map { |c| "#{c.name}\n" }.join,
|
133
|
+
deck.view(:gambit_text) )
|
134
|
+
|
135
|
+
hand = Gambit::Tools::Cards::Hand.new
|
136
|
+
hand << Gambit::Tools::Cards::StandardCard.new(:ace, :spades) <<
|
137
|
+
Gambit::Tools::Cards::StandardCard.new(:joker, :red) <<
|
138
|
+
Gambit::Tools::Cards::StandardCard.new(3, :clubs)
|
139
|
+
assert_equal( "<ol class=\"hand\">\n" +
|
140
|
+
"\t<li>The Ace of Spades</li>\n" +
|
141
|
+
"\t<li>The Red Joker</li>\n" +
|
142
|
+
"\t<li>The 3 of Clubs</li>\n" +
|
143
|
+
"</ol>\n",
|
144
|
+
hand.view(:gambit_html) )
|
145
|
+
assert_equal( "The Ace of Spades, The Red Joker and The 3 of Clubs",
|
146
|
+
hand.view(:gambit_text) )
|
147
|
+
|
148
|
+
pile = Gambit::Tools::Cards::Pile.new
|
149
|
+
pile << Gambit::Tools::Cards::StandardCard.new(:ace, :spades) <<
|
150
|
+
Gambit::Tools::Cards::StandardCard.new(:joker, :red) <<
|
151
|
+
Gambit::Tools::Cards::StandardCard.new(3, :clubs)
|
152
|
+
pile.face_up = lambda { |index| index != 0 }
|
153
|
+
assert_equal( "<ol class=\"pile\">\n" +
|
154
|
+
"\t<li>A Face-down Card</li>\n" +
|
155
|
+
"\t<li>The Red Joker</li>\n" +
|
156
|
+
"\t<li>The Ace of Spades</li>\n" +
|
157
|
+
"</ol>\n", pile.view(:gambit_html) )
|
158
|
+
assert_equal( "The Red Joker and The Ace of Spades",
|
159
|
+
pile.view(:gambit_text) )
|
160
|
+
end
|
161
|
+
|
162
|
+
def test_movehistory
|
163
|
+
hist = Gambit::Tools::MoveHistory.new("James", "Greg")
|
164
|
+
hist << "e4" << "e5" << "f4"
|
165
|
+
assert_equal( "<table class=\"movehistory\">\n" +
|
166
|
+
"<tr>\n" +
|
167
|
+
"\t<th> </th>\n" +
|
168
|
+
"\t<th id=\"James\">James</th>\n" +
|
169
|
+
"\t<th id=\"Greg\">Greg</th>\n" +
|
170
|
+
"</tr><tr class=\"odd\">\n" +
|
171
|
+
"\t<td class=\"turn\">1</td>\n" +
|
172
|
+
"\t<td id=\"James1\">e4</td>\n" +
|
173
|
+
"\t<td id=\"Greg1\">e5</td>\n" +
|
174
|
+
"</tr><tr class=\"even\">\n" +
|
175
|
+
"\t<td class=\"turn\">2</td>\n" +
|
176
|
+
"\t<td id=\"James2\">f4</td>\n" +
|
177
|
+
"\t<td id=\"Greg2\"> </td>\n" +
|
178
|
+
"</tr>\n" +
|
179
|
+
"</table>\n", hist.view(:gambit_html) )
|
180
|
+
assert_equal( " James Greg \n" +
|
181
|
+
"1: e4 e5 \n" +
|
182
|
+
"2: f4 \n", hist.view(:gambit_text) )
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_currency
|
186
|
+
Gambit::Tools::Currency[:gold] = 1
|
187
|
+
Gambit::Tools::Currency[:silver] = 0.5
|
188
|
+
Gambit::Tools::Currency[:copper] = 2
|
189
|
+
|
190
|
+
cur = Gambit::Tools::Currency.new
|
191
|
+
cur.deposit(150, :gold)
|
192
|
+
cur.deposit(75, :silver)
|
193
|
+
cur.deposit(25, :copper)
|
194
|
+
assert_equal( "<dl class=\"currency\">\n" +
|
195
|
+
"\t<dt>Copper</dt>\n" +
|
196
|
+
"\t<dd>25</dd>\n" +
|
197
|
+
"\t\n" +
|
198
|
+
"\t<dt>Gold</dt>\n" +
|
199
|
+
"\t<dd>150</dd>\n" +
|
200
|
+
"\t\n" +
|
201
|
+
"\t<dt>Silver</dt>\n" +
|
202
|
+
"\t<dd>75</dd>\n" +
|
203
|
+
"</dl>\n", cur.view(:gambit_html) )
|
204
|
+
assert_equal( "Copper: 25\n" +
|
205
|
+
" Gold: 150\n" +
|
206
|
+
"Silver: 75\n", cur.view(:gambit_text) )
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_scorecard
|
210
|
+
yahtzee = Gambit::Tools::Scorecard.new("James", "Greg")
|
211
|
+
yahtzee.use_category("Ones", 0, 6)
|
212
|
+
yahtzee.use_category("Twos", [0, 2, 4, 6, 8, 10])
|
213
|
+
yahtzee.use_category("Threes", [ 0, 3, 6, 9, 12, 15 ])
|
214
|
+
yahtzee.use_category("Fours", [ 0, 4, 8, 12, 16, 20 ])
|
215
|
+
yahtzee.use_category("Fives", [ 0, 5, 10, 15, 20, 25 ])
|
216
|
+
yahtzee.use_category("Sixes", [ 0, 6, 12, 18, 24, 30 ])
|
217
|
+
|
218
|
+
yahtzee.set_total( "Bonus", *%w{ Ones Twos Threes
|
219
|
+
Fours Fives Sixes } ) do |n|
|
220
|
+
if n >= 63 then 35 else 0 end
|
221
|
+
end
|
222
|
+
yahtzee.set_total( "Upper",
|
223
|
+
*%w{Ones Twos Threes Fours Fives Sixes Bonus} )
|
224
|
+
|
225
|
+
yahtzee.use_category("Three of a Kind", 0, 30)
|
226
|
+
yahtzee.use_category("Four of a Kind", 0, 30)
|
227
|
+
yahtzee.use_category("Full House", [0, 25])
|
228
|
+
yahtzee.use_category("Small Straight", [0, 30])
|
229
|
+
yahtzee.use_category("Large Straight", [0, 40])
|
230
|
+
yahtzee.use_category("Yahtzee") do |n|
|
231
|
+
n == 0 or n == 50 or (n - 50) % 100 == 0
|
232
|
+
end
|
233
|
+
yahtzee.use_category("Chance", 0, 36)
|
234
|
+
yahtzee.require_categories
|
235
|
+
|
236
|
+
yahtzee.set_total( "Lower", "Three of a Kind", "Four of a Kind",
|
237
|
+
"Full House", "Small Straight", "Large Straight",
|
238
|
+
"Yahtzee", "Chance" )
|
239
|
+
yahtzee.set_total("Overall", *%w{Upper Lower})
|
240
|
+
yahtzee.set_win("Overall")
|
241
|
+
|
242
|
+
yahtzee.score("James", 3, "Ones")
|
243
|
+
yahtzee.score("James", 4, "Twos")
|
244
|
+
yahtzee.score("James", 9, "Threes")
|
245
|
+
yahtzee.score("James", 8, "Fours")
|
246
|
+
yahtzee.score("James", 15, "Fives")
|
247
|
+
yahtzee.score("James", 24, "Sixes")
|
248
|
+
yahtzee.score("James", 25, "Full House")
|
249
|
+
yahtzee.score("Greg", 50, "Yahtzee")
|
250
|
+
yahtzee.score("Greg", 100, "Yahtzee")
|
251
|
+
yahtzee.score("Greg", 25, "Fives")
|
252
|
+
|
253
|
+
assert_equal( "<table class=\"scorecard\">\n" +
|
254
|
+
"<tr>\n" +
|
255
|
+
"\t<th> </th>\n" +
|
256
|
+
"\t<th id=\"James\">James</th>\n" +
|
257
|
+
"\t<th id=\"Greg\">Greg</th>\n" +
|
258
|
+
"</tr><tr class=\"odd\">\n" +
|
259
|
+
"\t<td class=\"category\">Ones</td>\n" +
|
260
|
+
"\t<td id=\"James--Ones\">3</td>\n" +
|
261
|
+
"\t<td id=\"Greg--Ones\">0</td>\n" +
|
262
|
+
"</tr><tr class=\"even\">\n" +
|
263
|
+
"\t<td class=\"category\">Twos</td>\n" +
|
264
|
+
"\t<td id=\"James--Twos\">4</td>\n" +
|
265
|
+
"\t<td id=\"Greg--Twos\">0</td>\n" +
|
266
|
+
"</tr><tr class=\"odd\">\n" +
|
267
|
+
"\t<td class=\"category\">Threes</td>\n" +
|
268
|
+
"\t<td id=\"James--Threes\">9</td>\n" +
|
269
|
+
"\t<td id=\"Greg--Threes\">0</td>\n" +
|
270
|
+
"</tr><tr class=\"even\">\n" +
|
271
|
+
"\t<td class=\"category\">Fours</td>\n" +
|
272
|
+
"\t<td id=\"James--Fours\">8</td>\n" +
|
273
|
+
"\t<td id=\"Greg--Fours\">0</td>\n" +
|
274
|
+
"</tr><tr class=\"odd\">\n" +
|
275
|
+
"\t<td class=\"category\">Fives</td>\n" +
|
276
|
+
"\t<td id=\"James--Fives\">15</td>\n" +
|
277
|
+
"\t<td id=\"Greg--Fives\">25</td>\n" +
|
278
|
+
"</tr><tr class=\"even\">\n" +
|
279
|
+
"\t<td class=\"category\">Sixes</td>\n" +
|
280
|
+
"\t<td id=\"James--Sixes\">24</td>\n" +
|
281
|
+
"\t<td id=\"Greg--Sixes\">0</td>\n" +
|
282
|
+
"</tr><tr class=\"odd\">\n" +
|
283
|
+
"\t<td class=\"category\">Bonus</td>\n" +
|
284
|
+
"\t<td id=\"James--Bonus\">35</td>\n" +
|
285
|
+
"\t<td id=\"Greg--Bonus\">0</td>\n" +
|
286
|
+
"</tr><tr class=\"even\">\n" +
|
287
|
+
"\t<td class=\"category\">Upper</td>\n" +
|
288
|
+
"\t<td id=\"James--Upper\">98</td>\n" +
|
289
|
+
"\t<td id=\"Greg--Upper\">25</td>\n" +
|
290
|
+
"</tr><tr class=\"odd\">\n" +
|
291
|
+
"\t<td class=\"category\">Three of a Kind</td>\n" +
|
292
|
+
"\t<td id=\"James--Three of a Kind\">0</td>\n" +
|
293
|
+
"\t<td id=\"Greg--Three of a Kind\">0</td>\n" +
|
294
|
+
"</tr><tr class=\"even\">\n" +
|
295
|
+
"\t<td class=\"category\">Four of a Kind</td>\n" +
|
296
|
+
"\t<td id=\"James--Four of a Kind\">0</td>\n" +
|
297
|
+
"\t<td id=\"Greg--Four of a Kind\">0</td>\n" +
|
298
|
+
"</tr><tr class=\"odd\">\n" +
|
299
|
+
"\t<td class=\"category\">Full House</td>\n" +
|
300
|
+
"\t<td id=\"James--Full House\">25</td>\n" +
|
301
|
+
"\t<td id=\"Greg--Full House\">0</td>\n" +
|
302
|
+
"</tr><tr class=\"even\">\n" +
|
303
|
+
"\t<td class=\"category\">Small Straight</td>\n" +
|
304
|
+
"\t<td id=\"James--Small Straight\">0</td>\n" +
|
305
|
+
"\t<td id=\"Greg--Small Straight\">0</td>\n" +
|
306
|
+
"</tr><tr class=\"odd\">\n" +
|
307
|
+
"\t<td class=\"category\">Large Straight</td>\n" +
|
308
|
+
"\t<td id=\"James--Large Straight\">0</td>\n" +
|
309
|
+
"\t<td id=\"Greg--Large Straight\">0</td>\n" +
|
310
|
+
"</tr><tr class=\"even\">\n" +
|
311
|
+
"\t<td class=\"category\">Yahtzee</td>\n" +
|
312
|
+
"\t<td id=\"James--Yahtzee\">0</td>\n" +
|
313
|
+
"\t<td id=\"Greg--Yahtzee\">150</td>\n" +
|
314
|
+
"</tr><tr class=\"odd\">\n" +
|
315
|
+
"\t<td class=\"category\">Chance</td>\n" +
|
316
|
+
"\t<td id=\"James--Chance\">0</td>\n" +
|
317
|
+
"\t<td id=\"Greg--Chance\">0</td>\n" +
|
318
|
+
"</tr><tr class=\"even\">\n" +
|
319
|
+
"\t<td class=\"category\">Lower</td>\n" +
|
320
|
+
"\t<td id=\"James--Lower\">25</td>\n" +
|
321
|
+
"\t<td id=\"Greg--Lower\">150</td>\n" +
|
322
|
+
"</tr><tr class=\"odd\">\n" +
|
323
|
+
"\t<td class=\"category\">Overall</td>\n" +
|
324
|
+
"\t<td id=\"James--Overall\">123</td>\n" +
|
325
|
+
"\t<td id=\"Greg--Overall\">175</td>\n" +
|
326
|
+
"</tr>\n" +
|
327
|
+
"</table>\n", yahtzee.view(:gambit_html) )
|
328
|
+
assert_equal( " James Greg \n" +
|
329
|
+
" Ones: 3 0 \n" +
|
330
|
+
" Twos: 4 0 \n" +
|
331
|
+
" Threes: 9 0 \n" +
|
332
|
+
" Fours: 8 0 \n" +
|
333
|
+
" Fives: 15 25 \n" +
|
334
|
+
" Sixes: 24 0 \n" +
|
335
|
+
"--------------- ----- ----- \n" +
|
336
|
+
" Bonus: 35 0 \n" +
|
337
|
+
"--------------- ----- ----- \n" +
|
338
|
+
" Upper: 98 25 \n" +
|
339
|
+
"\n" +
|
340
|
+
"Three of a Kind: 0 0 \n" +
|
341
|
+
" Four of a Kind: 0 0 \n" +
|
342
|
+
" Full House: 25 0 \n" +
|
343
|
+
" Small Straight: 0 0 \n" +
|
344
|
+
" Large Straight: 0 0 \n" +
|
345
|
+
" Yahtzee: 0 150 \n" +
|
346
|
+
" Chance: 0 0 \n" +
|
347
|
+
"--------------- ----- ----- \n" +
|
348
|
+
" Lower: 25 150 \n" +
|
349
|
+
"--------------- ----- ----- \n" +
|
350
|
+
" Overall: 123 175 \n",
|
351
|
+
yahtzee.view(:gambit_text) )
|
352
|
+
end
|
353
|
+
end
|