[#129195] Is compatibility important for us? — Esteban Manchado Vel痙quez <zoso@...>

Hi all,

28 messages 2005/02/01
[#129199] Re: Is compatibility important for us? — James Britt <jamesUNDERBARb@...> 2005/02/01

Esteban Manchado Vel痙quez wrote:

[#129204] Re: Is compatibility important for us? — Francis Hwang <sera@...> 2005/02/01

[#129207] Re: Is compatibility important for us? — Eric Hodel <drbrain@...7.net> 2005/02/01

On 31 Jan 2005, at 18:21, Francis Hwang wrote:

[#129209] Re: Is compatibility important for us? — Francis Hwang <sera@...> 2005/02/01

[#129214] Re: Is compatibility important for us? — "Trans" <transfire@...> 2005/02/01

Francis,

[#129216] Re: Is compatibility important for us? — Francis Hwang <sera@...> 2005/02/01

[#129698] Re: Is compatibility important for us? — Esteban Manchado Vel痙quez <zoso@...> 2005/02/04

I had this on "postponed", and I just realized. Sorry.

[#129718] Re: Is compatibility important for us? — James Britt <jamesUNDERBARb@...> 2005/02/05

Esteban Manchado Vel痙quez wrote:

[#129808] Re: Is compatibility important for us? — Esteban Manchado Vel痙quez <zoso@...> 2005/02/05

On Sat, Feb 05, 2005 at 10:29:11AM +0900, James Britt wrote:

[#129218] Partial function application (was: Re: Binding precedence for first sym...) — E S <eero.saynatkari@...>

Trans wrote:

13 messages 2005/02/01
[#129220] Re: Partial function application (was: Re: Binding precedence for first sym...) — "Trans" <transfire@...> 2005/02/01

[#129289] Newbie: How to delete a Rails app (Windows) — peter.cutting@...

Hi

25 messages 2005/02/01
[#129362] Re: Newbie: How to delete a Rails app (Windows) — Douglas Livingstone <rampant@...> 2005/02/02

> but how do I delete? (If I just delete then I get a permissions

[#129373] Re: Newbie: How to delete a Rails app (Windows) — Caio Tiago Oliveira <caiot1@...> 2005/02/02

Douglas Livingstone, 2/2/2005 06:04:

[#129380] Re: Newbie: How to delete a Rails app (Windows) — peter.cutting@... 2005/02/02

yes the switching off may have helped (will try logging off next time

[#129385] Nuby needs an intro to testing for Win 2K — Barry Sperling <barry@...> 2005/02/02

[#129293] Re: [QUIZ] To Excel (#17) — "Graham Foster" <graham@...>

> Years ago, on a job developing custom reporting software, this was

15 messages 2005/02/01

[#129316] Wee 0.7.0 + Tutorial Videos — Michael Neumann <mneumann@...>

Hi,

27 messages 2005/02/01
[#129449] Re: Wee 0.7.0 + Tutorial Videos — itsme213@... 2005/02/03

Michael, I may be doing something wrong, but none of the MPEGs worked

[#129345] ANN: ParseTree 1.3.3 and ruby2c 1.0.0 beta 1 — Ryan Davis <ryand-ruby@...>

Actual announcements are on http://blog.zenspider.com/

24 messages 2005/02/02

[#129351] yarv and dbi — jm <jeffm@...>

Anyone out there tried dbi with yarv

18 messages 2005/02/02
[#129358] Re: yarv and dbi — SASADA Koichi <ko1@...> 2005/02/02

jm <jeffm@ghostgun.com> wrote :

[#129451] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...>

"

90 messages 2005/02/03
[#130693] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/13

Ilias Lazaridis wrote:

[#130749] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Douglas Livingstone <rampant@...> 2005/02/14

> From the communities behaviour, I extract the following answer:

[#130784] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/14

Douglas Livingstone wrote:

[#130785] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Luke Graham <spoooq@...> 2005/02/14

From the link - "fictive technology collection". Ive worked on some of

[#130786] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Luke Graham <spoooq@...> 2005/02/14

Some of it is possible. I have created persistent Ruby objects, for

[#130823] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Austin Ziegler <halostatue@...> 2005/02/14

On Mon, 14 Feb 2005 17:49:18 +0900, Luke Graham <spoooq@gmail.com> wrote:

[#130856] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/14

Austin Ziegler wrote:

[#130871] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Austin Ziegler <halostatue@...> 2005/02/14

On Tue, 15 Feb 2005 04:09:54 +0900, Ilias Lazaridis

[#131021] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/15

Austin Ziegler wrote:

[#131025] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Thomas E Enebo <enebo@...> 2005/02/15

On Wed, 16 Feb 2005, Ilias Lazaridis defenestrated me:

[#131031] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/15

Thomas E Enebo wrote:

[#131036] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Thomas E Enebo <enebo@...> 2005/02/15

On Wed, 16 Feb 2005, Ilias Lazaridis defenestrated me:

[#131039] Re: [EVALUATION] - E01: The Java Failure - May Ruby Helps? — Ilias Lazaridis <ilias@...> 2005/02/15

Thomas E Enebo wrote:

[#129452] RedCloth 3.0.2 -- Please, oh please, let this be the one — why the lucky stiff <ruby-talk@...>

Okay, okay. The tumblers are clicking, the clouds are parting.

15 messages 2005/02/03

[#129554] lack of reaction to latest ruby implementations — Alexander Kellett <ruby-lists@...>

working on alternatives for the ruby runtime has

37 messages 2005/02/03

[#129686] iteration the ruby way — Navindra Umanee <navindra@...>

Hi,

18 messages 2005/02/04

[#129726] Ruby for closed source projects — Michael Gebhart <mail@...>

Hi,

16 messages 2005/02/05

[#129778] Korundum: error when overriding a KDE::RootPixmap method — Martin Traverso <martin@...>

Hi,

15 messages 2005/02/05

[#129831] Benchmark Mono - Ruby — Michael Gebhart <mail@...>

Hi,

21 messages 2005/02/06

[#129878] Ruby Interactive Shell — "Jenjhiz" <jenjhiz@...>

Hello,

18 messages 2005/02/06

[#129959] delayed string interpolation — Navindra Umanee <navindra@...>

Hi,

14 messages 2005/02/07

[#130044] web testing with Ruby — Jason Sweat <jason.sweat@...>

Does anyone have suggestions for projects/libraries to web test code

12 messages 2005/02/07

[#130068] Grid computing with Ruby? — Alexander Staubo <alex@...>

I have an interest in distributed computing and so-called grid

11 messages 2005/02/08

[#130090] Squeak like environment for Ruby — Logan Capaldo <logancapaldo@...>

Lately I've been playing around with Squeak (http://www.squeak.org/),

20 messages 2005/02/08
[#130091] Re: Squeak like environment for Ruby — Caio Tiago Oliveira <caiot1@...> 2005/02/08

Logan Capaldo, 8/2/2005 00:45:

[#130108] Re: Squeak like environment for Ruby — Alexander Kellett <ruby-lists@...> 2005/02/08

On Feb 8, 2005, at 4:59 AM, Caio Tiago Oliveira wrote:

[#130102] Syck 0.50 -- The new YAML is here for testing — why the lucky stiff <ruby-talk@...>

Finally, I can go back to drawing ponies out on the bridge by the old

13 messages 2005/02/08

[#130180] Ruby users in India? — Premshree Pillai <premshree.pillai@...>

Hi,

20 messages 2005/02/08

[#130280] How to mimic Perl's `s///' in Ruby? — Jos Backus <jos@...>

Given Perl's

18 messages 2005/02/09

[#130305] Phone number to words — Jordi Bunster <jordi@...>

Does anyone have one of those algorithms that convert a phone number to

13 messages 2005/02/10

[#130327] Building a Better Functor — "John W. Long" <ng@...>

Hi,

29 messages 2005/02/10

[#130399] A Ruby-relevant quote from Alan Kay — "Curt Hibbs" <curt@...>

ACM Queue just published an interview with Alan Kay (the creator of

27 messages 2005/02/10
[#130400] Re: A Ruby-relevant quote from Alan Kay — PA <petite.abeille@...> 2005/02/10

[#130408] Re: A Ruby-relevant quote from Alan Kay — Douglas Livingstone <rampant@...> 2005/02/10

> Steve Wart about "why Smalltalk never caught on":

[#130573] utilizing ++ and -- for comments — "Pe, Botp" <botp@...>

Since ++ and -- wont see the light of day in ruby, can we use it for comment

27 messages 2005/02/12
[#130587] Re: utilizing ++ and -- for comments — "George Moschovitis" <george.moschovitis@...> 2005/02/12

I also think that the =begin, =end notation is not comfortable to use.

[#130595] Re: utilizing ++ and -- for comments — Douglas Livingstone <rampant@...> 2005/02/12

> for example /* */

[#130707] Printing why's (poignant) guide to ruby — Richard Dale <Richard_Dale@...>

I'd like to try ruby on non-programmers teaching them using why's amazing

62 messages 2005/02/13
[#130714] Re: Printing why's (poignant) guide to ruby — Navindra Umanee <navindra@...> 2005/02/13

Richard Dale <Richard_Dale@tipitina.demon.co.uk> wrote:

[#130716] Re: Printing why's (poignant) guide to ruby — Alexander Kellett <ruby-lists@...> 2005/02/13

i'm really puzzled by this.

[#130731] Re: Printing why's (poignant) guide to ruby — Navindra Umanee <navindra@...> 2005/02/13

Alexander Kellett <ruby-lists@lypanov.net> wrote:

[#130843] Re: Printing why's (poignant) guide to ruby — Marcus Sharp <brothermarcus@...> 2005/02/14

*putting on flame retardant pants*

[#130715] Ruby on Windows: debugger questions and comments — umptious@... (JC)

'm evaluating scripting languages for a client. Ruby as a language

28 messages 2005/02/13

[#130742] (OT) Programmer's editors for the Mac — Timothy Hunter <cyclists@...>

Just got a new Powerbook, so I'm looking for suggestions for a good

43 messages 2005/02/14

[#130975] Is this old style Ruby? — centrepins@...

In Why's guide, I see the line:

30 messages 2005/02/15
[#130980] Re: Is this old style Ruby? — Jeremy Tregunna <jtregunna@...> 2005/02/15

[#130982] Re: Is this old style Ruby? — Nikolai Weibull <mailing-lists.ruby-talk@...> 2005/02/15

* Jeremy Tregunna (Feb 15, 2005 15:10):

[#130986] Re: Is this old style Ruby? — centrepins@... 2005/02/15

Page 349 of the (printed) pickaxe2 mentions '::' and '.', but doesn't

[#130988] Re: Is this old style Ruby? — "David A. Black" <dblack@...> 2005/02/15

Hi --

[#131103] Wee web-framework. It's great! — Joao Pedrosa <joaopedrosa@...>

Hi,

21 messages 2005/02/16
[#131111] Re: Wee web-framework. It's great! — "Vincent Foley" <vfoley@...> 2005/02/16

You know, I think Wee could become really hot if someone could mix it

[#131127] adding a dynamic method handler? (long post) — Mark Hubbart <discordantus@...>

Hi,

12 messages 2005/02/16

[#131132] Ruby + end user applications — "martinus" <martin.ankerl@...>

Ruby definitely needs more cool, simple to use, end user applications.

16 messages 2005/02/16

[#131168] FileSystem 0.1.0: Beta for me, Alpha for you — Francis Hwang <sera@...>

Greetings!

23 messages 2005/02/16

[#131252] Where is Ruby headed etc. — centrepins@... (Glenn)

A few musings/questions/dribble from an excited newbie. And my first

21 messages 2005/02/16
[#131256] Re: Where is Ruby headed etc. — Ben Giddings <bg-rubytalk@...> 2005/02/16

Glenn wrote:

[#131283] Re: Where is Ruby headed etc. — Brian McCallister <brianm@...> 2005/02/17

[#131286] Re: Where is Ruby headed etc. — Yukihiro Matsumoto <matz@...> 2005/02/17

Hi,

[#131275] installed ruby on linux without su access — Eko Budi Setiyo <contact_us@...>

Hi all,

17 messages 2005/02/17

[#131284] Ruby Visual Identity Team — "John W. Long" <ng@...>

Recently I've seen a couple of people mention how much they would like

43 messages 2005/02/17
[#131288] Re: Ruby Visual Identity Team — James Britt <jamesUNDERBARb@...> 2005/02/17

John W. Long wrote:

[#131307] Re: Ruby Visual Identity Team — gabriele renzi <rff_rff@...> 2005/02/17

James Britt ha scritto:

[#131404] - E02 - Nitro, a Ruby Based WebFramework — Ilias Lazaridis <ilias@...>

50 messages 2005/02/17
[#131445] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Aredridel <aredridel@...> 2005/02/17

>

[#131490] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Luke Graham <spoooq@...> 2005/02/18

Wow, I actually predicted this post in another thread. Nitro vs ruby is clearly

[#131494] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Alexander Kellett <ruby-lists@...> 2005/02/18

not too sure to be honest.

[#131496] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Alexander Kellett <ruby-lists@...> 2005/02/18

i take this back i read some of the various

[#131506] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Bill Guindon <agorilla@...> 2005/02/18

On Fri, 18 Feb 2005 11:30:49 +0900, Alexander Kellett

[#131592] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Christian Neukirchen <chneukirchen@...> 2005/02/18

Bill Guindon <agorilla@gmail.com> writes:

[#131605] Re: [EVALUATION] - E02 - Nitro, a Ruby Based WebFramework — Ilias Lazaridis <ilias@...> 2005/02/18

Christian Neukirchen wrote:

[#131422] ICFP Contest Dates Are Set — James Edward Gray II <james@...>

It's pretty early yet, but a lot of coders need time to plan and gather

13 messages 2005/02/17

[#131469] Virtual Ruby Group — Zach Dennis <zdennis@...>

Ok, I have a question for fellow rubyists, rubyiers, etc... There seem

55 messages 2005/02/17
[#131906] Re: Virtual Ruby Group — Zach Dennis <zdennis@...> 2005/02/21

It looks like there are a few folks interested in the Virtual Ruby Group

[#131921] Re: Virtual Ruby Group — "Curt Hibbs" <curt@...> 2005/02/21

One more suggestion: you could make a FreeRIDE plugin out of jabber4r, and

[#131942] Re: Virtual Ruby Group — Tanner Burson <tanner.burson@...> 2005/02/21

On Mon, 21 Feb 2005 21:02:19 +0900, Curt Hibbs <curt@hibbs.com> wrote:

[#131946] Re: Virtual Ruby Group — Bill Guindon <agorilla@...> 2005/02/21

On Tue, 22 Feb 2005 00:41:36 +0900, Tanner Burson

[#132114] Re: Virtual Ruby Group — Zach Dennis <zdennis@...> 2005/02/23

Bill Guindon wrote:

[#131499] pulling my hair out, why won't Kernel.sleep(0) sleep? — Sam Roberts <sroberts@...>

Can anybody give me any hints as to what I should be looking for? What

17 messages 2005/02/18

[#131545] Require when Executed file is required by another file. — "Zev Blut" <rubyzbibd@...>

Hello,

11 messages 2005/02/18

[#131563] 1-800-THE-QUIZ (#20) — Ruby Quiz <james@...>

The three rules of Ruby Quiz:

12 messages 2005/02/18

[#131635] Rails presentation — Jamis Buck <jamis_buck@...>

So I gave a presentation on Rails to the Utah Java Users Group last

14 messages 2005/02/18

[#131685] FXIrb 0.14 - a Win32 GUI wrapper around IRB — Martin DeMello <martindemello@...>

- What?

19 messages 2005/02/18

[#131753] Array#join non string arguments — Simon Strandgaard <neoneye@...>

A proposal:

15 messages 2005/02/19

[#131808] destructive! operations — Navindra Umanee <navindra@...>

Hi,

58 messages 2005/02/20
[#131847] Re: destructive! operations — "Robert Klemme" <bob.news@...> 2005/02/20

[#131852] Re: destructive! operations — Caio Tiago Oliveira <caiot1@...> 2005/02/20

Robert Klemme, 20/2/2005 12:04:

[#131859] Re: destructive! operations — James Edward Gray II <james@...> 2005/02/20

On Feb 20, 2005, at 10:23 AM, Caio Tiago Oliveira wrote:

[#131880] Re: destructive! operations — Navindra Umanee <navindra@...> 2005/02/20

James Edward Gray II <james@grayproductions.net> wrote:

[#131929] Re: destructive! operations — Austin Ziegler <halostatue@...> 2005/02/21

On Mon, 21 Feb 2005 06:07:58 +0900, Navindra Umanee

[#131939] Re: destructive! operations — "Bill Kelly" <billk@...> 2005/02/21

From: "Christian Neukirchen" <chneukirchen@gmail.com>

[#131943] Re: destructive! operations — Christian Neukirchen <chneukirchen@...> 2005/02/21

"Bill Kelly" <billk@cts.com> writes:

[#131958] Re: destructive! operations — Pit Capitain <pit@...> 2005/02/21

Christian Neukirchen schrieb:

[#131964] Re: destructive! operations — Christian Neukirchen <chneukirchen@...> 2005/02/21

Pit Capitain <pit@capitain.de> writes:

[#131969] Re: destructive! operations — Pit Capitain <pit@...> 2005/02/21

Christian Neukirchen schrieb:

[#131973] Re: destructive! operations — Christian Neukirchen <chneukirchen@...> 2005/02/21

Pit Capitain <pit@capitain.de> writes:

[#131985] Re: destructive! operations — "ES" <ruby-ml@...> 2005/02/21

On Mon, February 21, 2005 6:07 pm, Christian Neukirchen said:

[#131988] Re: destructive! operations — Pit Capitain <pit@...> 2005/02/21

ES schrieb:

[#131940] ANN: 2005 International Obfuscated Ruby Code Contest (IORCC) — Todd Nathan <iorcc@...>

Dear Fellow Rubists,

39 messages 2005/02/21
[#132095] Re: ANN: 2005 International Obfuscated Ruby Code Contest (IORCC) — "Josef 'Jupp' Schugt" <jupp@...> 2005/02/22

Todd Nathan wrote:

[#132102] Re: ANN: 2005 International Obfuscated Ruby Code Contest (IORCC) — Yukihiro Matsumoto <matz@...> 2005/02/22

Hi,

[#132105] Re: ANN: 2005 International Obfuscated Ruby Code Contest (IORCC) — "David A. Black" <dblack@...> 2005/02/22

Hi --

[#132107] Re: ANN: 2005 International Obfuscated Ruby Code Contest (IORCC) — Bill Guindon <agorilla@...> 2005/02/22

On Wed, 23 Feb 2005 08:23:08 +0900, David A. Black <dblack@wobblini.net> wrote:

[#132036] Proposal for nil, 0, and "" in an if statement — Dan Fitzpatrick <dan@...>

The following was derived from a portion of the destrutive! operations

38 messages 2005/02/22
[#132041] Re: Proposal for nil, 0, and "" in an if statement — David Heinemeier Hansson <david@...> 2005/02/22

> Here is a proposal for evaluating "", 0, and nil in an if statement:

[#132046] Re: Proposal for nil, 0, and "" in an if statement — Pit Capitain <pit@...> 2005/02/22

David Heinemeier Hansson schrieb:

[#132047] Re: Proposal for nil, 0, and "" in an if statement — Gavin Kistner <gavin@...> 2005/02/22

On Feb 22, 2005, at 6:41 AM, Pit Capitain wrote:

[#132053] Re: Proposal for nil, 0, and "" in an if statement — Gavin Kistner <gavin@...> 2005/02/22

On Feb 22, 2005, at 6:47 AM, Gavin Kistner wrote:

[#132054] Re: Proposal for nil, 0, and "" in an if statement — "David A. Black" <dblack@...> 2005/02/22

Hi --

[#132156] surprising: class A; end; A === A ==> false — Sam Roberts <sroberts@...>

I'm used to thinking of === being MORE useful

10 messages 2005/02/23

[#132186] Lighting the candles on the cake? — James Britt <jamesUNDERBARb@...>

Don't want to eat birthday cake too soon, but I know that someplace it's

12 messages 2005/02/24

[#132246] Simple HTML Renderer / Browser? — Randy Kramer <rhkramer@...>

I need a simple HTML renderer (to get started--eventually, I want to be able

18 messages 2005/02/24

[#132257] ruby-talk.com Expired? — James Edward Gray II <james@...>

I use http://ruby-talk.com/# style links on the Ruby Quiz site and I

13 messages 2005/02/24

[#132373] Ajax: A New Approach to Web Applications — "Curt Hibbs" <curt@...>

I always have trouble remembering whether its HttpXmlRequest, or

37 messages 2005/02/25
[#132379] Re: [OT] Ajax: A New Approach to Web Applications — "James G. Britt " <ruby.talk.list@...> 2005/02/25

On Sat, 26 Feb 2005 06:45:34 +0900, Curt Hibbs <curt@hibbs.com> wrote:

[#132382] Re: [OT] Ajax: A New Approach to Web Applications — "Curt Hibbs" <curt@...> 2005/02/25

James G. Britt wrote:

[#132375] Re: [OT] Ajax: A New Approach to Web Applications — PA <petite.abeille@...> 2005/02/25

[#132455] RubyGems 0.8.5 — Jim Weirich <jim@...>

= Announce: RubyGems Release 0.8.5

23 messages 2005/02/27
[#132525] RubyGems 0.8.6 (was Re: [ANN] RubyGems 0.8.5) — Chad Fowler <chadfowler@...> 2005/02/27

On Sun, 27 Feb 2005 10:34:34 +0900, Jim Weirich <jim@weirichhouse.org> wrote:

[#132500] Parsers vs. Homemade "Parsing" via REs — Randy Kramer <rhkramer@...>

I have the need to translate several megabytes of TWiki marked up text to

10 messages 2005/02/27

[SUMMARY] Yahtzee (#19)

From: Ruby Quiz <james@...>
Date: 2005-02-17 13:52:01 UTC
List: ruby-talk #131331
Well, there wasn't any discussion or submissions this week, save my own.  Guess
that means you'll have to suffer through my code this week.

There are really two aspects to a game of Yahtzee:  Dice rolling and score
keeping.  With dice rolling, you need to be able to handle a roll of multiple
dice and re-rolls of selected dice.  You'll need to be able to display and
examine this roll, of course.  Then, you'll need to be able to sum all the dice
or just certain dice.

Finally, when it's time to score those rolls, you need some way to match die
against patterns.  Three of a Kind, Four of a Kind, Full House and Yahtzee are
repetition patterns.  You're looking for any number to appear on the dice a set
number of times.  With Full House, you're actually looking for two different
dice to appear a different number of times.

Small Straight and Large Straight need another form of pattern matching: 
Sequence patterns.  Here you're searching for a run on the dice of a specified
length, but the actual numbers in the run don't matter.

Here's the class I coded up to cover those needs:

	# Namespace for all things Yahtzee.
	module Yahtzee
		# An object for managing the rolls of a Yahtzee game.
		class Roll
			#
			# Create an instance of Roll.  Methods can then be used the
			# examine the results of the roll and re-roll dice.
			#
			def initialize(  )
				@dice = Array.new(5) { rand(6) + 1 }
			end
			
			# Examine the individual dice of a Roll.
			def []( index )
				@dice[index]
			end
		
			# Count occurrences of a set of pips.
			def count( *pips )
				@dice.inject(0) do |total, die|
					if pips.include?(die) then total + 1 else total end
				end
			end
		
			# Add all occurrences of a set of pips, or all the dice.
			def sum( *pips )
				if pips.size == 0
					@dice.inject(0) { |total, die| total + die }
				else
					@dice.inject(0) do |total, die|
						if pips.include?(die) then total + die else total end
					end
				end
			end
		
			#
			# Examines Roll for a pattern of dice, returning true if found.  
			# Patterns can be of the form:
			#
			#     roll.matches?(1, 2, 3, 4)
			#
			# Which validates a sequence, regardless of the actual pips on
			# the dice.
			#
			# You can also use the form:
			# 
			#     roll.matches?(*%w{x x x y y})
			#
			# To validate repititions.
			#
			# The two forms can be mixed in any combination and when they
			# are, both must match completely.
			#
			def matches?( *pattern )
				digits, letters = pattern.partition { |e| e.is_a?(Integer) }
				matches_digits?(digits) and matches_letters?(letters)
			end
		
			# Re-roll selected _dice_.
			def reroll( *dice )
				if dice.size == 0
					@dice = Array.new(5) { rand(6) + 1 }
				else
					indices = [ ]
					pool    = @dice.dup
					dice.each do |d|
						i = pool.index(d) or
							raise ArgumentError, "Dice not found."
						indices << i
						pool[i] = -1
					end
				
					indices.each { |i| @dice[i] = rand(6) + 1 }
				end
			end
		
			# To make printing out rolls easier.
			def to_s(  )
				"#{@dice[0..-2].join(',')} and #{@dice[-1]}"
			end
		
			private
		
			# Verifies matching of sequence patterns.
			def matches_digits?( digits )
				return true if digits.size < 2
			
				digits.sort!
				test = @dice.uniq.sort
				loop do
					(0..(@dice.length - digits.length)).each do |index|
						return true if test[index, digits.length] == digits
					end
			
					digits.collect! { |d| d + 1 }
					break if digits.last > 6	
				end
			
				false
			end
		
			# Verifies matching of repetition patterns.
			def matches_letters?( letters )
				return true if letters.size < 2
			
				counts = Hash.new(0)
				letters.each { |l| counts[l] += 1 }
				counts = counts.values.sort.reverse
			
				pips = @dice.uniq
				counts.each do |c|
					unless match = pips.find { |p| count(p) >= c }
						return false
					end
					pips.delete(match)
				end
			
				true
			end
		end
	end

The descriptions and comments above should make that class pretty transparent, I
hope.

The method matches?() is my dice pattern matching system.  It understands arrays
of letters and/or numbers, feeding the correct sets to the private methods
matches_digits?() and matches_letters?().

Letters are used to check repetition.  For example, the pattern used to match a
Full House is %w{x x x y y}.  That requires three of any one number and two of a
different number.

Numbers are used to check sequence patterns.  As another example, the pattern to
match a Small Straight is [1, 2, 3, 4].  That requires that there be four
different numbers shown on the dice, each exactly one apart from one of the
other numbers.  Which numbers are shown doesn't matter.

As an interesting aside, the above class proved tricky to unit test.  Well, for
me anyway.  I didn't end up posting my tests because I was ashamed of the hack I
used.  Perhaps this should be a separate quiz...

Scoring is pretty simple.  We just need a Scorecard object that holds categories
we can add points to and totals based on those categories.  We need to be able
to print that, of course, and allow the user to identify categories using some
form of label.  Here's what I came up with for that:

	# Namespace for all things Yahtzee.
	module Yahtzee
		# A basic score tracking object.
		class Scorecard
			# Create an instance of Scorecard.  Add categories and totals,
			# track score and display results as needed.
			def initialize(  )
				@categories = [ ]
			end
		
			#
			# Add one or more categories to this Scorecard.  Order is 
			# maintained.
			#
			def add_categories( *categories )
				categories.each do |cat|
					@categories << [cat, 0]
				end
			end
		
			#
			# Add a total, with a block to calculate it from passed a
			# categories Hash.
			#
			def add_total( name, &calculator )
				@categories << [name, calculator]
			end
			
			#
			# The primary score action method.  Adds _count_ points to the
			# category at _index_.
			#
			def count( index, count )
				@categories.assoc(category(index))[1] += count
			end
		
			# Lookup the score of a given category.
			def []( name )
				@categories.assoc(name)[1]
			end
			
			# Lookup a category name, by _index.
			def category( index )
				id = 0
				@categories.each_with_index do |(name, count_or_calc), i|
					next unless count_or_calc.is_a?(Numeric)
					id += 1
					return @categories[i][0] if id == index
				end

				raise ArgumentError, "Invalid category."
			end
			
			# Support for easy printing.
			def to_s(  )
				id = 0
				@categories.inject("") do |disp, (name, count_or_calc)|
					if count_or_calc.is_a?(Numeric)
						id += 1
						disp + "%3d: %-20s %4d\n" % [id, name, count_or_calc]
					else
						disp + "     %-20s %4d\n" %
							[name, count_or_calc.call(to_hash)]
					end
				end
			end
		
			# Convert category listing to a Hash.
			def to_hash(  )
				@categories.inject(Hash.new) do |hash, (name, count_or_calc)|
					if count_or_calc.is_a?(Numeric)
						hash[name] = count_or_calc
					end
					hash
				end
			end
		end
	end

Using that isn't too tough.  Create a Scorecard and add categories and totals to
it.  Categories are really just a name that can be associated with a point
count.  Totals are passed in as a block of code that can calculate the total as
needed.  The block is passed a hash of category names and their current points,
when called.  Moving into the "main" section of my program, we can see how I use
this to build Yahtzee's Scorecard:

	# Console game interface.
	if __FILE__ == $0
		# Assemble Scorecard.
		score = Yahtzee::Scorecard.new()
		UPPER = %w{Ones Twos Threes Fours Fives Sixes}
		UPPER_TOTAL = lambda do |cats|
			cats.inject(0) do |total, (cat, count)|
				if UPPER.include?(cat) then total + count else total end
			end
		end
		score.add_categories(*UPPER)
		score.add_total("Bonus") do |cats|
			upper = UPPER_TOTAL.call(cats)
			if upper >= 63 then 35 else 0 end
		end
		score.add_total("Upper Total") do |cats|
			upper = UPPER_TOTAL.call(cats)
			if upper >= 63 then upper + 35 else upper end
		end
		LOWER = [ "Three of a Kind", "Four of a Kind", "Full House",
				  "Small Straight", "Large Straight", "Yahtzee", "Chance" ]
		bonus_yahtzees = 0
		LOWER_TOTAL = lambda do |cats|
			cats.inject(bonus_yahtzees) do |total, (cat, count)|
				if LOWER.include?(cat) then total + count else total end
			end
		end
		score.add_categories(*LOWER[0..-2])
		score.add_total("Bonus Yahtzees") { bonus_yahtzees }
		score.add_categories(LOWER[-1])
		score.add_total("Lower Total", &LOWER_TOTAL)
		score.add_total("Overall Total") do |cats|
			upper = UPPER_TOTAL.call(cats)
			if upper >= 63
				upper + 35 + LOWER_TOTAL.call(cats)
			else
				upper + LOWER_TOTAL.call(cats)
			end
		end
		
		# ...

I make a little use of the fact that Ruby's blocks are closures there,
especially with the Bonus Yahtzees total.  I simply have it refer to a
bonus_yahtzees variable, which the game engine can increase as needed.

Let's step into that engine now.  Here's the section that handles dice rolling:

		# ...
		
		# Game.
		puts "\nWelcome to Yahtzee!"
		scratches = (1..13).to_a
		13.times do
			# Rolling...
			roll = Yahtzee::Roll.new
			rolls = 2
			while rolls > 0
				puts "\nYou rolled #{roll}."
				print "Action:  " +
				      "(c)heck score, (s)core, (q)uit or #s to reroll?  "
				choice = STDIN.gets.chomp
				case choice
				when /^c/i
					puts "\nScore:\n#{score}"
				when /^s/i
					break
				when /^q/i
					exit
				else
					begin
						pips = choice.gsub(/\s+/, "").split(//).map do |n|
							Integer(n)
						end
						roll.reroll(*pips)
						rolls -= 1
					rescue
						puts "Error:  That not a valid reroll."
					end
				end
			end
			
			# ...

Most of that code is for processing user interface commands.  The actual dice
roll handling is just calls to the correct methods of Roll at the correct times.

Finally, here's the scoring portion of the game:

			# ...
	
			# Scoring...
			loop do
				if roll.matches?(*%w{x x x x x}) and score["Yahtzee"] == 50
					bonus_yahtzees += 100
					
					if scratches.include?(roll[0])
						score.count(roll[0], roll.sum(roll[0]))
						scratches.delete(choice)
						puts "Bonus Yahtzee scored in " +
						     "#{score.category(roll[0])}."
						break
					end
					
					puts "Bonus Yahtzee!  100 points added.  " +
					     "Score in lower section as a wild-card."
					bonus_yahtzee = true
				else
					bonus_yahtzee = false
				end
				
				print "\nScore:\n#{score}\n" +
				      "Where would you like to count your #{roll} " +
				      "(# of category)?  "
				begin
					choice = Integer(STDIN.gets.chomp)
					raise "Already scored." unless scratches.include?(choice)
					case choice
					when 1..6
						score.count(choice, roll.sum(choice))
					when 7
						if roll.matches?(*%w{x x x}) or bonus_yahtzee
							score.count(choice, roll.sum())
						end
					when 8
						if roll.matches?(*%w{x x x x}) or bonus_yahtzee
							score.count(choice, roll.sum())
						end
					when 9
						if roll.matches?(*%w{x x x y y}) or bonus_yahtzee
							score.count(choice, 25)
						end
					when 10
						if roll.matches?(1, 2, 3, 4) or bonus_yahtzee
							score.count(choice, 30)
						end
					when 11
						if roll.matches?(1, 2, 3, 4, 5) or bonus_yahtzee
							score.count(choice, 40)
						end
					when 12
						if roll.matches?(*%w{x x x x x})
							score.count(choice, 50)
						end
					when 13
						score.count(choice, roll.sum)
					end
					scratches.delete(choice)
					break
				rescue
					puts "Error:  Invalid category choice."
				end
			end
		end
		
		print "\nFinal Score:\n#{score}\nThanks for playing.\n\n"
	end

The first if block in there is watching for Bonus Yahtzees, which are the
hardest thing to track in a Yahtzee game.  If a second Yahtzee is thrown, it
increments the bonus_yahtzee variable (so the Scorecard total will change), then
it tries to score the Yahtzee in the correct slot of the Upper section.  If that
slot is already full, it warns the code below to allow wild-card placement by
setting the boolean variable bonus_yahtzee.

The rest of the scoring code is a case statement that validates dice patterns
and scores them correctly.  It looks like a lot of code, but it's very basic in
function.  I'm really just stitching Roll and Scorecard together here.

That's all there is to my version of Yahtzee.  I didn't do the extra challenges,
obviously.  It's pretty easy to add Triple Yahtzee to this version.  The AI is a
bigger challenge, if you want it to play well.  Those I'll leave as a challenge
for the reader.

You already know what tomorrow's quiz is.  You asked for it.

In This Thread

Prev Next