[#144186] Re: array of object insert polices — "Pe, Botp" <botp@...>

dave [mailto:dave.m@email.it] wrote:

14 messages 2005/06/01

[#144206] Implementing a Read-Only array — Gavin Kistner <gavin@...>

Right up front, let me say that I realize that I can't prevent

14 messages 2005/06/01

[#144224] Method Chaining Issues — "aartist" <aartist@...>

try this:

28 messages 2005/06/01
[#144231] Re: Method Chaining Issues — "Phrogz" <gavin@...> 2005/06/01

This is a FAQ, though no page on the RubyGarden wiki seems to address

[#144240] Re: Method Chaining Issues — Nikolai Weibull <mailing-lists.ruby-talk@...> 2005/06/01

Phrogz wrote:

[#144230] ternary operator confusion — Belorion <belorion@...>

I don't know if this is "improper" use of the ternary operator, but I

19 messages 2005/06/01
[#144233] Re: ternary operator confusion — "Phrogz" <gavin@...> 2005/06/01

true ? a.push(1) : a.push(2)

[#144257] Re: ternary operator confusion — "Marcel Molina Jr." <marcel@...> 2005/06/01

On Thu, Jun 02, 2005 at 01:40:23AM +0900, Phrogz wrote:

[#144263] Re: ternary operator confusion — Eric Mahurin <eric_mahurin@...> 2005/06/01

--- "Marcel Molina Jr." <marcel@vernix.org> wrote:

[#144453] RubyScript2Exe and GUI toolkits — Erik Veenstra <pan@...>

13 messages 2005/06/03

[#144487] Building a business case for Ruby — Joe Van Dyk <joevandyk@...>

Hi,

29 messages 2005/06/03

[#144535] ruby-dev summary 26128-26222 — Minero Aoki <aamine@...>

Hi all,

11 messages 2005/06/04

[#144579] Package, a future replacement for setup.rb and mkmf.rb — Christian Neukirchen <chneukirchen@...>

29 messages 2005/06/04

[#144672] newbie read.scan (?) question — "Bruce D'Arcus" <bdarcus.lists@...>

Hi,

16 messages 2005/06/06

[#144691] making a duck — Eric Mahurin <eric_mahurin@...>

Regarding duck-typing... Is there an easy way make a "duck"?

27 messages 2005/06/06

[#144867] ruby-wish@ruby-lang.org mailing list — dave <dave.m@...>

19 messages 2005/06/08
[#144870] Re: [PROPOSAL] ruby-wish@ruby-lang.org mailing list — "Robert Klemme" <bob.news@...> 2005/06/08

Austin Ziegler wrote:

[#144890] RubyStuff: The Ruby Shop for Ruby Programmers — James Britt <james_b@...>

Announcing the formal grand opening of Ruby Stuff: The Ruby Shop for

36 messages 2005/06/08

[#144966] python/ruby benchmark. — "\"</script>" <groleo@...>

I took a look at

78 messages 2005/06/09
[#144967] Re: python/ruby benchmark. — gabriele renzi <surrender_it@...> 2005/06/09

"</script> ha scritto:

[#144974] Re: python/ruby benchmark. — Lothar Scholz <mailinglists@...> 2005/06/09

Hello gabriele,

[#144977] Re: python/ruby benchmark. — Kent Sibilev <ksruby@...> 2005/06/09

Java is an order of magnitude faster than Ruby. The development of a

[#144980] Re: python/ruby benchmark. — Lothar Scholz <mailinglists@...> 2005/06/09

Hello Kent,

[#144983] Re: python/ruby benchmark. — "Ryan Leavengood" <mrcode@...> 2005/06/09

Lothar Scholz said:

[#145196] Re: python/ruby benchmark(don't shoot the messenger) — ptkwt@... (Phil Tomson) 2005/06/12

In article <9e7db91105061106485b68d629@mail.gmail.com>,

[#145207] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Phil Tomson wrote:

[#145212] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/12

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145219] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Austin Ziegler wrote:

[#145223] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/12

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145240] Re: python/ruby benchmark(don't shoot the messenger) — Steven Jenkins <steven.jenkins@...> 2005/06/12

Austin Ziegler wrote:

[#145241] Re: python/ruby benchmark(don't shoot the messenger) — Austin Ziegler <halostatue@...> 2005/06/13

On 6/12/05, Steven Jenkins <steven.jenkins@ieee.org> wrote:

[#145000] RDoc

Hi, I have a question. When I compiled ruby-1.8.2

13 messages 2005/06/09
[#145003] Re: RDoc — Eric Hodel <drbrain@...7.net> 2005/06/09

On 09 Jun 2005, at 13:55, Jesffffas Antonio Sfffe1nchez A. wrote:

[#145238] finding Hash subsets based on key value — "ee" <erik.eide@...>

Hi

17 messages 2005/06/12

[#145304] PDF::Writer 1.0 (version 1.0.1) — Austin Ziegler <halostatue@...>

= PDF::Writer

21 messages 2005/06/13
[#145411] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Jason Foreman <threeve.org@...> 2005/06/14

No love from PDF::Writer on Mac OS X 10.4.1. I hope to get this fixed

[#145420] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Austin Ziegler <halostatue@...> 2005/06/14

On 6/14/05, Jason Foreman <threeve.org@gmail.com> wrote:

[#145432] Re: [ANN] PDF::Writer 1.0 (version 1.0.1) — Jamis Buck <jamis@37signals.com> 2005/06/15

On Jun 14, 2005, at 5:11 PM, Austin Ziegler wrote:

[#145339] survey: what editor do you use to hack ruby? — Lowell Kirsh <lkirsh@...>

I've been having a tough time getting emacs set up properly with ruby

62 messages 2005/06/14

[#145390] Ruby and recursion (Ackermann benchmark) — ptkwt@... (Phil Tomson)

14 messages 2005/06/14

[#145586] How to make a browser in Ruby Tk — sujeet kumar <sujeetkr@...>

Hi

13 messages 2005/06/16

[#145636] Super-scalar Optimizations — "Phrogz" <gavin@...>

I was looking over the shoulder of a C++ coworker yesterday, when he

14 messages 2005/06/16

[#145677] Truth maintenance system in Ruby — "itsme213" <itsme213@...>

Anyone know of any kind of truth-maintenance system implemented in Ruby (or,

12 messages 2005/06/17

[#145720] Frameless RDoc template ('technology preview') — ES <ruby-ml@...>

Hi!

17 messages 2005/06/17

[#145779] Newbe questions... — "Chuck Brotman" <brotman@...>

In Ruby Is there a prefered (or otherwise elegant) way to do an inner &

17 messages 2005/06/18

[#145790] GC.disable not working? — Eric Mahurin <eric_mahurin@...>

From what I can tell, GC.disable doesn't work. I'm wanting to

37 messages 2005/06/18
[#145822] Re: GC.disable not working? — ts <decoux@...> 2005/06/19

>>>>> "E" == Eric Mahurin <eric_mahurin@yahoo.com> writes:

[#146024] evaluation of ruby — "Franz Hartmann" <porschefranz@...> 2005/06/21

Hello all,

[#145830] preventing instantiation — "R. Mark Volkmann" <mark@...>

What is the recommended way in Ruby to prevent other classes from creating

13 messages 2005/06/19
[#145831] Re: preventing instantiation — Gavri Fernandez <gavri.fernandez@...> 2005/06/19

On 6/19/05, R. Mark Volkmann <mark@ociweb.com> wrote:

[#145879] x==1 vs 1==x — Gavin Kistner <gavin@...>

I'm against _premature_ optimization in theory, but believe that a

19 messages 2005/06/20
[#145880] Re: x==1 vs 1==x — ts <decoux@...> 2005/06/20

>>>>> "G" == Gavin Kistner <gavin@refinery.com> writes:

[#145943] Chess Variants (II) (#36) — James Edward Gray II <james@...>

I don't want to spoil all the fun, in case anyone is still attempting

12 messages 2005/06/20

[#146038] 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Michael Tan <mtan1232000@...>

Just new to Ruby since last week, running my same functional program on the windows XP(Pentium M1.5G), the Ruby version is 10 times slower than the Java version. The program is to find the prime numbers like 2, 3,5, 7, 11, 13... Are there setup issues? or it is normal?

47 messages 2005/06/21
[#146044] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Florian Frank" <flori@...> 2005/06/21

Michael Tan wrote:

[#146047] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Jim Freeze <jim@...> 2005/06/21

* Florian Frank <flori@nixe.ping.de> [2005-06-22 05:40:14 +0900]:

[#146050] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Ryan Leavengood" <mrcode@...> 2005/06/21

Jim Freeze said:

[#146132] Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Mark Thomas" <mrt@...> 2005/06/22

Florian Frank wrote:

[#146064] rubyscript2exe — Joe Van Dyk <joevandyk@...>

Hi,

14 messages 2005/06/21

[#146169] spidering a website to build a sitemap — Bill Guindon <agorilla@...>

I need to spider a site and build a sitemap for it. I've looked

17 messages 2005/06/22

[#146178] traits-0.4.0 - the coffee release — "Ara.T.Howard" <Ara.T.Howard@...>

15 messages 2005/06/22

[#146328] string to Class object — "R. Mark Volkmann" <mark@...>

How can I create a Class object from a String that contains the name of a class?

15 messages 2005/06/24

[#146380] Application-0.6.0 — Jim Freeze <jim@...>

CommandLine - Application and OptionParser

22 messages 2005/06/24

[#146391] ASP.NET vs Ruby on Rails — Stephen Kellett <snail@...>

HI Folks,

21 messages 2005/06/24
[#146457] Re: ASP.NET vs Ruby on Rails — "Dema" <demetriusnunes@...> 2005/06/25

Hi Stephen,

[#146425] speeding up Process.detach frequency — Joe Van Dyk <joevandyk@...>

Is there any way to speed up Process.detach? The ri documentation for

14 messages 2005/06/25

[#146483] I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Michael Tan <mtan1232000@...>

22 messages 2005/06/26
[#146485] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — "Florian Frank" <flori@...> 2005/06/26

Michael Tan wrote:

[#146504] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Brad Wilson <dotnetguy@...> 2005/06/26

For comparison, the port of your code to (less than elegant) C#.

[#146515] Re: I saw the beauty of Ruby Re: 1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds — Florian Gro<florgro@...> 2005/06/26

Brad Wilson wrote:

[#146491] What do you want to see in a Sparklines Library? — Daniel Nugent <nugend@...>

This is sort of an interest gauging/feature request poll.

17 messages 2005/06/26
[#146506] Re: What do you want to see in a Sparklines Library? — Daniel Amelang <daniel.amelang@...> 2005/06/26

See what's already been done before you get too far.

[#146517] Re: What do you want to see in a Sparklines Library? — Daniel Nugent <nugend@...> 2005/06/26

Yup, seen the stuff on RedHanded, I was planning on writing a little

[#146562] RCM - A Ruby Configuration Management System — Michael Neumann <mneumann@...>

Hi all,

22 messages 2005/06/27

[#146630] yield does not take a block — Daniel Brockman <daniel@...>

Under ruby 1.9.0 (2005-06-23) [i386-linux], irb 0.9.5(05/04/13),

48 messages 2005/06/28
[#146666] Re: yield does not take a block — Daniel Brockman <daniel@...> 2005/06/28

Yukihiro Matsumoto <matz@ruby-lang.org> writes:

[#146680] Re: yield does not take a block — Yukihiro Matsumoto <matz@...> 2005/06/28

Hi,

[#146684] Re: yield does not take a block — Eric Mahurin <eric_mahurin@...> 2005/06/28

[#146779] Re: yield does not take a block — "Adam P. Jenkins" <thorin@...> 2005/06/29

Eric Mahurin wrote:

[#146700] Anything in new Eclipse for Rubyists? — "jfry" <jeff.fry@...>

Hey there, I know that a number of folks on the list use Eclipse as

14 messages 2005/06/28

[#146773] Programmers Contest: Fit pictures on a page — hicinbothem@...

GLOSSY: The Summer Programmer Of The Month Contest is underway!

18 messages 2005/06/29

[#146815] shift vs. slice!(0) and others — Eric Mahurin <eric_mahurin@...>

I just did some benchmarking of various ways to insert/delete

12 messages 2005/06/29

[SUMMARY] Chess Variants (II) (#36)

From: Ruby Quiz <james@...>
Date: 2005-06-23 13:03:31 UTC
List: ruby-talk #146254
Everyone must have worn themselves out on the crazy hard task last week and had
no juice left for the easier one this week.

Since we're implementing these games in terms of some chess library, it's really
best if you can restate the game in chess terms.  Let's take Gun Chess, for
example.  Pieces don't move when capturing.  That requires me to rewrite my
library's move() method, which is too much work because of all the special
cases.  Instead, I can just restate the problem:  Whenever a piece captures, it
returns to the square it started on.  That is trivial to implement:

	# An enhanced chess board for playing Gun Chess.
	class GunChess < Chess::Board
		# Returns a numerical count of all the pieces on the board.
		def count_pieces(  )
			find_all { |(square, piece)| piece }.size
		end
		
		# Make standard chess moves, save that capturing pieces do not move.
		def move( from_square, to_square, promote_to = nil )
			old_count = count_pieces
			
			super    # normal chess move
			
			if count_pieces < old_count         # if it was a capture...
				move(to_square, from_square)    # move the piece back
				next_turn                       # fix the extra turn change
			end
			
			self
		end
	end

The overridden move() method is the key here.  It counts the number of pieces on
the board (using the helper method count_pieces()), then executes a normal chess
move.  Before returning, the pieces are again counted and if the number is less
we move the piece back to it's starting square because a capture has just taken
place.

Pop quiz:  Why did I count the pieces, instead of checking for a piece on the
to_square (which is probably easier)?

En-passant.  When capturing en-passant, there is no piece on the to_square, but
we can still spot it because the piece count will drop.

Let's examine another variation.  Fairy Chess is just chess with an upgraded
queen.  That should be all the hint you need for an easy implementation. 
Subclass Chess::Queen and just add the new moves.

My library also requires you to update the king's awareness of check slightly. 
While it's good to have the ability to change check when needed, this is
probably a weakness of my original library.  It could find check using the moves
of pieces on the board and then we would just need to add the fairy.

Anyway, here's what I came up with:

	#
	# The container for the behavior of a chess fairy.  Fairies are simply
	# treated as both a Queen and a Knight.
	# 
	class Fairy < Chess::Queen
		#
		# Returns all the capturing moves for a Fairy on the provided _board_
		# at the provided _square_ of the provided _color_.
		# 
		def self.captures( board, square, color )
			captures =  Chess::Queen.captures(board, square, color)
			captures += Chess::Knight.captures(board, square, color)
			captures.sort
		end

		#
		# Returns all the non-capturing moves for a Fairy on the provided
		# _board_ at the provided _square_ of the provided _color_.
		# 
		def self.moves( board, square, color )
			moves =  Chess::Queen.moves(board, square, color)
			moves += Chess::Knight.moves(board, square, color)
			moves.sort
		end
	end

	# Make the Chess::King aware of the Fairy.
	class FairyAwareKing < Chess::King
		# Enhance in_check? to spot special Fairy moves.
		def self.in_check?( bd, sq, col )
			return true if Chess::Knight.captures(bd, sq, col).any? do |name|
				bd[name].is_a?(Fairy)
			end

			Chess::King.in_check?( bd, sq, col )
		end

		# Make this piece show up as a normal King.
		def to_s(  )
			if @color == :white then "K" else "k" end
		end
	end

	# An enhanced chess board for playing Fairy Chess.
	class FairyChess < Chess::Board
		# Setup a normal board, then replace the queens with fairies.
		def setup(  )
			super
			
			@squares["d1"] = Fairy.new(self, "d1", :white)
			@squares["d8"] = Fairy.new(self, "d8", :black)
			@squares["e1"] = FairyAwareKing.new(self, "e1", :white)
			@squares["e8"] = FairyAwareKing.new(self, "e8", :black)
		end
	end

The first class is my fairy.  You can see that my library allows me to access
the captures and moves of a queen and a knight.  Adding those together gives us
a fairy.

The second class is my updated king.  It will know when it is in check by a
fairy.  Because Fairy is a subclass of Chess::Queen, the old check will already
spot Chess::Queen threats from a Fairy.  All I had to add was the Chess::Knight
threats.

Finally, all the new board class has to do is change the initial setup() to
include the two new pieces.

Blackhole Chess is even easier than the above two variations, because it's
already stated in easy to implement terms.  You can check to see if a move will
cross one of the blackholes, and simply remove the moving piece when it will:

	# An enhanced chess board for playing Blackhole Chess.
	class BlackholeChess < Chess::Board
		# 
		# A general purpose test to see if a _test_ square is between _start_
		# and _finish_ squares, on a rank, file or diagonal.
		# 
		def self.between?( start, finish, test )
			test_rank,   test_file   = test[1, 1].to_i,   test[0]
			start_rank,  start_file  = start[1, 1].to_i,  start[0]
			finish_rank, finish_file = finish[1, 1].to_i, finish[0]
			
			( test_rank == start_rank and test_rank == finish_rank and
			  test_file >= [start_file, finish_file].min and
			  test_file <= [start_file, finish_file].max ) or
			( test_file == start_file and test_file == finish_file and
			  test_rank >= [start_rank, finish_rank].min and
			  test_rank <= [start_rank, finish_rank].max ) or
			( (start_file - finish_file).abs ==
			  (start_rank - finish_rank).abs and 
			  (start_file - test_file).abs ==
			  (start_rank - test_rank).abs and
			  (test_file - finish_file).abs ==
			  (test_rank - finish_rank).abs and  
			  test_file >= [start_file, finish_file].min and
			  test_file <= [start_file, finish_file].max and
			  test_rank >= [start_rank, finish_rank].min and
			  test_rank <= [start_rank, finish_rank].max )
		end

		# End the game if a King goes missing.
		def in_checkmate?( who = @turn )
			if find { |(s, p)| p and p.color == who and p.is_a? Chess::King }
				super
			else
				true
			end
		end
		
		# Eliminate any piece moving through the blackholes.
		def move( from_square, to_square, promote_to = nil )
			if self.class.between?(from_square, to_square, "d5") or
			   self.class.between?(from_square, to_square, "f5")
				@squares[from_square] = nil
				next_turn
			else
				super
			end
			
			self
		end
		
		# Board display with two added blackholes.
		def to_s(  )
			super.sub( /^(5\s+\|(?:[^|]+\|){3})[^|]+\|([^|]+\|)[^|]+\|/,
			           "\\1 * |\\2 * |" )
		end
	end

The between?() method is my helper for checking if a move will cross over a
blackhole.  You can glance down to move() to see it used, just as I described
above.  I also have to update in_checkmate?() to recognize a missing king as a
losing condition and to_s() to draw the blackholes.

Fibonacci Chess is the easiest of the four I implemented, as long as your
library has something like my next_turn() method to override:

	# An enhanced chess board for playing Fibonacci Chess.
	class FibonacciBoard < Chess::Board
		# Setup chess board and initialize move count sequence.
		def initialize(  )
			super
			
			@fib1  = nil
			@fib2  = nil
			@count = 1
		end
		
		# Advance turn, as players complete moves in the Fibonacci sequence.
		def next_turn(  )
			if @fib1.nil?
				@fib1 = 1
			elsif @fib2.nil?
				@fib2 = 2
				next_turn if in_check?(@turn == :white ? :black : :white)
			elsif @count.zero? or
			      in_check?(@turn == :white ? :black : :white)
				@fib1, @fib2 = @fib2, @fib1 + @fib2
				@count = @fib2 - 1
			else
				@count -= 1
				return
			end

			super
		end
		
		# Return a String description of the moves remaining.
		def moves_remaining(  )
			if @fib1.nil? or @fib2.nil? or @count.zero?
				"last move"
			else
				"#{@count + 1} moves"
			end
		end
	end

As you can see, I just changed the traditional one turn flop to roll after
Fibonacci N moves or the other player is placed in check, whichever comes first.
The moves_remaining() method was a hook for the interface to give you a move
countdown on your turn.

I didn't implement the other three variations, but I would use the same
technique.  Just shift their changes to something as close as possible to chess.

For example, with Madhouse Chess, you can use a very similar move() override to
my Gun Chess example.  Save a dup() of the board, instead of just the piece
count, because you'll need access to the soon-to-be captured piece.  Make a
normal chess move, then check the before and after piece counts.  If it dropped,
prompt the player to select a square and move the captured piece from the old
board to the new one at that location.

Baseline Chess is the easiest variation of all, I think.  With my library, you
can just override Chess::Board.setup() to prompt for the starting squares. 
Disabling castling is also trivial.  Just make a nonsense move with the king
after he's placed to the exact same square he was on.  This makes the king think
he has moved and so he won't allow castling moves.

Extinction Chess is probably the hardest variation (conceptually speaking--it's
actually very little code).  The first step is overriding
Chess::Board.in_checkmate?() to spot the new win condition.  Just walk the board
looking for one of everything.  Then you need to subclass Chess::King as I did
in Fairy Chess to shut off check.  Just replace in_check?() with something that
always returns false.  Don't forget to override Chess::Board.setup() to swap the
old king out for the new one.

Okay, that's all for chess variants.  Sorry again for the time sink element of
this one.  Faster quizzes are coming soon.

Let me remind everyone that Ruby Quiz is taking a break this weekend to
encourage anyone who would like to to compete in the ICFP 05 programming
contest.  That contest is a lot of work, but they usually have excellent
challenges and I think it's worth the effort.  Ruby has had a small showing in
previous years, so we need all the people showing off our favorite language we
can get!  Hope to see some familiar names there.

Ruby Quiz returns a week from tomorrow, when we'll build inference engines...

In This Thread

Prev Next